Java Code Examples for android.app.NotificationManager#isNotificationPolicyAccessGranted()
The following examples show how to use
android.app.NotificationManager#isNotificationPolicyAccessGranted() .
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: SettingsActivity.java From Finder with GNU General Public License v3.0 | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); NotificationManager nManage = (NotificationManager) getActivity().getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= 23 && stringValue.equals("true") && !nManage.isNotificationPolicyAccessGranted()) { //request for muting permission Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); Toast.makeText(getActivity(), R.string.enable_sound, Toast.LENGTH_LONG).show(); if (preference.getKey().equals("disable_sound")) { startActivityForResult(intent, REQUEST_CODE_MUTE); } else { startActivityForResult(intent, REQUEST_CODE_TRACKING); } return false; } return true; }
Example 2
Source File: SettingsActivity.java From Finder with GNU General Public License v3.0 | 6 votes |
@Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); if (stringValue.equals("")) { Toast.makeText(getActivity(), R.string.wrong_values, Toast.LENGTH_LONG).show(); return false; } NotificationManager nManage = (NotificationManager) getActivity().getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= 23 && !nManage.isNotificationPolicyAccessGranted()) { //request for muting permission Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); Toast.makeText(getActivity(), R.string.enable_sound, Toast.LENGTH_LONG).show(); new_ring_command = stringValue; startActivityForResult(intent, REQUEST_CODE_RINGING); return false; } return true; }
Example 3
Source File: AudioManagerUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 判断是否授权 Do not disturb 权限 * <pre> * 授权 Do not disturb 权限, 才可进行音量操作 * </pre> * @param setting 如果没授权, 是否跳转到设置页面 * @return {@code true} yes, {@code false} no */ public static boolean isDoNotDisturb(final boolean setting) { try { NotificationManager notificationManager = AppUtils.getNotificationManager(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !notificationManager.isNotificationPolicyAccessGranted()) { if (setting) { Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); AppUtils.startActivity(intent); } } else { return true; } } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "isDoNotDisturb"); } return false; }
Example 4
Source File: AutoDoNotDisturbReceiver.java From GotoSleep with GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { Log.d("AutoDnDReceiver", "Attempting to enable DnD"); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context); Calendar bedtime; bedtime = getBedtimeCal(parseBedtime(settings.getString(BEDTIME_KEY, "22:00"))); NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && mNotificationManager.isNotificationPolicyAccessGranted()) { mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALARMS); Toast.makeText(context, context.getString(R.string.autoDnDToast), Toast.LENGTH_SHORT).show(); } mNotificationManager.cancel(NOTIFICATION_REQUEST_CODE); cancelNextNotification(context); setNextDayNotification(context, bedtime, TAG); }
Example 5
Source File: PermissionUtils.java From prayer-times-android with Apache License 2.0 | 6 votes |
private void checkPermissions(@NonNull Context c) { pCalendar = ContextCompat.checkSelfPermission(c, Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(c, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED; pStorage = ContextCompat.checkSelfPermission(c, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(c, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; pLocation = ContextCompat.checkSelfPermission(c, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE); pNotPolicy = nm.isNotificationPolicyAccessGranted(); Crashlytics.setBool("pNotPolicy", pLocation); } else pNotPolicy = true; Crashlytics.setBool("pCalendar", pCalendar); Crashlytics.setBool("pStorage", pStorage); Crashlytics.setBool("pLocation", pLocation); Crashlytics.setBool("pNotPolicy", pNotPolicy); }
Example 6
Source File: PermissionUtils.java From prayer-times-android with Apache License 2.0 | 6 votes |
public void needNotificationPolicy(@NonNull final Activity act) { if (act.isDestroyed()) return; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return; } NotificationManager nm = (NotificationManager) act.getSystemService(Context.NOTIFICATION_SERVICE); pNotPolicy = nm.isNotificationPolicyAccessGranted(); if (!pNotPolicy) { Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); PackageManager packageManager = act.getPackageManager(); if (intent.resolveActivity(packageManager) != null) { act.startActivity(intent); } else { ActivityCompat.requestPermissions(act, new String[]{Manifest.permission.ACCESS_NOTIFICATION_POLICY}, 0); } } }
Example 7
Source File: PermissionUtils.java From prayer-times-android with Apache License 2.0 | 6 votes |
public void needNotificationPolicy(@NonNull final Activity act) { if (act.isDestroyed()) return; if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { return; } NotificationManager nm = (NotificationManager) act.getSystemService(Context.NOTIFICATION_SERVICE); pNotPolicy = nm.isNotificationPolicyAccessGranted(); if (!pNotPolicy) { Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); PackageManager packageManager = act.getPackageManager(); if (intent.resolveActivity(packageManager) != null) { act.startActivity(intent); } else { ActivityCompat.requestPermissions(act, new String[]{Manifest.permission.ACCESS_NOTIFICATION_POLICY}, 0); } } }
Example 8
Source File: PermissionUtils.java From prayer-times-android with Apache License 2.0 | 6 votes |
private void checkPermissions(@NonNull Context c) { pCalendar = ContextCompat.checkSelfPermission(c, Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(c, Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED; pStorage = ContextCompat.checkSelfPermission(c, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(c, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED; pLocation = ContextCompat.checkSelfPermission(c, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE); pNotPolicy = nm.isNotificationPolicyAccessGranted(); Crashlytics.setBool("pNotPolicy", pLocation); } else pNotPolicy = true; Crashlytics.setBool("pCalendar", pCalendar); Crashlytics.setBool("pStorage", pStorage); Crashlytics.setBool("pLocation", pLocation); Crashlytics.setBool("pNotPolicy", pNotPolicy); }
Example 9
Source File: DoNotDisturbUtil.java From mollyim-android with GNU General Public License v3.0 | 6 votes |
@RequiresApi(23) private static boolean handlePriority(@NonNull Context context, @NonNull NotificationManager notificationManager, @NonNull Recipient recipient) { if (Build.VERSION.SDK_INT < 28 && !notificationManager.isNotificationPolicyAccessGranted()) { Log.w(TAG, "Notification Policy is not granted"); return true; } final NotificationManager.Policy policy = notificationManager.getNotificationPolicy(); final boolean areCallsPrioritized = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_CALLS) != 0; final boolean isRepeatCallerEnabled = (policy.priorityCategories & NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS) != 0; if (!areCallsPrioritized && !isRepeatCallerEnabled) { return false; } if (areCallsPrioritized && !isRepeatCallerEnabled) { return isContactPriority(context, recipient, policy.priorityCallSenders); } if (!areCallsPrioritized) { return isRepeatCaller(context, recipient); } return isContactPriority(context, recipient, policy.priorityCallSenders) || isRepeatCaller(context, recipient); }
Example 10
Source File: PermissionUtils.java From SimpleSmsRemote with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.N) private static void RequestAccessNotificationPolicyPermission(Activity activity) { NotificationManager notificationManager = (NotificationManager) activity.getSystemService(Context.NOTIFICATION_SERVICE); if (!notificationManager.isNotificationPolicyAccessGranted()) { Intent intent = new Intent( android.provider.Settings .ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); activity.startActivity(intent); } }
Example 11
Source File: SettingsActivity.java From KUAS-AP-Material with MIT License | 5 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == PERMISSION_REQUEST_NOTIFICATION_POLICY_ACCESS_SETTING) { NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && notificationManager.isNotificationPolicyAccessGranted()) { setUpCourseVibrate(); } } }
Example 12
Source File: SettingsActivity.java From KUAS-AP-Material with MIT License | 5 votes |
private void restorePreference() { mHeadPhotoSwitch.setChecked(Memory.getBoolean(this, Constant.PREF_HEAD_PHOTO, true)); mNotifyCourseSwitch.setChecked(Memory.getBoolean(this, Constant.PREF_COURSE_NOTIFY, false)); mNotifyBusSwitch.setChecked(Memory.getBoolean(this, Constant.PREF_BUS_NOTIFY, false)); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !notificationManager.isNotificationPolicyAccessGranted()) { Memory.setBoolean(this, Constant.PREF_COURSE_VIBRATE, false); } mVibrateCourseSwitch .setChecked(Memory.getBoolean(this, Constant.PREF_COURSE_VIBRATE, false)); }
Example 13
Source File: AudioPauser.java From speechutils with Apache License 2.0 | 5 votes |
/** * Creates and returns an AudioPauser. * * @param context Context * @param isMuteStream if true then we additionally try to mute the audio stream. * This does not succeed if the app is not allowed to * "modify notification do not disturb policy" on Android N and higher. * @return AudioPauser */ public static AudioPauser createAudioPauser(Context context, boolean isMuteStream) { if (isMuteStream && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (nm != null && !nm.isNotificationPolicyAccessGranted()) { isMuteStream = false; } } return new AudioPauser(context, isMuteStream); }
Example 14
Source File: PermissionUtils.java From SimpleSmsRemote with MIT License | 5 votes |
/** * Check if the app has a specific permissions * * @param context app context * @param permission permission to check * @return true if app has permission */ public static boolean AppHasPermission(Context context, String permission) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && permission.equals(Manifest.permission.WRITE_SETTINGS)) { return Settings.System.canWrite(context); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && permission.equals(Manifest.permission.ACCESS_NOTIFICATION_POLICY)) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); return notificationManager.isNotificationPolicyAccessGranted(); } return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; }
Example 15
Source File: MrNotification.java From BaseProject with Apache License 2.0 | 5 votes |
/** * 是否授予音量操作的权限 * <a>https://blog.csdn.net/manjianchao/article/details/77576638</a> * @param context * @return */ public static boolean isNotificationPolicyAccessGranted(Context context) { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (nm != null && Build.VERSION.SDK_INT >= 23) { return nm.isNotificationPolicyAccessGranted();//need api >= 23 } return true; }
Example 16
Source File: SettingsActivity.java From KUAS-AP-Material with MIT License | 4 votes |
private void setUpCourseVibrate() { mTracker.send( new HitBuilders.EventBuilder().setCategory("vibrate course").setAction("create") .build()); mVibrateCourseSwitch.setChecked(!mVibrateCourseSwitch.isChecked()); mTracker.send( new HitBuilders.EventBuilder().setCategory("vibrate course").setAction("click") .setLabel(mVibrateCourseSwitch.isChecked() + "").build()); if (!mVibrateCourseSwitch.isChecked()) { Memory.setBoolean(SettingsActivity.this, Constant.PREF_COURSE_VIBRATE, false); return; } NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !notificationManager.isNotificationPolicyAccessGranted()) { mVibrateCourseSwitch.setChecked(false); Memory.setBoolean(SettingsActivity.this, Constant.PREF_COURSE_VIBRATE, false); new AlertDialog.Builder(this).setMessage(R.string.course_vibrate_permission) .setPositiveButton(R.string.go_to_settings, new DialogInterface.OnClickListener() { @TargetApi(Build.VERSION_CODES.N) @Override public void onClick(DialogInterface dialogInterface, int i) { Intent intent = new Intent( android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); startActivityForResult(intent, PERMISSION_REQUEST_NOTIFICATION_POLICY_ACCESS_SETTING); } }).setNegativeButton(R.string.skip, null).show(); return; } final Dialog progressDialog = Utils.createLoadingDialog(this, R.string.loading); progressDialog.show(); Utils.setUpCourseNotify(this, new GeneralCallback() { @Override public void onSuccess() { super.onSuccess(); mTracker.send(new HitBuilders.EventBuilder().setCategory("vibrate course") .setAction("status").setLabel("success").build()); Memory.setBoolean(SettingsActivity.this, Constant.PREF_COURSE_VIBRATE, true); Utils.dismissDialog(progressDialog); Toast.makeText(SettingsActivity.this, R.string.course_vibrate_hint, Toast.LENGTH_LONG).show(); Toast.makeText(SettingsActivity.this, R.string.beta_function, Toast.LENGTH_SHORT) .show(); } @Override public void onFail(String errorMessage) { super.onFail(errorMessage); mTracker.send(new HitBuilders.EventBuilder().setCategory("vibrate course") .setAction("status").setLabel("fail " + errorMessage).build()); Utils.dismissDialog(progressDialog); mVibrateCourseSwitch.setChecked(false); Memory.setBoolean(SettingsActivity.this, Constant.PREF_COURSE_VIBRATE, false); Toast.makeText(SettingsActivity.this, errorMessage, Toast.LENGTH_SHORT).show(); } @Override public void onTokenExpired() { super.onTokenExpired(); mTracker.send(new HitBuilders.EventBuilder().setCategory("vibrate course") .setAction("status").setLabel("token expired").build()); Utils.dismissDialog(progressDialog); Utils.showTokenExpired(SettingsActivity.this); } }); }
Example 17
Source File: ApiTwentyThreePlus.java From linphone-android with GNU General Public License v3.0 | 4 votes |
public static boolean isDoNotDisturbPolicyAllowingRinging( Context context, Address remoteAddress) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); int filter = notificationManager.getCurrentInterruptionFilter(); if (filter == NotificationManager.INTERRUPTION_FILTER_PRIORITY) { Log.w("[Audio Manager] Priority interruption filter detected"); boolean accessGranted = notificationManager.isNotificationPolicyAccessGranted(); if (!accessGranted) { Log.e( "[Audio Manager] Access to policy is denied, let's assume it is not safe for ringing"); return false; } NotificationManager.Policy policy = notificationManager.getNotificationPolicy(); int callPolicy = policy.priorityCallSenders; if (callPolicy == NotificationManager.Policy.PRIORITY_SENDERS_ANY) { Log.i("[Audio Manager] Priority for calls is Any, we can ring"); } else { if (remoteAddress == null) { Log.e( "[Audio Manager] Remote address is null, let's assume it is not safe for ringing"); return false; } LinphoneContact contact = ContactsManager.getInstance().findContactFromAddress(remoteAddress); if (callPolicy == NotificationManager.Policy.PRIORITY_SENDERS_CONTACTS) { Log.i("[Audio Manager] Priority for calls is Contacts, let's check"); if (contact == null) { Log.w( "[Audio Manager] Couldn't find a contact for address " + remoteAddress.asStringUriOnly()); return false; } else { Log.i( "[Audio Manager] Contact found for address " + remoteAddress.asStringUriOnly() + ", we can ring"); } } else if (callPolicy == NotificationManager.Policy.PRIORITY_SENDERS_STARRED) { Log.i("[Audio Manager] Priority for calls is Starred Contacts, let's check"); if (contact == null) { Log.w( "[Audio Manager] Couldn't find a contact for address " + remoteAddress.asStringUriOnly()); return false; } else if (!contact.isFavourite()) { Log.w( "[Audio Manager] Contact found for address " + remoteAddress.asStringUriOnly() + ", but it isn't starred"); return false; } else { Log.i( "[Audio Manager] Starred contact found for address " + remoteAddress.asStringUriOnly() + ", we can ring"); } } } } else if (filter == NotificationManager.INTERRUPTION_FILTER_ALARMS) { Log.w("[Audio Manager] Alarms interruption filter detected"); return false; } else { Log.i("[Audio Manager] Interruption filter is " + filter + ", we can ring"); } return true; }
Example 18
Source File: DNDModeChecker.java From volume_control_android with MIT License | 4 votes |
public static boolean isDNDPermissionGranted(Context context) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); return TestLabUtils.isInTestLab(context) || Build.VERSION.SDK_INT < Build.VERSION_CODES.M || notificationManager.isNotificationPolicyAccessGranted(); }
Example 19
Source File: GrantPermissionActivity.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
@TargetApi(Build.VERSION_CODES.M) @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { //noinspection SwitchStatementWithTooFewBranches switch (requestCode) { case PERMISSIONS_REQUEST_CODE: { // If request is cancelled, the result arrays are empty. //PPApplication.logE("GrantPermissionActivity.onRequestPermissionsResult", "grantResults.length="+grantResults.length); boolean allGranted = true; for (int grantResult : grantResults) { if (grantResult == PackageManager.PERMISSION_DENIED) { allGranted = false; //forceGrant = false; break; } } Context context = getApplicationContext(); for (Permissions.PermissionType permissionType : this.permissions) { if (permissionType.permission.equals(Manifest.permission.WRITE_SETTINGS)) { if (!Settings.System.canWrite(context)) { allGranted = false; break; } } if (permissionType.permission.equals(Manifest.permission.ACCESS_NOTIFICATION_POLICY)) { NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (mNotificationManager != null) { if (!mNotificationManager.isNotificationPolicyAccessGranted()) { allGranted = false; break; } } } if (permissionType.permission.equals(Manifest.permission.SYSTEM_ALERT_WINDOW)) { if (!Settings.canDrawOverlays(context)) { allGranted = false; break; } } } if (allGranted) { finishGrant(); } else { showRationale(context); } break; } // other 'case' lines to check for other // permissions this app might request } }
Example 20
Source File: ApiTwentyThreePlus.java From linphone-android with GNU General Public License v3.0 | 4 votes |
public static boolean isDoNotDisturbSettingsAccessGranted(Context context) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); return notificationManager.isNotificationPolicyAccessGranted(); }