Java Code Examples for android.support.v4.app.NotificationManagerCompat#areNotificationsEnabled()
The following examples show how to use
android.support.v4.app.NotificationManagerCompat#areNotificationsEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreferencesChannelsActivity.java From notification-channel-compat with Apache License 2.0 | 6 votes |
protected void loadFragment() { String channelId = getIntent().getStringExtra(INTENT_EXTRA_CHANNEL_ID); PreferenceFragmentCompat frag; NotificationManagerCompat manager = NotificationManagerCompat.from(this); if (!manager.areNotificationsEnabled()) frag = new PreferencesChannelsSystemFragment(); else frag = TextUtils.isEmpty(channelId) ? new PreferencesChannelsMainFragment() : PreferencesChannelsSubFragment.newInstance(channelId); getSupportFragmentManager() .beginTransaction() .replace(R.id.settings_container, frag) .commit(); }
Example 2
Source File: LocalNotificationManager.java From OsmGo with MIT License | 6 votes |
@Nullable public JSONArray schedule(PluginCall call, List<LocalNotification> localNotifications) { JSONArray ids = new JSONArray(); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); boolean notificationsEnabled = notificationManager.areNotificationsEnabled(); if (!notificationsEnabled) { call.error("Notifications not enabled on this device"); return null; } for (LocalNotification localNotification : localNotifications) { Integer id = localNotification.getId(); if (localNotification.getId() == null) { call.error("LocalNotification missing identifier"); return null; } dismissVisibleNotification(id); cancelTimerForNotification(id); buildNotification(notificationManager, localNotification, call); ids.put(id); } return ids; }
Example 3
Source File: PermissionCheck.java From android-push-settings-advisor with GNU General Public License v3.0 | 5 votes |
/** * 通知权限检查 * @param context * @return */ private static boolean isNotificationEnabled(Context context) { if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) { return false; } NotificationManagerCompat manager = NotificationManagerCompat.from(context); // areNotificationsEnabled方法的有效性官方只最低支持到API 19,低于19的仍可调用此方法不过只会返回true,即默认为用户已经开启了通知。 boolean isOpened = manager.areNotificationsEnabled(); return isOpened; // 目前有替代方法,但不保证完全适用, 故保留 // 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 */ // try { // 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 = (Integer) opPostNotificationValue.get(Integer.class); // int result = (Integer)checkOpNoThrowMethod.invoke(mAppOps, value, uid, pkg); // return result == AppOpsManager.MODE_ALLOWED; // } catch (ClassNotFoundException e) { // e.printStackTrace(); // } catch (NoSuchMethodException e) { // e.printStackTrace(); // } catch (NoSuchFieldException e) { // e.printStackTrace(); // } catch (InvocationTargetException e) { // e.printStackTrace(); // } catch (IllegalAccessException e) { // e.printStackTrace(); // } // return false; }
Example 4
Source File: PreferencesChannelsSystemFragment.java From notification-channel-compat with Apache License 2.0 | 5 votes |
@Override public void onResume() { super.onResume(); NotificationManagerCompat manager = NotificationManagerCompat.from(getContext()); if (manager.areNotificationsEnabled()) // user must have enabled it, so go to main screen { ((PreferencesChannelsActivity) getActivity()).loadFragment(); // will now load main or sub fragment based on origina intent } }
Example 5
Source File: LocalNotificationManager.java From OsmGo with MIT License | 4 votes |
public boolean areNotificationsEnabled(){ NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context); return notificationManager.areNotificationsEnabled(); }
Example 6
Source File: NotificationUtil.java From AppUpdate with Apache License 2.0 | 2 votes |
/** * 获取通知栏开关状态 * * @return true |false */ public static boolean notificationEnable(Context context) { NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context); return notificationManagerCompat.areNotificationsEnabled(); }