我有一个ListView,其中包含安装的应用程序列表,对于每个应用程序,我需要知道通知是否已启用。 目前,我使用以下代码来了解通知是否已启用:
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, appUID, appPackage) == AppOpsManager.MODE_ALLOWED);
我遇到了以下异常:
Caused by: java.lang.SecurityException: uid 10062 does not have android.permission.UPDATE_APP_OPS_STATS. W/System.err: at android.os.Parcel.readException(Parcel.java:1683) W/System.err: at android.os.Parcel.readException(Parcel.java:1636) W/System.err: at com.android.internal.app.IAppOpsService$Stub$Proxy.checkOperation(IAppOpsService.java:343)
我已经包含了
<uses-permission android:name="android.permission.UPDATE_APP_OPS_STATS"/>
我仍然遇到相同的错误。 使用哪些API可以获取该值,以确定它是否被阻止。
NotificationManager.getNotificationPolicy()
是否适合您。链接 - sonictt1