java
13
4public class NotificationsUtils {
5
6private static final String CHECK_OP_NO_THROW = "checkOpNoThrow";
7private static final String OP_POST_NOTIFICATION = "OP_POST_NOTIFICATION";
8
9public static boolean isNotificationEnabled(Context context) {
10
11 AppOpsManager mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
12
13 ApplicationInfo appInfo = context.getApplicationInfo();
14
15 String pkg = context.getApplicationContext().getPackageName();
16
17 int uid = appInfo.uid;
18
19 Class appOpsClass = null; /* Context.APP_OPS_MANAGER */
20
21 try {
22
23 appOpsClass = Class.forName(AppOpsManager.class.getName());
24
25 Method checkOpNoThrowMethod = appOpsClass.getMethod(CHECK_OP_NO_THROW, Integer.TYPE, Integer.TYPE, String.class);
26
27 Field opPostNotificationValue = appOpsClass.getDeclaredField(OP_POST_NOTIFICATION);
28 int value = (int)opPostNotificationValue.get(Integer.class);
29
30 return ((int)checkOpNoThrowMethod.invoke(mAppOps,value, uid, pkg) == AppOpsManager.MODE_ALLOWED);
31
32 } catch (ClassNotFoundException e) {
33 e.printStackTrace();
34 } catch (NoSuchMethodException e) {
35 e.printStackTrace();
36 } catch (NoSuchFieldException e) {
37 e.printStackTrace();
38 } catch (InvocationTargetException e) {
39 e.printStackTrace();
40 } catch (IllegalAccessException e) {
41 e.printStackTrace();
42 }
43 return false;
44}
45}
java
1NotificationsUtils.isNotificationEnabled(getApplicationContext())
SC-04E
Android 5.0.1
で確認したところ問題ありませんでした。
参照したURLは以下のようになります。
https://code.google.com/p/android/issues/detail?id=38482
http://stackoverflow.com/questions/11649151/android-4-1-how-to-check-notifications-are-disabled-for-the-application
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/14 00:29
2016/03/14 03:20