当前位置: 首页>>代码示例>>Java>>正文


Java AppOpsManager.MODE_ALLOWED属性代码示例

本文整理汇总了Java中android.app.AppOpsManager.MODE_ALLOWED属性的典型用法代码示例。如果您正苦于以下问题:Java AppOpsManager.MODE_ALLOWED属性的具体用法?Java AppOpsManager.MODE_ALLOWED怎么用?Java AppOpsManager.MODE_ALLOWED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.app.AppOpsManager的用法示例。


在下文中一共展示了AppOpsManager.MODE_ALLOWED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: usagePermissionCheck

public static boolean usagePermissionCheck(Context context) {
    boolean granted = false;
    if (context != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        try {
            AppOpsManager appOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
            int mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, android.os.Process.myUid(), context.getPackageName());
            if (mode == AppOpsManager.MODE_DEFAULT) {
                String permissionUsage = "android.permission.PACKAGE_USAGE_STATS";
                granted = (context.checkCallingOrSelfPermission(permissionUsage) == PackageManager.PERMISSION_GRANTED);
            } else {
                granted = (mode == AppOpsManager.MODE_ALLOWED);
            }
        } catch (Throwable e) {
        }
    }
    return granted;
}
 
开发者ID:miLLlulei,项目名称:Accessibility,代码行数:17,代码来源:PackageUsageHelper.java

示例2: checkOp

@TargetApi(Build.VERSION_CODES.KITKAT)
private 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 {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int) method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
开发者ID:Sora-Shiro,项目名称:LemonYi,代码行数:17,代码来源:MiuiUtils.java

示例3: checkOp

@TargetApi(Build.VERSION_CODES.KITKAT)
private 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 {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e("", "Below API 19 cannot invoke!");
    }
    return false;
}
 
开发者ID:Sora-Shiro,项目名称:LemonYi,代码行数:17,代码来源:QikuUtils.java

示例4: HavaPermissionForTest

/**
 * 判断是否有用权限
 *
 * @param context 上下文参数
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean HavaPermissionForTest(Context context)
{
    try
    {
        PackageManager packageManager = context.getPackageManager();
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
        AppOpsManager appOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        int mode = 0;
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName);
        }
        return (mode == AppOpsManager.MODE_ALLOWED);
    } catch (PackageManager.NameNotFoundException e)
    {
        return true;
    }
}
 
开发者ID:heipidage,项目名称:GcmForMojo,代码行数:24,代码来源:MessageUtil.java

示例5: checkAlertWindowsPermission

public static boolean checkAlertWindowsPermission(Context context) {
	try {
		Object object = context.getSystemService(Context.APP_OPS_SERVICE);
		if (object == null) {
			return false;
		}
		Class localClass = object.getClass();
		Class[] arrayOfClass = new Class[3];
		arrayOfClass[0] = Integer.TYPE;
		arrayOfClass[1] = Integer.TYPE;
		arrayOfClass[2] = String.class;
		Method method = localClass.getMethod("checkOp", arrayOfClass);
		if (method == null) {
			return false;
		}
		Object[] arrayOfObject1 = new Object[3];
		arrayOfObject1[0] = 24;
		arrayOfObject1[1] = Binder.getCallingUid();
		arrayOfObject1[2] = context.getPackageName();
		int m = ((Integer) method.invoke(object, arrayOfObject1));
		return m == AppOpsManager.MODE_ALLOWED;
	} catch (Exception ex) {

	}
	return false;
}
 
开发者ID:stytooldex,项目名称:stynico,代码行数:26,代码来源:testThread.java

示例6: checkOp

@TargetApi(Build.VERSION_CODES.KITKAT)
private 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 {
            Class clazz = AppOpsManager.class;
            Method method = clazz.getDeclaredMethod("checkOp", int.class, int.class, String.class);
            return AppOpsManager.MODE_ALLOWED == (int)method.invoke(manager, op, Binder.getCallingUid(), context.getPackageName());
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:17,代码来源:MeizuUtils.java

示例7: checkOp

@TargetApi(19)
private static boolean checkOp(Context context, int op) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= Build.VERSION_CODES.KITKAT) {
        AppOpsManager manager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
        try {
            Method method = manager.getClass().getDeclaredMethod("checkOp", int.class, int.class, String.class);
            int property = (Integer) method.invoke(manager, op,
                    Binder.getCallingUid(), context.getPackageName());
            return AppOpsManager.MODE_ALLOWED == property;
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
    }
    return false;
}
 
开发者ID:coopese,项目名称:qmui,代码行数:17,代码来源:QMUIDeviceHelper.java

示例8: checkPermissionCamera

private void checkPermissionCamera() {
    int checkPermission = 0;
    if (Build.VERSION.SDK_INT >= 23) {
        // checkPermission =ContextCompat.checkSelfPermission(this,Manifest.permission.CAMERA);
        checkPermission = PermissionChecker.checkSelfPermission(this, Manifest.permission.CAMERA);
        if (checkPermission != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.CAMERA},
                    MY_PERMISSIONS_REQUEST_CAMERA);
        } else {
            isOpenCamera = true;
        }

    } else {
        checkPermission = checkPermission(26);
        if (checkPermission == AppOpsManager.MODE_ALLOWED) {
            isOpenCamera = true;
        } else if (checkPermission == AppOpsManager.MODE_IGNORED) {
            isOpenCamera = false;
            displayFrameworkBugMessageAndExit();
        }
    }
}
 
开发者ID:zybieku,项目名称:ZbarCode,代码行数:23,代码来源:CaptureActivity.java

示例9: hasAuthorFloatWin

/**
 * 判断是否开启浮窗权限
 * @return
 */
