Java Code Examples for android.app.NotificationManager#INTERRUPTION_FILTER_ALL

The following examples show how to use android.app.NotificationManager#INTERRUPTION_FILTER_ALL . 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: InterruptionFilterChangedBroadcastReceiver.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
public static void requestInterruptionFilter(Context context, final int zenMode) {
    //if (android.os.Build.VERSION.SDK_INT >= 23) {
        boolean no60 = !Build.VERSION.RELEASE.equals("6.0");
        if (no60 && GlobalGUIRoutines.activityActionExists(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS, context)) {
            int interruptionFilter = NotificationManager.INTERRUPTION_FILTER_ALL;
            switch (zenMode) {
                case ActivateProfileHelper.ZENMODE_ALL:
                    interruptionFilter = NotificationManager.INTERRUPTION_FILTER_ALL;
                    break;
                case ActivateProfileHelper.ZENMODE_PRIORITY:
                    interruptionFilter = NotificationManager.INTERRUPTION_FILTER_PRIORITY;
                    break;
                case ActivateProfileHelper.ZENMODE_NONE:
                    interruptionFilter = NotificationManager.INTERRUPTION_FILTER_NONE;
                    break;
                case ActivateProfileHelper.ZENMODE_ALARMS:
                    interruptionFilter = NotificationManager.INTERRUPTION_FILTER_ALARMS;
                    break;
            }
            NotificationManager mNotificationManager = (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
            if (mNotificationManager != null)
                mNotificationManager.setInterruptionFilter(interruptionFilter);
        }
    //}
}
 
Example 2
Source File: InterruptionFilterChangedBroadcastReceiver.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
private static int getZenMode(Context context, AudioManager audioManager) {
    // convert to profile zenMode
    int zenMode = 0;
    NotificationManager mNotificationManager = (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
    if (mNotificationManager != null) {
        int interruptionFilter = mNotificationManager.getCurrentInterruptionFilter();
        //PPApplication.logE("InterruptionFilterChangedBroadcastReceiver.getZenMode", "interruptionFilter=" + interruptionFilter);
        int ringerMode = audioManager.getRingerMode();
        switch (interruptionFilter) {
            case NotificationManager.INTERRUPTION_FILTER_ALL:
                //if (ActivateProfileHelper.vibrationIsOn(/*context, */audioManager, true))
                if (ringerMode == AudioManager.RINGER_MODE_VIBRATE)
                    zenMode = 4;
                else
                    zenMode = 1;
                break;
            case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
                //if (ActivateProfileHelper.vibrationIsOn(/*context, */audioManager, true))
                if (ringerMode == AudioManager.RINGER_MODE_VIBRATE)
                    zenMode = 5;
                else
                    zenMode = 2;
                break;
            case NotificationManager.INTERRUPTION_FILTER_NONE:
                zenMode = 3;
                break;
            case NotificationManager.INTERRUPTION_FILTER_ALARMS:
                zenMode = 6;
                break;
            case NotificationManager.INTERRUPTION_FILTER_UNKNOWN:
                zenMode = 1;
                break;
        }
        //PPApplication.logE("InterruptionFilterChangedBroadcastReceiver.getZenMode", "zenMode=" + zenMode);
    }
    return zenMode;
}
 
Example 3
Source File: AlarmNotifications.java    From SuntimesWidget with GNU General Public License v3.0 4 votes vote down vote up
private static boolean passesInterruptionFilter(Context context, @NonNull AlarmClockItem item)
{
    if (Build.VERSION.SDK_INT >= 23)
    {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        int filter = (notificationManager != null) ? notificationManager.getCurrentInterruptionFilter()
                                                   : NotificationManager.INTERRUPTION_FILTER_UNKNOWN;
        switch (filter)
        {
            case NotificationManager.INTERRUPTION_FILTER_ALARMS:        // (4) alarms only
                return (item.type == AlarmClockItem.AlarmType.ALARM);

            case NotificationManager.INTERRUPTION_FILTER_NONE:          // (3) suppress all
                return false;

            case NotificationManager.INTERRUPTION_FILTER_PRIORITY:      // (2) allow priority
                if (Build.VERSION.SDK_INT >= 28) {
                    return (item.type == AlarmClockItem.AlarmType.ALARM) &&
                            (isCategorySet(getNotificationPolicy(notificationManager), PRIORITY_CATEGORY_ALARMS));
                } else {
                    return (item.type == AlarmClockItem.AlarmType.ALARM);
                }

            case NotificationManager.INTERRUPTION_FILTER_ALL:           // (1) allow all
            case NotificationManager.INTERRUPTION_FILTER_UNKNOWN:       // (0) unknown
            default:
                return true;
        }

    } else if (Build.VERSION.SDK_INT >= 21) {
        try {
            int zenMode = Settings.Global.getInt(context.getContentResolver(), "zen_mode");
            switch (zenMode)
            {
                case 2: // Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
                    return false;

                case 3: // Settings.Global.ZEN_MODE_ALARMS:
                case 1: // Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
                    return (item.type == AlarmClockItem.AlarmType.ALARM);

                case 0: // Settings.Global.ZEN_MODE_OFF:
                default:
                    return true;
            }

        } catch (Settings.SettingNotFoundException e) {
            Log.e(TAG, "interruptionFilter: Setting Not Found: zen_mode .. " + e);
            return true;
        }

    } else return true;
}
 
Example 4
Source File: InterruptionFilterChangedBroadcastReceiver.java    From PhoneProfilesPlus with Apache License 2.0 4 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    //CallsCounter.logCounter(context, "InterruptionFilterChangedBroadcastReceiver.onReceive", "InterruptionFilterChangedBroadcastReceiver_onReceive");

    //if (android.os.Build.VERSION.SDK_INT >= 23) {
        boolean no60 = !Build.VERSION.RELEASE.equals("6.0");
        if (no60 && GlobalGUIRoutines.activityActionExists(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS, context)) {
            if (!RingerModeChangeReceiver.internalChange) {

                NotificationManager mNotificationManager = (NotificationManager) context.getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
                if (mNotificationManager != null) {
                    int interruptionFilter = mNotificationManager.getCurrentInterruptionFilter();
                    final AudioManager audioManager = (AudioManager) context.getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
                    int ringerMode = AudioManager.RINGER_MODE_NORMAL;
                    if (audioManager != null)
                        ringerMode = audioManager.getRingerMode();

                    // convert to profile zenMode
                    int zenMode = 0;
                    switch (interruptionFilter) {
                        case NotificationManager.INTERRUPTION_FILTER_ALL:
                            //if (ActivateProfileHelper.vibrationIsOn(/*context.getApplicationContext(), */audioManager, true))
                            if (ringerMode == AudioManager.RINGER_MODE_VIBRATE)
                                zenMode = 4;
                            else
                                zenMode = 1;
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
                            //if (ActivateProfileHelper.vibrationIsOn(/*context.getApplicationContext(), */audioManager, true))
                            if (ringerMode == AudioManager.RINGER_MODE_VIBRATE)
                                zenMode = 5;
                            else
                                zenMode = 2;
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_NONE:
                            zenMode = 3;
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_ALARMS:
                            zenMode = 6;
                            break;
                        case NotificationManager.INTERRUPTION_FILTER_UNKNOWN:
                            zenMode = 1;
                            break;
                    }
                    //PPApplication.logE(TAG, "onReceive(zenMode=" + zenMode + ')');
                    if (zenMode != 0) {
                        RingerModeChangeReceiver.notUnlinkVolumes = true;
                        ActivateProfileHelper.saveRingerMode(context.getApplicationContext(), 5);
                        ActivateProfileHelper.saveZenMode(context.getApplicationContext(), zenMode);
                    }
                }
            }

            //RingerModeChangeReceiver.setAlarmForDisableInternalChange(getApplicationContext());
        }
    //}
}