android.app.NotificationManager#getNotificationPolicy ( )源码实例Demo

下面列出了android.app.NotificationManager#getNotificationPolicy ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mollyim-android   文件: DoNotDisturbUtil.java
@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);
}
 
源代码2 项目: SuntimesWidget   文件: AlarmNotifications.java
@TargetApi(23)
@Nullable
private static NotificationManager.Policy getNotificationPolicy(NotificationManager notificationManager)
{
    if (notificationManager != null)
    {
        try {
            NotificationManager.Policy policy = notificationManager.getNotificationPolicy();    // does getting the policy require a permission? conflicting documentation..
            Log.d(TAG, "getNotificationPolicy: " + policy);
            return policy;

        } catch (SecurityException e) {
            Log.e(TAG, "getNotificationPolicy: Access Denied.. " + e);
            return null;
        }
    } else return null;
}
 
源代码3 项目: linphone-android   文件: ApiTwentyThreePlus.java
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;
}