應用檢查後臺啓動權限的方法如下: public static boolean canBackgroundStart(Context context) { AppOpsManager ops = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); try { int op = 10021; // >= 23 // ops.checkOpNoThrow(op, uid, packageName) Method method = ops.getClass().getMethod("checkOpNoThrow", new Class[] {int.class, int.class, String.class} ); Integer result = (Integer) method.invoke(ops, op, Process.myUid(), context.getPackageName()); return result == AppOpsManager.MODE_ALLOWED; } catch (Exception e) { Log.e(TAG, "not support", e); } return false; }
該方法是申請“後臺彈出頁面”權限白名單時小米官方給出的檢查後臺啓動權限的方法。
需要的朋友拿走