android.service.notification.NotificationListenerService Java Examples

The following examples show how to use android.service.notification.NotificationListenerService. 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: NLService.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
@Override
public void onNotificationPosted(StatusBarNotification sbn,
                                 NotificationListenerService.RankingMap rankingMap) {

    if (mForwardOnlyPriorityNotifs) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
                mInterruptionFilter == INTERRUPTION_FILTER_PRIORITY) {
            String packageName = sbn.getPackageName();
            String rankingKey = null;
            for (String s : rankingMap.getOrderedKeys()) {
                if (s.contains(packageName)) {
                    rankingKey = s;
                    break;
                }
            }

            Ranking ranking = new Ranking();
            if (rankingKey != null && rankingMap.getRanking(rankingKey, ranking)) {
                if (!ranking.matchesInterruptionFilter()) {
                    return;
                }
            }
        }
    }
    onNotificationPosted(sbn);
}
 
Example #2
Source File: RingerModeLoader.java    From Easer with GNU General Public License v3.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private boolean setDoNotDisturbForLollipop(RingerMode mode) {
    int mode_num;
    if (mode == RingerMode.dnd_all) {
        mode_num = NotificationListenerService.INTERRUPTION_FILTER_ALL;
    } else if (mode == RingerMode.dnd_priority) {
        mode_num = NotificationListenerService.INTERRUPTION_FILTER_PRIORITY;
    } else if (mode == RingerMode.dnd_none) {
        mode_num = NotificationListenerService.INTERRUPTION_FILTER_NONE;
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && mode == RingerMode.dnd_alarms) {
        mode_num = NotificationListenerService.INTERRUPTION_FILTER_ALARMS;
    } else {
        throw new IllegalStateException("DoNotDisturb mode run out of cases???");
    }
    InterruptionFilterSwitcherService.setInterruptionFilter(context, mode_num);
    return true;
}
 
