标签:des style blog http color io os ar for
先扯会....好久没写Blog了....这段时间有点小忙...瞎忙.....忙的自己都感觉都不应该.....严重影响了生活质量......生活的幸福指数!!!.....到现在还特么的单身!!!求介绍啊......
MIUI是我个人非常喜欢的ROM....虽然有诸多的不爽....但是搞开发就能理解.....写好一个产品是多么的不易.....好多东西的不可控....精力的有限! 现在买手机都看能不能刷MIUI..不能刷的就犹豫了.....
===============盗链....盗内容的都是Erbility, Shability ========================
===============http://www.cnblogs.com/fangyucun/p/4027750.html=================
步入正题.....解决这个问题...无非就是2点
1.跳转
2.判断是否真的打开
......代码打开是别想了....要不然人家也不能弄着玩啊.....除非是你发现了什么....
跳转的思路很简单..手动找到那个界面..看看是哪个Activity.
public static ComponentName getTopComponentName(Context context) { ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); List< ActivityManager.RunningTaskInfo > taskInfo = am.getRunningTasks(1); ComponentName componentName = taskInfo.get(0).topActivity; return componentName; }
再通过ComponentName想知道什么不行啊.....不知道怎么执行....能想到这个问题...不应该吧....随便建议一下....跑个线程
下面就是跳转了....
/** * 打开MIUI权限管理界面(MIUI v5, v6) * @param context */ public static void openMiuiPermissionActivity(Context context) { Intent intent = new Intent("miui.intent.action.APP_PERM_EDITOR"); String rom = RomUtils.getRom(); if (RomUtils.ROM_MIUI_V5.equals(rom)) { PackageInfo pInfo = null; try { pInfo = context.getPackageManager().getPackageInfo(packageName, 0); } catch (NameNotFoundException e) { Flog.e(e); } intent.setClassName(SETTINGS_PACKAGE_NAME, "com.miui.securitycenter.permission.AppPermissionsEditor"); intent.putExtra("extra_package_uid", pInfo.applicationInfo.uid); } else if (RomUtils.ROM_MIUI_V6.equals(rom)) { intent.setClassName("com.miui.securitycenter", "com.miui.permcenter.permissions.AppPermissionsEditorActivity"); intent.putExtra("extra_pkgname", context.getPackageName()); } if (isIntentAvailable(context, intent)) { if (context instanceof Activity) { Activity a = (Activity) context; a.startActivityForResult(intent, 2); } } else { Flog.e("Intent is not available!"); } }
很可惜....V5的悬浮窗权限在应用详情里面...
@TargetApi(9) public static void openAppDetailActivity(Context context, String packageName) { Intent intent = null; if (Build.VERSION.SDK_INT >= 9) { intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); Uri uri = Uri.fromParts(SCHEME_PACKAGE, packageName, null); intent.setData(uri); } else { final String className = Build.VERSION.SDK_INT == 8 ? SETTINGS_APPDETAILS_CLASS_NAME_22 : SETTINGS_APPDETAILS_CLASS_NAME_B21; intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(SETTINGS_PACKAGE_NAME, SETTINGS_APPDETAILS_CLASS_NAME); intent.putExtra(className, packageName); } if (isIntentAvailable(context, intent)) { context.startActivity(intent); } else { Flog.e("intent is not available!"); } }
另外加了个Intent的判断
/** * 判断是否有可以接受的Activity * @param context * @param action * @return */ public static boolean isIntentAvailable(Context context, Intent intent) { if (intent == null) return false; return context.getPackageManager().queryIntentActivities(intent, PackageManager.GET_ACTIVITIES).size() > 0; }
v5, v6不知道怎么判断? 好吧...有点跑题了....
public static String getSystemProperty() { String line = null; BufferedReader reader = null; try { Process p = Runtime.getRuntime().exec("getprop ro.miui.ui.version.name" ); reader = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024); line = reader.readLine(); return line; } catch (IOException e) { Flog.e(e); } finally { IoUtils.close(reader); } return "UNKNOWN"; }
根据返回的是V5还是V6判断
=====完成跳转.....下面就是判断了......自己是没琢磨出来....问的MIUI的工程师.....小帅哥太帅了.....感谢.....
/** * 判断MIUI的悬浮窗权限 * @param context * @return */ @TargetApi(Build.VERSION_CODES.KITKAT) public static boolean isMiuiFloatWindowOpAllowed(Context context) { final int version = Build.VERSION.SDK_INT; if (version >= 19) { checkOp(context, OP_SYSTEM_ALERT_WINDOW); //自己写就是24 为什么是24?看AppOpsManager } else { if ((context.getApplicationInfo().flags & 1<<27) == 1) { return true; } else { return false; } } return false; }
@TargetApi(Build.VERSION_CODES.KITKAT) public static boolean checkOp(Context context, int op) { final int version = Build.VERSION.SDK_INT; if (version >= 19) { AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); try { if (AppOpsManager.MODE_ALLOWED == (Integer)ReflectUtils.invokeMethod(manager, "checkOp", op,
Binder.getCallingUid(), context.packageName())) { //这儿反射就自己写吧 return true; } else { return false; } } catch (Exception e) { Flog.e(e.getMessage()); } } else { Flog.e("Below API 19 cannot invoke!"); } return false; }
到这儿就完事了...没想到牵扯的代码还挺多.......
标签:des style blog http color io os ar for
原文地址:http://www.cnblogs.com/fangyucun/p/4027750.html