public static int hasAuthorFloatWin(Context context){

    if (DeviceInfoUtil.getSystemVersion() < 19){
        return NOT_SUPPORT_AUTHOR;
    }
    try {
        AppOpsManager appOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE);
        Class c = appOps.getClass();
        Class[] cArg = new Class[3];
        cArg[0] = int.class;
        cArg[1] = int.class;
        cArg[2] = String.class;
        Method lMethod = c.getDeclaredMethod("checkOp", cArg);
        if (AppOpsManager.MODE_ALLOWED == (Integer) lMethod.invoke(appOps, 24, Binder.getCallingUid(), context.getPackageName())){
            return HAS_AUTHOR;
        } else {
            return NOT_AUTHOR;
        }

    } catch(Exception e) {
       return NOT_SUPPORT_AUTHOR;
    }

}
 
开发者ID:liuguangli,项目名称:FloatUtil,代码行数:28,代码来源:SmartFloatUtil.java

示例10: isNotificationEnabled

public static boolean isNotificationEnabled(Context context) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
            ApplicationInfo appInfo = context.getApplicationInfo();
            String pkg = context.getApplicationContext().getPackageName();
            int uid = appInfo.uid;
            Class appOpsClass = null; /* Context.APP_OPS_MANAGER */
            appOpsClass = Class.forName(AppOpsManager.class.getName());
            Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class);
            Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION);
            int value = (int) opPostNotificationValue.get(Integer.class);
            return ((int) checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg) == AppOpsManager.MODE_ALLOWED);
        }
    } catch (Exception e) {
    }
    return true;
}
 
开发者ID:LiangMaYong,项目名称:android-base,代码行数:18,代码来源:ToastCompat.java

示例11: checkOp

@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 {
            Method method = manager.getClass().getDeclaredMethod("checkOp", int.class, int.class, String.class);
            int property = (Integer) method.invoke(manager, op,
                    Binder.getCallingUid(), context.getPackageName());
            if (AppOpsManager.MODE_ALLOWED == property) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        Log.e(TAG, "Below API 19 cannot invoke!");
    }
    return false;
}
 
开发者ID:xingstarx,项目名称:XiaoMiContactsHelper,代码行数:22,代码来源:MIUIUtils.java

示例12: isAccessGranted

private boolean isAccessGranted() {
    try {
        PackageManager packageManager = getPackageManager();
        ApplicationInfo applicationInfo = packageManager.getApplicationInfo(getPackageName(), 0);
        AppOpsManager appOpsManager = (AppOpsManager) getSystemService(Context.APP_OPS_SERVICE);
        int mode = 0;
        if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.KITKAT) {
            mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
                    applicationInfo.uid, applicationInfo.packageName);
        }
        return (mode == AppOpsManager.MODE_ALLOWED);

    } catch (PackageManager.NameNotFoundException e) {
        return false;
    }
}
 
开发者ID:IvanVolosyuk,项目名称:diskusage,代码行数:16,代码来源:PermissionRequestActivity.java

示例13: hasPermission

private boolean hasPermission() {
    AppOpsManager appOps = (AppOpsManager)
            getSystemService(Context.APP_OPS_SERVICE);
    int mode = 0;
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
        mode = appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
                android.os.Process.myUid(), getPackageName());
    }
    return mode == AppOpsManager.MODE_ALLOWED;
}
 
开发者ID:Sl0v3C,项目名称:Android_AutoSignInTool,代码行数:10,代码来源:MainPage.java

示例14: checkUsageStatsPermission

/**
 * Check if the user has granted the usage stats permission, which must be manually complete via the
 * settings.
 *
 * @param ctx the application context
 * @return true if the permissions have been granted, false otherwise
 */
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static boolean checkUsageStatsPermission(@NonNull final Context ctx) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "checkUsageStatsPermission");
    }

    final AppOpsManager appOps = (AppOpsManager) ctx.getSystemService(Context.APP_OPS_SERVICE);

    return appOps.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS,
            android.os.Process.myUid(), ctx.getPackageName()) == AppOpsManager.MODE_ALLOWED;
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:18,代码来源:PermissionHelper.java

示例15: canAllow

public boolean canAllow() {
    if (mSelected.isEmpty()) {
        return false;
    }
    for (OpsInfo opsInfo : mOpsInfo) {
        if (mSelected.contains(opsInfo.op) && opsInfo.mode != AppOpsManager.MODE_ALLOWED) {
            return true;
        }
    }
    return false;
}
 
开发者ID:brevent,项目名称:Brevent,代码行数:11,代码来源:OpsItemAdapter.java


注:本文中的android.app.AppOpsManager.MODE_ALLOWED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。