|
|
@@ -0,0 +1,106 @@
|
|
|
+package com.tongyu.luck.happywork.utils;
|
|
|
+
|
|
|
+import android.content.ComponentName;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Build;
|
|
|
+import android.text.TextUtils;
|
|
|
+
|
|
|
+import com.tongyu.luck.happywork.BuildConfig;
|
|
|
+import com.tongyu.luck.happywork.ui.base.BaseActivity;
|
|
|
+
|
|
|
+public class JumpUtils {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 前往权限设置
|
|
|
+ */
|
|
|
+ public static void goPermissionSetting(BaseActivity baseActivity) {
|
|
|
+ String sdk = android.os.Build.VERSION.SDK; // SDK号
|
|
|
+ String model = android.os.Build.MODEL; // 手机型号
|
|
|
+ String release = android.os.Build.VERSION.RELEASE; // android系统版本号
|
|
|
+ String brand = Build.BRAND;//手机厂商
|
|
|
+ if (TextUtils.equals(brand.toLowerCase(), "redmi") || TextUtils.equals(brand.toLowerCase(), "xiaomi")) {
|
|
|
+ gotoMiuiPermission(baseActivity);//小米
|
|
|
+ } else if (TextUtils.equals(brand.toLowerCase(), "meizu")) {
|
|
|
+ gotoMeizuPermission(baseActivity);
|
|
|
+ } else if (TextUtils.equals(brand.toLowerCase(), "huawei") || TextUtils.equals(brand.toLowerCase(), "honor")) {
|
|
|
+ gotoHuaweiPermission(baseActivity);
|
|
|
+ } else {
|
|
|
+ baseActivity.startActivity(getAppDetailSettingIntent());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到miui的权限管理页面
|
|
|
+ */
|
|
|
+ private static void gotoMiuiPermission(Context context) {
|
|
|
+ try { // MIUI 8
|
|
|
+ Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
|
|
|
+ localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.PermissionsEditorActivity");
|
|
|
+ localIntent.putExtra("extra_pkgname", context.getPackageName());
|
|
|
+ context.startActivity(localIntent);
|
|
|
+ } catch (Exception e) {
|
|
|
+ try { // MIUI 5/6/7
|
|
|
+ Intent localIntent = new Intent("miui.intent.action.APP_PERM_EDITOR");
|
|
|
+ localIntent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity");
|
|
|
+ localIntent.putExtra("extra_pkgname", context.getPackageName());
|
|
|
+ context.startActivity(localIntent);
|
|
|
+ } catch (Exception e1) { // 否则跳转到应用详情
|
|
|
+ context.startActivity(getAppDetailSettingIntent());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到魅族的权限管理系统
|
|
|
+ */
|
|
|
+ private static void gotoMeizuPermission(Context context) {
|
|
|
+ try {
|
|
|
+ Intent intent = new Intent("com.meizu.safe.security.SHOW_APPSEC");
|
|
|
+ intent.addCategory(Intent.CATEGORY_DEFAULT);
|
|
|
+ intent.putExtra("packageName", BuildConfig.APPLICATION_ID);
|
|
|
+ context.startActivity(intent);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ context.startActivity(getAppDetailSettingIntent());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 华为的权限管理页面
|
|
|
+ */
|
|
|
+ private static void gotoHuaweiPermission(Context context) {
|
|
|
+ try {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ ComponentName comp = new ComponentName("com.huawei.systemmanager", "com.huawei.permissionmanager.ui.MainActivity");//华为权限管理
|
|
|
+ intent.setComponent(comp);
|
|
|
+ context.startActivity(intent);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ context.startActivity(getAppDetailSettingIntent());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取应用详情页面intent(如果找不到要跳转的界面,也可以先把用户引导到系统设置页面)
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private static Intent getAppDetailSettingIntent() {
|
|
|
+ Intent localIntent = new Intent();
|
|
|
+ localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ if (Build.VERSION.SDK_INT >= 9) {
|
|
|
+ localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
|
|
|
+ localIntent.setData(Uri.fromParts("package", BuildConfig.APPLICATION_ID, null));
|
|
|
+ } else if (Build.VERSION.SDK_INT <= 8) {
|
|
|
+ localIntent.setAction(Intent.ACTION_VIEW);
|
|
|
+ localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
|
|
|
+ localIntent.putExtra("com.android.settings.ApplicationPkgName", BuildConfig.APPLICATION_ID);
|
|
|
+ }
|
|
|
+ return localIntent;
|
|
|
+
|
|
|
+ }
|
|
|
+}
|