Example #3
Source File: RemoteControlLollipop.java    From Noyze with Apache License 2.0 5 votes vote down vote up
protected RemoteControlLollipop(Context context, Class<? extends NotificationListenerService> clazz) {
    super(context);
    mControllerService = new ComponentName(context, clazz);
    mControllers = new ConcurrentHashMap<>();
    mMediaSessionManager = (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
    mMediaSessionManager.addOnActiveSessionsChangedListener(this, mControllerService);
    mRegistered = true;
}
 
Example #4
Source File: NotificationListenerJellyBeanMR2.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private boolean postActiveNotifications(@NonNull NotificationListenerService service) {
    StatusBarNotification[] an = service.getActiveNotifications();
    if (an == null) return false;
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.init(service, an);
    return mInitialized = true;
}
 
Example #5
Source File: NotificationListenerJellyBeanMR2.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onNotificationRemoved(@NonNull NotificationListenerService service,
                                  @NonNull StatusBarNotification sbn) {
    if (mInitialized || !postActiveNotifications(service)) {
        NotificationPresenter np = NotificationPresenter.getInstance();
        np.removeNotificationFromMain(OpenNotification.newInstance(sbn), 0);
    }
}
 
Example #6
Source File: NotificationListenerJellyBeanMR2.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onNotificationPosted(@NonNull NotificationListenerService service,
                                 @NonNull StatusBarNotification sbn) {
    if (mInitialized || !postActiveNotifications(service)) {
        Context context = service.getApplicationContext();
        NotificationPresenter np = NotificationPresenter.getInstance();
        np.postNotificationFromMain(context, OpenNotification.newInstance(sbn), 0);
    }
}
 
Example #7
Source File: Constants.java    From Noyze with Apache License 2.0 5 votes vote down vote up
public int getZenModeListenerInterruptionFilter(int mZenMode) {
    switch (mZenMode) {
        case ZEN_MODE_OFF:
            return NotificationListenerService.INTERRUPTION_FILTER_ALL;
        case ZEN_MODE_IMPORTANT_INTERRUPTIONS:
            return NotificationListenerService.INTERRUPTION_FILTER_PRIORITY;
        case ZEN_MODE_NO_INTERRUPTIONS:
            return NotificationListenerService.INTERRUPTION_FILTER_NONE;
        default:
            return NotificationListenerService.INTERRUPTION_FILTER_NONE;
    }
}
 
Example #8
Source File: VrManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void grantNotificationListenerAccess(String pkg, int userId) {
    NotificationManager nm = mContext.getSystemService(NotificationManager.class);
    PackageManager pm = mContext.getPackageManager();
    ArraySet<ComponentName> possibleServices = EnabledComponentsObserver.loadComponentNames(pm,
            userId, NotificationListenerService.SERVICE_INTERFACE,
            android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE);

    for (ComponentName c : possibleServices) {
        if (Objects.equals(c.getPackageName(), pkg)) {
            nm.setNotificationListenerAccessGrantedForUser(c, userId, true);
        }
    }
}
 
Example #9
Source File: NotificationListenerLollipop.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onNotificationPosted(@NonNull NotificationListenerService service,
                                 @NonNull StatusBarNotification sbn) {
    Context context = service.getApplicationContext();
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.postNotificationFromMain(context, OpenNotification.newInstance(sbn), 0);
}
 
Example #10
Source File: NotificationListenerLollipop.java    From AcDisplay with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public void onListenerConnected(@NonNull NotificationListenerService service) {
    StatusBarNotification[] an = service.getActiveNotifications();
    if (an == null) return;
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.init(service, an);
}
 
Example #11
Source File: Constants.java    From Noyze with Apache License 2.0 5 votes vote down vote up
private static int zenModeFromListenerInterruptionFilter(int listenerInterruptionFilter) {
    switch (listenerInterruptionFilter) {
        case NotificationListenerService.INTERRUPTION_FILTER_ALL:
            return ZEN_MODE_OFF;
        case NotificationListenerService.INTERRUPTION_FILTER_PRIORITY:
            return ZEN_MODE_IMPORTANT_INTERRUPTIONS;
        case NotificationListenerService.INTERRUPTION_FILTER_NONE:
            return ZEN_MODE_NO_INTERRUPTIONS;
        default:
            return ZEN_MODE_OFF;
    }
}
 
Example #12
Source File: PPNotificationListenerService.java    From PhoneProfilesPlus with Apache License 2.0 5 votes vote down vote up
/** Convenience method for sending an {@link android.content.Intent} with {@link #ACTION_REQUEST_INTERRUPTION_FILTER}. */
@SuppressLint("InlinedApi")
public static void requestInterruptionFilter(final Context context, final int zenMode) {
    boolean a60 = (android.os.Build.VERSION.SDK_INT == 23) && Build.VERSION.RELEASE.equals("6.0");
    if (/*((android.os.Build.VERSION.SDK_INT >= 21) && (android.os.Build.VERSION.SDK_INT < 23)) ||*/ a60) {
        if (isNotificationListenerServiceEnabled(context)) {
            int interruptionFilter = NotificationListenerService.INTERRUPTION_FILTER_ALL;
            switch (zenMode) {
                case ActivateProfileHelper.ZENMODE_ALL:
                    interruptionFilter = NotificationListenerService.INTERRUPTION_FILTER_ALL;
                    break;
                case ActivateProfileHelper.ZENMODE_PRIORITY:
                    interruptionFilter = NotificationListenerService.INTERRUPTION_FILTER_PRIORITY;
                    break;
                case ActivateProfileHelper.ZENMODE_NONE:
                    interruptionFilter = NotificationListenerService.INTERRUPTION_FILTER_NONE;
                    break;
                case ActivateProfileHelper.ZENMODE_ALARMS:
                    interruptionFilter = NotificationListenerService.INTERRUPTION_FILTER_ALARMS;
                    break;
            }
            //Intent request = getInterruptionFilterRequestIntent(interruptionFilter, context);
            Intent request = new Intent(PPNotificationListenerService.ACTION_REQUEST_INTERRUPTION_FILTER);
            request.putExtra(EXTRA_FILTER, interruptionFilter);
            request.setPackage(context.getPackageName());
            context.sendBroadcast(request);
        }
    }
}
 
Example #13
Source File: RemoteControlLollipop.java    From Noyze with Apache License 2.0 5 votes vote down vote up
protected RemoteControlLollipop(Context context, Class<? extends NotificationListenerService> clazz) {
    super(context);
    mControllerService = new ComponentName(context, clazz);
    mControllers = new ConcurrentHashMap<>();
    mMediaSessionManager = (MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
    mMediaSessionManager.addOnActiveSessionsChangedListener(this, mControllerService);
    mRegistered = true;
}
 
Example #14
Source File: Constants.java    From Noyze with Apache License 2.0 5 votes vote down vote up
private static int zenModeFromListenerInterruptionFilter(int listenerInterruptionFilter) {
    switch (listenerInterruptionFilter) {
        case NotificationListenerService.INTERRUPTION_FILTER_ALL:
            return ZEN_MODE_OFF;
        case NotificationListenerService.INTERRUPTION_FILTER_PRIORITY:
            return ZEN_MODE_IMPORTANT_INTERRUPTIONS;
        case NotificationListenerService.INTERRUPTION_FILTER_NONE:
            return ZEN_MODE_NO_INTERRUPTIONS;
        default:
            return ZEN_MODE_OFF;
    }
}
 
Example #15
Source File: Constants.java    From Noyze with Apache License 2.0 5 votes vote down vote up
public int getZenModeListenerInterruptionFilter(int mZenMode) {
    switch (mZenMode) {
        case ZEN_MODE_OFF:
            return NotificationListenerService.INTERRUPTION_FILTER_ALL;
        case ZEN_MODE_IMPORTANT_INTERRUPTIONS:
            return NotificationListenerService.INTERRUPTION_FILTER_PRIORITY;
        case ZEN_MODE_NO_INTERRUPTIONS:
            return NotificationListenerService.INTERRUPTION_FILTER_NONE;
        default:
            return NotificationListenerService.INTERRUPTION_FILTER_NONE;
    }
}
 
Example #16
Source File: NotificationListenerLollipop.java    From HeadsUp with GNU General Public License v2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public void onListenerConnected(@NonNull NotificationListenerService service) {
    StatusBarNotification[] an = service.getActiveNotifications();
    if (an == null) return;
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.init(service, an);
}
 
Example #17
Source File: NotificationListener.java    From android-notification-log with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static NotificationListenerService.RankingMap getRanking() {
	if(instance != null) {
		try {
			return instance.getCurrentRanking();
		} catch (Exception e) {
			if(Const.DEBUG) e.printStackTrace();
		}
	}
	return null;
}
 
Example #18
Source File: NotificationChannel.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * @hide
 */
@SystemApi
public JSONObject toJson() throws JSONException {
    JSONObject record = new JSONObject();
    record.put(ATT_ID, getId());
    record.put(ATT_NAME, getName());
    record.put(ATT_DESC, getDescription());
    if (getImportance() != DEFAULT_IMPORTANCE) {
        record.put(ATT_IMPORTANCE,
                NotificationListenerService.Ranking.importanceToString(getImportance()));
    }
    if (canBypassDnd()) {
        record.put(ATT_PRIORITY, Notification.PRIORITY_MAX);
    }
    if (getLockscreenVisibility() != DEFAULT_VISIBILITY) {
        record.put(ATT_VISIBILITY, Notification.visibilityToString(getLockscreenVisibility()));
    }
    if (getSound() != null) {
        record.put(ATT_SOUND, getSound().toString());
    }
    if (getAudioAttributes() != null) {
        record.put(ATT_USAGE, Integer.toString(getAudioAttributes().getUsage()));
        record.put(ATT_CONTENT_TYPE,
                Integer.toString(getAudioAttributes().getContentType()));
        record.put(ATT_FLAGS, Integer.toString(getAudioAttributes().getFlags()));
    }
    record.put(ATT_LIGHTS, Boolean.toString(shouldShowLights()));
    record.put(ATT_LIGHT_COLOR, Integer.toString(getLightColor()));
    record.put(ATT_VIBRATION_ENABLED, Boolean.toString(shouldVibrate()));
    record.put(ATT_USER_LOCKED, Integer.toString(getUserLockedFields()));
    record.put(ATT_FG_SERVICE_SHOWN, Boolean.toString(isFgServiceShown()));
    record.put(ATT_VIBRATION, longArrayToString(getVibrationPattern()));
    record.put(ATT_SHOW_BADGE, Boolean.toString(canShowBadge()));
    record.put(ATT_DELETED, Boolean.toString(isDeleted()));
    record.put(ATT_GROUP, getGroup());
    record.put(ATT_BLOCKABLE_SYSTEM, isBlockableSystem());
    return record;
}
 
Example #19
Source File: ZenLog.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static String hintsToString(int hints) {
    switch (hints) {
        case 0 : return "none";
        case NotificationListenerService.HINT_HOST_DISABLE_EFFECTS:
                return "disable_effects";
        case NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS:
                return "disable_call_effects";
        case NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS:
                return "disable_notification_effects";
        default: return Integer.toString(hints);
    }
}
 
Example #20
Source File: NotificationListenerLollipop.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNotificationRemoved(@NonNull NotificationListenerService service,
                                  @NonNull StatusBarNotification sbn) {
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.removeNotificationFromMain(OpenNotification.newInstance(sbn), 0);
}
 
Example #21
Source File: RemoteControlCompat.java    From Noyze with Apache License 2.0 4 votes vote down vote up
public static RemoteControlCompat get(Context context, Class<? extends NotificationListenerService> clazz) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        return new RemoteControlLollipop(context, clazz);
    return new RemoteControlKitKat(context);
}
 
Example #22
Source File: Utils.java    From Noyze with Apache License 2.0 4 votes vote down vote up
/** @return True if a given {@link android.service.notification.NotificationListenerService} is enabled. */
public static <T extends NotificationListenerService> boolean isNotificationListenerServiceRunning(Context context, String className) {
    return isSettingsServiceEnabled(context, Constants.getEnabledNotificationListeners(), getServiceComponentNames(context, className));
}
 
Example #23
Source File: Utils.java    From Noyze with Apache License 2.0 4 votes vote down vote up
/** @return True if a given {@link android.service.notification.NotificationListenerService} is enabled. */
public static <T extends NotificationListenerService> boolean isNotificationListenerServiceRunning(Context context, Class<T> clazz) {
    return isSettingsServiceEnabled(context, Constants.getEnabledNotificationListeners(), getServiceComponentNames(clazz));
}
 
Example #24
Source File: NotificationListenerLollipop.java    From HeadsUp with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNotificationPosted(@NonNull NotificationListenerService service,
                                 @NonNull StatusBarNotification sbn) {
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.postNotificationFromMain(service, OpenNotification.newInstance(sbn), 0);
}
 
Example #25
Source File: NotificationListenerLollipop.java    From HeadsUp with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNotificationRemoved(@NonNull NotificationListenerService service,
                                  @NonNull StatusBarNotification sbn) {
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.removeNotificationFromMain(OpenNotification.newInstance(sbn));
}
 
Example #26
Source File: NotificationListenerJellyBeanMR2.java    From HeadsUp with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onListenerConnected(@NonNull NotificationListenerService service) { /* unused */ }
 
Example #27
Source File: NotificationListenerJellyBeanMR2.java    From HeadsUp with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNotificationPosted(@NonNull NotificationListenerService service,
                                 @NonNull StatusBarNotification sbn) {
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.postNotificationFromMain(service, OpenNotification.newInstance(sbn), 0);
}
 
Example #28
Source File: NotificationListenerJellyBeanMR2.java    From HeadsUp with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onNotificationRemoved(@NonNull NotificationListenerService service,
                                  @NonNull StatusBarNotification sbn) {
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.removeNotificationFromMain(OpenNotification.newInstance(sbn));
}
 
Example #29
Source File: NotificationListenerJellyBeanMR2.java    From AcDisplay with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onListenerConnected(@NonNull NotificationListenerService service) { /* unused */ }
 
Example #30
Source File: PolicyManagementFragment.java    From android-testdpc with Apache License 2.0 4 votes vote down vote up
@Override
protected List<ResolveInfo> doInBackground(Void... voids) {
    return mPackageManager.queryIntentServices(
            new Intent(NotificationListenerService.SERVICE_INTERFACE),
            PackageManager.GET_META_DATA | PackageManager.MATCH_UNINSTALLED_PACKAGES);
}