diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index a11fb4a..5a71ccb 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -4,6 +4,7 @@
package="com.arpa.hndahesudintocctmsdriver">
+
@@ -65,19 +66,42 @@
android:name="com/alct/mdp"
android:required="false" />
+
+
+
+
+
+
+
+ android:screenOrientation="portrait">
+
+
+
+ android:screenOrientation="portrait" />
+ android:screenOrientation="portrait" />
@@ -92,10 +116,17 @@
android:screenOrientation="portrait" />
+ android:screenOrientation="portrait" />
+
+
+
+
+
+ android:screenOrientation="portrait" />
@@ -111,13 +142,13 @@
+ android:screenOrientation="portrait" />
+ android:screenOrientation="portrait" />
+ android:screenOrientation="portrait" />
@@ -130,13 +161,13 @@
+ android:screenOrientation="portrait" />
+ android:screenOrientation="portrait" />
+ android:screenOrientation="portrait" />
@@ -159,10 +190,10 @@
+ android:screenOrientation="portrait" />
+ android:screenOrientation="portrait" />
@@ -170,13 +201,13 @@
+ android:screenOrientation="portrait" />
+ android:screenOrientation="portrait" />
+ android:screenOrientation="portrait" />
+ android:windowSoftInputMode="stateAlwaysHidden" />
-
+
diff --git a/app/src/main/java/com/arpa/hndahesudintocctmsdriver/App.java b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/App.java
index 7b155a3..370a08d 100644
--- a/app/src/main/java/com/arpa/hndahesudintocctmsdriver/App.java
+++ b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/App.java
@@ -3,14 +3,17 @@ package com.arpa.hndahesudintocctmsdriver;
import android.app.ActivityManager;
import android.app.Application;
import android.content.Context;
+import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.os.Build;
import android.util.Log;
import com.alct.mdp.MDPLocationCollectionManager;
import com.arpa.hndahesudintocctmsdriver.report.JTTProcess;
import com.arpa.hndahesudintocctmsdriver.request.net.Api;
+import com.arpa.hndahesudintocctmsdriver.ui.text.TestNotificationListenerService;
import com.dahe.mylibrary.CommonBaseLibrary;
import com.esign.esignsdk.EsignSdk;
import com.arpa.hndahesudintocctmsdriver.util.sp.SPUtil;
@@ -29,10 +32,24 @@ public class App extends Application {
public static int APP_STATUS = APP_STATUS_KILLED; // 记录App的启动状态
private Context con;
public static App mApplication = null;
+ /**
+ * 启动服务
+ */
+ private void startService() {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ /****************第三点*******************/
+ //安卓8.0以上开启为前台服务
+ startForegroundService(new Intent(this, App.class));
+ } else {
+ startService(new Intent(this, App.class));
+ }
+ startService(new Intent(this, TestNotificationListenerService.class));
+ }
@Override
public void onCreate() {
super.onCreate();
+ startService();
mApplication = this;
con = getBaseContext();
CommonBaseLibrary.getInstance().init(this, Api.BASE_URL);
diff --git a/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/my/MyFragment.java b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/my/MyFragment.java
index 05874c4..be911f4 100644
--- a/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/my/MyFragment.java
+++ b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/my/MyFragment.java
@@ -1,10 +1,13 @@
package com.arpa.hndahesudintocctmsdriver.ui.my;
import android.Manifest;
+import android.content.ComponentName;
+import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Message;
+import android.provider.Settings;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -16,6 +19,7 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.core.app.NotificationManagerCompat;
import com.arpa.hndahesudintocctmsdriver.event.PersonEvent;
import com.arpa.hndahesudintocctmsdriver.event.VehicleEvent;
@@ -23,6 +27,7 @@ import com.arpa.hndahesudintocctmsdriver.parts.ConfigParts;
import com.arpa.hndahesudintocctmsdriver.parts.StartOrderParts;
import com.arpa.hndahesudintocctmsdriver.parts.UserParts;
import com.arpa.hndahesudintocctmsdriver.ui.business.BusinessActivity;
+import com.arpa.hndahesudintocctmsdriver.ui.text.TextActivity;
import com.arpa.hndahesudintocctmsdriver.util.PicturlUtil;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
@@ -50,6 +55,7 @@ import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
/**
* @author hlh
@@ -232,24 +238,27 @@ public class MyFragment extends BaseFragment {
});
//联系我们
onContact.setOnClickListener(v -> {
- String serviceMobile="";
- if(ConfigParts.getConfigParts(con)!=null){
- serviceMobile=ConfigParts.getConfigParts(con).getData().getServiceMobile();
- serviceMobile=StringUtil.isNull(serviceMobile,"");
- }
- String[] title={"平台客服:"+serviceMobile};
- String[] value={serviceMobile};
- new XPopup.Builder(con)
- .isDarkTheme(false)
- .isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个
- .asCenterList("请选择",title,
- (position1, text) -> {
- Intent intent = new Intent(Intent.ACTION_DIAL);
- Uri data = Uri.parse("tel:" + value[position1]);
- intent.setData(data);
- startActivity(intent);
- })
- .show();
+ getActivity().startActivity(new Intent(getActivity(), TextActivity.class));
+// isNotificationListenerEnabled(getActivity());
+// goHuaWeiMainager();
+// String serviceMobile="";
+// if(ConfigParts.getConfigParts(con)!=null){
+// serviceMobile=ConfigParts.getConfigParts(con).getData().getServiceMobile();
+// serviceMobile=StringUtil.isNull(serviceMobile,"");
+// }
+// String[] title={"平台客服:"+serviceMobile};
+// String[] value={serviceMobile};
+// new XPopup.Builder(con)
+// .isDarkTheme(false)
+// .isDestroyOnDismiss(true) //对于只使用一次的弹窗,推荐设置这个
+// .asCenterList("请选择",title,
+// (position1, text) -> {
+// Intent intent = new Intent(Intent.ACTION_DIAL);
+// Uri data = Uri.parse("tel:" + value[position1]);
+// intent.setData(data);
+// startActivity(intent);
+// })
+// .show();
});
//咨询建议
onOpinion.setOnClickListener(v -> {
@@ -264,6 +273,47 @@ public class MyFragment extends BaseFragment {
onSetUp.setOnClickListener(v -> startActivity(new Intent(con, SetupActivity.class)));
}
+ /**
+ * 是否开启通知使用权限
+ * @param context
+ * @return
+ */
+ public void isNotificationListenerEnabled(Context context) {
+ Set packageNames = NotificationManagerCompat.getEnabledListenerPackages(context);
+ if (!packageNames.contains(context.getPackageName())) {//没有开启使用权限,去开启
+ Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
+ startActivity(intent);
+ }
+ }
+
+
+ private void goHuaWeiMainager() {
+ try {
+ Intent intent = new Intent(getActivity().getPackageName());
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+// ComponentName comp = new ComponentName("com.huawei.systemmanager", "com.huawei.permissionmanager.ui.MainActivity");
+ ComponentName comp = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");
+ intent.setComponent(comp);
+ getActivity().startActivity(intent);
+ } catch (Exception e) {
+ Toast.makeText(getActivity(), "跳转失败", Toast.LENGTH_LONG).show();
+ e.printStackTrace();
+ goIntentSetting();
+ }
+ }
+
+
+ private void goIntentSetting() {
+ Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
+ Uri uri = Uri.fromParts("package", getActivity().getPackageName(), null);
+ intent.setData(uri);
+ try {
+ getActivity().startActivity(intent);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
public void initAuth(){
if(userBean.getData()!=null){
name.setText(StringUtil.isNull(userBean.getData().getUname(),"未实名"));
diff --git a/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/AutoStartAppUtil.java b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/AutoStartAppUtil.java
new file mode 100644
index 0000000..743a007
--- /dev/null
+++ b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/AutoStartAppUtil.java
@@ -0,0 +1,36 @@
+package com.arpa.hndahesudintocctmsdriver.ui.text;
+
+import android.content.ComponentName;
+import android.content.Intent;
+
+/**
+ * @ClassName AutoStartAppUtil
+ * @Author 用户
+ * @Date 2022/10/9 9:56
+ * @Description TODO
+ */
+public class AutoStartAppUtil {
+ public static final Intent[] POWERMANAGER_INTENTS = {
+ new Intent().setComponent(new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity")),
+ new Intent().setComponent(new ComponentName("com.letv.android.letvsafe", "com.letv.android.letvsafe.AutobootManageActivity")),
+ new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity")),
+ new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity")),
+ new Intent().setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity")),
+ //new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.privacypermissionsentry.PermissionTopActivity")),
+ new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.permission.startup.StartupAppListActivity")),
+ new Intent().setComponent(new ComponentName("com.coloros.safecenter", "com.coloros.safecenter.startupapp.StartupAppListActivity")),
+ new Intent().setComponent(new ComponentName("com.oppo.safe", "com.oppo.safe.permission.startup.StartupAppListActivity")),
+ new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.AddWhiteListActivity")),
+ new Intent().setComponent(new ComponentName("com.iqoo.secure", "com.iqoo.secure.ui.phoneoptimize.BgStartUpManager")),
+ new Intent().setComponent(new ComponentName("com.vivo.permissionmanager", "com.vivo.permissionmanager.activity.BgStartUpManagerActivity")),
+ new Intent().setComponent(new ComponentName("com.samsung.android.lool", "com.samsung.android.sm.battery.ui.BatteryActivity")),
+ new Intent().setComponent(new ComponentName("com.samsung.android.lool", "com.samsung.android.sm.ui.battery.BatteryActivity")),
+ new Intent().setComponent(new ComponentName("com.htc.pitroad", "com.htc.pitroad.landingpage.activity.LandingPageActivity")),
+ new Intent().setComponent(new ComponentName("com.asus.mobilemanager", "com.asus.mobilemanager.MainActivity")),
+ new Intent().setComponent(new ComponentName("com.transsion.phonemanager", "com.itel.autobootmanager.activity.AutoBootMgrActivity")),
+ new Intent().setComponent(new ComponentName("com.meizu.safe", "com.meizu.safe.permission.SmartBGActivity")),
+ new Intent().setComponent(new ComponentName("cn.nubia.security2", "cn.nubia.security.appmanage.selfstart.ui.SelfStartActivity")),
+ new Intent().setComponent(new ComponentName("com.transsion.phonemaster", "com.cyin.himgr.applicationmanager.view.activities.AutoStartActivity")),
+ };
+
+}
diff --git a/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/TestNotificationListenerService.java b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/TestNotificationListenerService.java
new file mode 100644
index 0000000..f1693fc
--- /dev/null
+++ b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/TestNotificationListenerService.java
@@ -0,0 +1,31 @@
+package com.arpa.hndahesudintocctmsdriver.ui.text;
+
+import android.content.Intent;
+import android.service.notification.NotificationListenerService;
+import android.service.notification.StatusBarNotification;
+
+/**
+ * @ClassName TestNotificationListenerService
+ * @Author 用户
+ * @Date 2022/10/9 9:53
+ * @Description TODO
+ */
+public class TestNotificationListenerService extends NotificationListenerService {
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ return super.onStartCommand(intent, flags, startId);
+ }
+
+ @Override
+ public void onNotificationPosted(StatusBarNotification sbn) {
+ super.onNotificationPosted(sbn);
+ //Notification notification = sbn.getNotification();
+// Log.d(LiveTaskApplication.TAG, "sbn.getPackageName: " + sbn.getPackageName());
+ }
+}
diff --git a/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/TestService.java b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/TestService.java
new file mode 100644
index 0000000..48c5b5e
--- /dev/null
+++ b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/TestService.java
@@ -0,0 +1,119 @@
+package com.arpa.hndahesudintocctmsdriver.ui.text;
+
+import android.annotation.SuppressLint;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.PixelFormat;
+import android.graphics.drawable.Drawable;
+import android.os.Build;
+import android.os.IBinder;
+
+import androidx.core.app.NotificationCompat;
+
+import com.arpa.hndahesudintocctmsdriver.R;
+import com.arpa.hndahesudintocctmsdriver.ui.MainActivity;
+
+/**
+ * @ClassName TestService
+ * @Author 用户
+ * @Date 2022/10/9 9:51
+ * @Description TODO
+ */
+public class TestService extends Service {
+
+ private static final int VISIBILITY_PUBLIC = 1000;
+ private static final int PRIORITY_HIGH = 1000;
+ private final String CHANNEL_ONE_ID = "100";
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+
+ @Override
+ public boolean onUnbind(Intent intent) {
+ return super.onUnbind(intent);
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ /****************第一点*******************/
+ //创建通知栏常驻通知
+ initNotif("title", "text");
+ }
+
+ @Override
+ public void onDestroy() {
+ stopForeground(true);
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+// return super.onStartCommand(intent, flags, startId);
+ /****************第二点*******************/
+ //返回START_STICKY,被系统或手动清理后可重启
+ return START_STICKY;
+ }
+
+ public void initNotif(String title, String context) {
+ //RemoteViews remoteView = new RemoteViews(getPackageName(), R.layout.RemoteView);
+ Drawable drawable = getResources().getDrawable(R.mipmap.ic_launcher, null);
+ drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
+ Bitmap bitmapIcon = getBitmapFromDrawable(drawable);
+
+ Intent nfIntent = new Intent(this, MainActivity.class);
+ PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, nfIntent, 0);
+ @SuppressLint("WrongConstant") NotificationCompat.Builder builder = new NotificationCompat.Builder(this.getApplicationContext(), CHANNEL_ONE_ID)
+ .setContentIntent(pendingIntent) // 设置PendingIntent
+ .setSmallIcon(R.mipmap.ic_launcher) // 设置状态栏内的小图标
+ //.setLargeIcon(bitmapIcon)// 设置大图标
+ .setContentTitle(title)
+ .setContentText(context) // 设置内容
+ .setWhen(System.currentTimeMillis())// 设置该通知发生的时间
+ .setVisibility(VISIBILITY_PUBLIC)// 锁屏显示全部通知
+ //.setDefaults(Notification.DEFAULT_ALL)// //使用默认的声音、振动、闪光
+ .setPriority(PRIORITY_HIGH);// 通知的优先级
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ //修改安卓8.0以上系统报错
+ NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ONE_ID, "服务常驻通知", NotificationManager.IMPORTANCE_MIN);
+ notificationChannel.enableLights(false);//如果使用中的设备支持通知灯,则说明此通知通道是否应显示灯
+ notificationChannel.setShowBadge(false);//是否显示角标
+ notificationChannel.enableVibration(false);//是否震动
+ notificationChannel.setLockscreenVisibility(VISIBILITY_PUBLIC);//锁屏显示全部通知
+ NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ manager.createNotificationChannel(notificationChannel);
+ builder.setChannelId(CHANNEL_ONE_ID);
+ }
+ Notification notification = builder.build(); // 获取构建好的Notification
+ notification.defaults = Notification.DEFAULT_SOUND; //设置为默认的声音
+
+ startForeground(1, notification);
+ }
+
+ /**
+ * 把资源图片转换成Bitmap
+ *
+ * @param drawable 资源图片
+ * @return 位图
+ */
+ public static Bitmap getBitmapFromDrawable(Drawable drawable) {
+ int width = drawable.getBounds().width();
+ int height = drawable.getBounds().height();
+ Bitmap bitmap = Bitmap.createBitmap(width, height, drawable
+ .getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
+ : Bitmap.Config.RGB_565);
+ Canvas canvas = new Canvas(bitmap);
+ drawable.setBounds(0, 0, width, height);
+ drawable.draw(canvas);
+ return bitmap;
+ }
+
+}
diff --git a/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/TextActivity.java b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/TextActivity.java
new file mode 100644
index 0000000..39cb4a9
--- /dev/null
+++ b/app/src/main/java/com/arpa/hndahesudintocctmsdriver/ui/text/TextActivity.java
@@ -0,0 +1,338 @@
+package com.arpa.hndahesudintocctmsdriver.ui.text;
+
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.os.Bundle;
+import android.os.PowerManager;
+import android.provider.Settings;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.View;
+import android.webkit.WebView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AlertDialog;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.NotificationManagerCompat;
+import androidx.core.content.ContextCompat;
+
+import com.arpa.hndahesudintocctmsdriver.R;
+
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * @ClassName TextActivity
+ * @Author 用户
+ * @Date 2022/10/9 10:05
+ * @Description TODO
+ */
+public class TextActivity extends AppCompatActivity implements View.OnClickListener{
+
+ private TextView mLeft;
+ private TextView mBandName;
+ private TextView mAutoStart;
+ private TextView mTutorials;
+ private TextView mLockApp;
+ private TextView mBatteryOptimization;
+ private WebView mWebView1, mWebView2;
+
+ private boolean isWeb = false;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main1);
+ //提示: 需要与服务共享数据自行绑定服务
+ initView();
+ /****************第四点*******************/
+ //开启通知使用权限(有的手机需要开启才能重启进程)
+ isNotificationListenerEnabled(this);
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == mLeft) {
+ if (isWeb) {
+ isWeb = false;
+ mWebView1.setVisibility(View.GONE);
+ mWebView2.setVisibility(View.GONE);
+ return;
+ }
+ finish();
+ } else if (v == mTutorials) {
+ isWeb = true;
+ mWebView1.setVisibility(View.VISIBLE);
+ String brand = getDeviceBrand();
+ String htmlName = "";
+ if (brand.equalsIgnoreCase("huawei")) {
+ htmlName = "huawei";
+ } else if (brand.equalsIgnoreCase("honor")) {
+ htmlName = "honor";
+ } else if (brand.equalsIgnoreCase("infinix")) {
+ htmlName = "infinix";
+ } else if (brand.equalsIgnoreCase("meizu")) {
+ htmlName = "meizu";
+ } else if (brand.equalsIgnoreCase("xiaomi")) {
+ htmlName = "xiaomi";
+ } else if (brand.equalsIgnoreCase("redmi")) {
+ htmlName = "redmi";
+ } else if (brand.equalsIgnoreCase("oppo")) {
+ htmlName = "oppo";
+ } else if (brand.equalsIgnoreCase("realme")) {
+ htmlName = "realme";
+ } else if (brand.equalsIgnoreCase("onePlus")) {
+ htmlName = "onePlus";
+ } else if (brand.equalsIgnoreCase("vivo")) {
+ htmlName = "vivo";
+ } else if (brand.equalsIgnoreCase("iqoo")) {
+ htmlName = "iqoo";
+ } else if (brand.equalsIgnoreCase("smartisan")) {
+ htmlName = "smartisan";
+ } else if (brand.equalsIgnoreCase("sumsang")) {
+ htmlName = "sumsang";
+ } else if (brand.equalsIgnoreCase("asus")) {
+ htmlName = "asus";
+ } else if (brand.equalsIgnoreCase("lenovo")) {
+ htmlName = "lenovo";
+ } else if (brand.equalsIgnoreCase("nubia")) {
+ htmlName = "nubia";
+ }
+ if (!getSystemLanguage().contains("zh")) {// 非中文
+ htmlName = htmlName + "_e";
+ }
+ mWebView1.loadUrl("http://服务器接口地址/autostart/autostart_" + htmlName + ".html");
+
+ } else if (v == mAutoStart) {
+ Intent intents = null;
+ for (Intent intent : AutoStartAppUtil.POWERMANAGER_INTENTS)
+ if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
+ intents = intent;
+ break;
+ }
+ Log.e("gy", "手机品牌 device brand:" + getDeviceBrand());
+ if (intents != null) {
+ if (getDeviceBrand().equalsIgnoreCase("Infinix")) {
+ Toast.makeText(this, "无权打开系统界面, 请点击查看教程手动设置", Toast.LENGTH_SHORT).show();
+ return;
+ }
+ if (getDeviceBrand().equalsIgnoreCase("OPPO") || getDeviceBrand().equalsIgnoreCase("realme")) {
+ if (ContextCompat.checkSelfPermission(TextActivity.this, "oppo.permission.OPPO_COMPONENT_SAFE") != PackageManager.PERMISSION_GRANTED) {
+ // oppo 为系统权限不对外开放
+ Toast.makeText(this, "无权打开系统界面, 请点击查看教程手动设置", Toast.LENGTH_SHORT).show();
+// ActivityCompat.requestPermissions(PermissionsDescriptionActivity.this, new
+// String[]{"oppo.permission.OPPO_COMPONENT_SAFE"}, 1);
+ } else {
+ startActivity(intents);
+ }
+ return;
+ }
+ try {
+ startActivity(intents);
+ }catch (Exception e){
+ System.out.println(e);
+ }
+
+ } else {
+ if (getDeviceBrand().equalsIgnoreCase("OnePlus")) {
+ intents = new Intent("com.android.settings.action.BACKGROUND_OPTIMIZE");
+ startActivity(intents);
+ return;
+ }
+// if (SystemUtil.getDeviceBrand().equalsIgnoreCase("SMARTISAN")) {
+// intents = new Intent("com.smartisanos.security.action.SWITCHED_PERMISSIONS_NEW");//无效
+// startActivity(intents);
+// return;
+// }
+ Toast.makeText(this, "无权打开系统界面, 请点击查看教程手动设置", Toast.LENGTH_SHORT).show();
+ }
+ } else if (v == mLockApp) {
+ isWeb = true;
+ mWebView2.setVisibility(View.VISIBLE);
+ if (getSystemLanguage().contains("zh")) {// 中文
+ mWebView2.loadUrl("http://服务器接口地址/locktask/lockApp.html");
+ } else {
+ mWebView2.loadUrl("http://服务器接口地址/locktask/lockApp_e.html");
+ }
+ } else if (v == mBatteryOptimization) {
+ // 显示屏幕以控制哪些应用可以忽略电池优化
+ // 您可以PowerManager.isIgnoringBatteryOptimizations()用来确定应用程序是否已经忽略优化。
+ // 您可以 ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS用来要求用户将您放在此列表中。
+ //android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setIcon(R.mipmap.ic_launcher)
+ .setTitle("忽略电池优化")
+ .setMessage("参考说明:\n在手机 设置 --> 电池 --> 耗电管理 中找到" + getString(R.string.app_name) + ", 设置 允许后台运行 或 允许后台启动 等")
+ .setPositiveButton("设置忽略", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(final DialogInterface dialog, final int which) {
+ if (!isIgnoringBatteryOptimizations()) {
+ try {
+ Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
+ intent.setData(Uri.parse("package:" + getPackageName()));
+ //跳转之前判断intent是否存在,否则有的机型会报找不到activity
+ if (intent.resolveActivity(getPackageManager()) == null) {
+ intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
+ intent.setData(Uri.parse("package:" + getPackageName()));
+ if (intent.resolveActivity(getPackageManager()) == null) {
+// showToast("无法启动系统界面,请以参考说明操作");
+ } else {
+ startActivity(intent);
+ }
+ } else {
+ startActivity(intent);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ })
+ .show();
+ }
+ }
+
+ /**
+ * 是否开启通知使用权限
+ * @param context
+ * @return
+ */
+ public void isNotificationListenerEnabled(Context context) {
+ Set packageNames = NotificationManagerCompat.getEnabledListenerPackages(this);
+ if (!packageNames.contains(context.getPackageName())) {//没有开启使用权限,去开启
+ Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
+ startActivity(intent);
+ }
+ }
+
+ private void initView() {
+ mBandName = (TextView) findViewById(R.id.bandName);
+ mLeft = (TextView) findViewById(R.id.left);
+ mLeft.setOnClickListener(this);
+ mAutoStart = (TextView) findViewById(R.id.autoStart);
+ mAutoStart.setOnClickListener(this);
+ mTutorials = (TextView) findViewById(R.id.tutorials);
+ mTutorials.setOnClickListener(this);
+ mLockApp = (TextView) findViewById(R.id.lockApp);
+ mLockApp.setOnClickListener(this);
+ mBatteryOptimization = (TextView) findViewById(R.id.battery_optimization);
+ mBatteryOptimization.setOnClickListener(this);
+ mWebView1 = (WebView) findViewById(R.id.webView1);
+ mWebView1.setOnClickListener(this);
+ mWebView2 = (WebView) findViewById(R.id.webView2);
+ mWebView2.setOnClickListener(this);
+
+ mBandName.setText(getDeviceBrand());
+ }
+
+
+ /**
+ * 确定应用程序是否已经忽略电池优化
+ *
+ * @return
+ */
+ private boolean isIgnoringBatteryOptimizations() {
+ boolean isIgnoring = false;
+ PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
+ if (powerManager != null) {
+ isIgnoring = powerManager.isIgnoringBatteryOptimizations(getPackageName());
+ }
+ return isIgnoring;
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
+ //super.onRequestPermissionsResult(requestCode, permissions, grantResults);
+ switch (requestCode) {
+ case 1:
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
+ Intent intents = null;
+ for (Intent intent : AutoStartAppUtil.POWERMANAGER_INTENTS)
+ if (getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) != null) {
+ intents = intent;
+ break;
+ }
+ if (intents != null) {
+ startActivity(intents);
+ }
+ } else {
+ Toast.makeText(this, "无权打开系统界面, 请点击查看教程手动设置", Toast.LENGTH_SHORT).show();
+ }
+ break;
+ default:
+ }
+ }
+
+ /**
+ * 原生Android系统 开启后台运行调用这里
+ */
+ public void requestIgnoreBatteryOptimizations() {
+ try {
+ Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
+ intent.setData(Uri.parse("package:" + getPackageName()));
+ startActivity(intent);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ moveTaskToBack(true);//按返回键,不 finish activity
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
+ /**
+ * 获取当前手机系统语言。
+ *
+ * @return 返回当前系统语言。例如:当前设置的是“中文-中国”,则返回“zh-CN”
+ */
+ public static String getSystemLanguage() {
+ return Locale.getDefault().getLanguage();
+ }
+
+ /**
+ * 获取当前系统上的语言列表(Locale列表)
+ *
+ * @return 语言列表
+ */
+ public static Locale[] getSystemLanguageList() {
+ return Locale.getAvailableLocales();
+ }
+
+ /**
+ * 获取当前手机系统版本号
+ *
+ * @return 系统版本号
+ */
+ public static String getSystemVersion() {
+ return android.os.Build.VERSION.RELEASE;
+ }
+
+ /**
+ * 获取手机型号
+ *
+ * @return 手机型号
+ */
+ public static String getSystemModel() {
+ return android.os.Build.MODEL;
+ }
+
+ /**
+ * 获取手机厂商
+ *
+ * @return 手机厂商
+ */
+ public static String getDeviceBrand() {
+ return android.os.Build.BRAND;
+ }
+}
diff --git a/app/src/main/res/layout/activity_main1.xml b/app/src/main/res/layout/activity_main1.xml
new file mode 100644
index 0000000..f82b13c
--- /dev/null
+++ b/app/src/main/res/layout/activity_main1.xml
@@ -0,0 +1,221 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mylibrary/src/main/java/com/dahe/mylibrary/utils/MobileInfoUtils.java b/mylibrary/src/main/java/com/dahe/mylibrary/utils/MobileInfoUtils.java
new file mode 100644
index 0000000..421b9c0
--- /dev/null
+++ b/mylibrary/src/main/java/com/dahe/mylibrary/utils/MobileInfoUtils.java
@@ -0,0 +1,163 @@
+package com.dahe.mylibrary.utils;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Build;
+import android.provider.Settings;
+import android.util.Log;
+import android.view.WindowManager;
+
+import com.dahe.mylibrary.R;
+
+/**
+ * @ClassName MobileInfoUtils
+ * @Author 用户
+ * @Date 2022/10/8 10:18
+ * @Description TODO
+ */
+public class MobileInfoUtils {
+
+// private SettingDialogPermision dialog_per;
+
+ //获取手机类型
+
+ private static String getMobileType() {
+
+ return Build.MANUFACTURER;
+
+ }
+
+ //跳转至授权页面
+
+ public void jumpStartInterface(Context context) {
+
+ Intent intent = new Intent();
+
+ try {
+
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ Log.e("HLQ_Struggle", "******************当前手机型号为:" + getMobileType());
+
+ ComponentName componentName = null;
+
+ if (getMobileType().equals("Xiaomi")) { // 红米Note4测试通过
+
+ componentName = new ComponentName("com.miui.securitycenter", "com.miui.permcenter.autostart.AutoStartManagementActivity");
+
+ } else if (getMobileType().equals("Letv")) { // 乐视2测试通过
+
+ intent.setAction("com.letv.android.permissionautoboot");
+
+ } else if (getMobileType().equals("samsung")) { // 三星Note5测试通过
+
+ //componentName = new ComponentName("com.samsung.android.sm_cn", "com.samsung.android.sm.ui.ram.AutoRunActivity");
+
+ //componentName = ComponentName.unflattenFromString("com.samsung.android.sm/.ui.ram.RamActivity");// Permission Denial not exported from uid 1000,不允许被其他程序调用
+
+ componentName = ComponentName.unflattenFromString("com.samsung.android.sm/.app.dashboard.SmartManagerDashBoardActivity");
+
+ } else if (getMobileType().equals("HUAWEI")) { // 华为测试通过
+
+ //componentName = new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity");//锁屏清理
+
+ componentName = ComponentName.unflattenFromString("com.huawei.systemmanager/.startupmgr.ui.StartupNormalAppListActivity");//跳自启动管理
+
+ //SettingOverlayView.show(context);
+
+ } else if (getMobileType().equals("vivo")) { // VIVO测试通过
+
+ componentName = ComponentName.unflattenFromString("com.iqoo.secure/.safeguard.PurviewTabActivity");
+
+ } else if (getMobileType().equals("Meizu")) { //万恶的魅族
+
+ //componentName = ComponentName.unflattenFromString("com.meizu.safe/.permission.PermissionMainActivity");//跳转到手机管家
+
+ componentName = ComponentName.unflattenFromString("com.meizu.safe/.permission.SmartBGActivity");//跳转到后台管理页面
+
+ } else if (getMobileType().equals("OPPO")) { // OPPO R8205测试通过
+
+ componentName = ComponentName.unflattenFromString("com.oppo.safe/.permission.startup.StartupAppListActivity");
+
+ } else if (getMobileType().equals("ulong")) { // 360手机 未测试
+
+ componentName = new ComponentName("com.yulong.android.coolsafe", ".ui.activity.autorun.AutoRunListActivity");
+
+ } else {
+
+ // 将用户引导到系统设置页面
+
+ if (Build.VERSION.SDK_INT >= 9) {
+
+ Log.e("HLQ_Struggle", "APPLICATION_DETAILS_SETTINGS");
+
+ intent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
+
+ intent.setData(Uri.fromParts("package", context.getPackageName(), null));
+
+ } else if (Build.VERSION.SDK_INT <= 8) {
+
+ intent.setAction(Intent.ACTION_VIEW);
+
+ intent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
+
+ intent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName());
+
+ }
+
+ }
+
+ intent.setComponent(componentName);
+
+ context.startActivity(intent);
+
+// if (getMobileType().equals("Xiaomi")) {
+//
+// showtip();//显示弹窗(**特别注意**)
+//
+// }
+//
+// if (getMobileType().equals("samsung")){
+//
+// new SettingOverlayView().show(context);//
+//
+// }
+
+ } catch (Exception e) {//抛出异常就直接打开设置页面
+
+ Log.e("HLQ_Struggle", e.getLocalizedMessage());
+
+ intent = new Intent(Settings.ACTION_SETTINGS);
+
+ context.startActivity(intent);
+
+ }
+
+ }
+
+//小米手机显示弹窗
+
+// private void showtip() {
+//
+// try {
+//
+// dialog_per=new SettingDialogPermision(context, R.style.CustomDialog4);
+//
+// dialog_per.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);//注意这里改成吐司类型
+//
+// dialog_per.show();
+//
+// Log.e("HLQ_Struggle","显示弹窗");
+//
+// } catch (Exception e) {
+//
+// e.printStackTrace();
+//
+// Log.e("HLQ_Struggle", "没有显示弹窗"+e.getMessage());
+//
+// }
+//
+// }
+}