小米、Vivo、Oppo后台弹出界面和锁屏权限检测

您所在的位置:网站首页 小米手机相机权限怎么开启 小米、Vivo、Oppo后台弹出界面和锁屏权限检测

小米、Vivo、Oppo后台弹出界面和锁屏权限检测

2024-04-05 19:43| 来源: 网络整理| 查看: 265

最近有个需求,是说要app退居到桌面的时候,收到消息要主动打开app内指定界面,这块理论上直接设置跳转界面就完了,事实在华为手机测试也没问题的,然后现实给你啪啪的打脸了

发现到了小米,Vivo跟Oppo手机上,这个就不行了,我去

然后经过了一番搜索,终于找到了,这块功能是在https://github.com/zhoulinxue/BGStart参考了这个大佬封装的库上面改的

直接上代码:

/** * 小米后台弹出界面权限检测 * @param context * @return */ public static boolean isAllowedBackPopPermission(Context context) { AppOpsManager ops = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); try { int op = 10021; Method method = ops.getClass().getMethod("checkOpNoThrow", new Class[]{int.class, int.class, String.class}); Integer result = (Integer) method.invoke(ops, op, android.os.Process.myUid(), context.getPackageName()); return result == AppOpsManager.MODE_ALLOWED; } catch (Exception e) { Log.e(TAG, "not support"); } return false; } /** * 小米后台锁屏检测方法 * @param context * @return */ public static boolean canShowLockView(Context context) { AppOpsManager ops = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { ops = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); } try { int op = 10020; // >= 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, android.os.Process.myUid(), context.getPackageName()); return result == AppOpsManager.MODE_ALLOWED; } catch (Exception e) { e.printStackTrace(); } return false; } /** * 判断vivo后台弹出界面 1未开启 0开启 * * @param context * @return */ public static int getvivoBgStartActivityPermissionStatus(Context context) { String packageName = context.getPackageName(); Uri uri2 = Uri.parse("content://com.vivo.permissionmanager.provider.permission/start_bg_activity"); String selection = "pkgname = ?"; String[] selectionArgs = new String[]{packageName}; try { Cursor cursor = context .getContentResolver() .query(uri2, null, selection, selectionArgs, null); if (cursor != null) { if (cursor.moveToFirst()) { int currentmode = cursor.getInt(cursor.getColumnIndex("currentstate")); cursor.close(); return currentmode; } else { cursor.close(); return 1; } } } catch (Throwable throwable) { throwable.printStackTrace(); } return 1; } /** * 判断vivo锁屏显示 1未开启 0开启 * @param context * @return */ public static int getVivoLockStatus(Context context) { String packageName = context.getPackageName(); Uri uri2 = Uri.parse("content://com.vivo.permissionmanager.provider.permission/control_locked_screen_action"); String selection = "pkgname = ?"; String[] selectionArgs = new String[]{packageName}; try { Cursor cursor = context .getContentResolver() .query(uri2, null, selection, selectionArgs, null); if (cursor != null) { if (cursor.moveToFirst()) { int currentmode = cursor.getInt(cursor.getColumnIndex("currentstate")); cursor.close(); return currentmode; } else { cursor.close(); return 1; } } } catch (Throwable throwable) { throwable.printStackTrace(); } return 1; } oppo: Settings.canDrawOverlays(activity)

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3