本文整理汇总了Java中android.service.notification.NotificationListenerService类的典型用法代码示例。如果您正苦于以下问题:Java NotificationListenerService类的具体用法?Java NotificationListenerService怎么用?Java NotificationListenerService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NotificationListenerService类属于android.service.notification包,在下文中一共展示了NotificationListenerService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: activateZenMode
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void activateZenMode() {
ZenModeChange doNotDistrubChange = Preferences.getEnum(service.getGlobalSettings(), GlobalSettings.TIMED_MUTE_ZEN_CHANGE);
if (doNotDistrubChange != ZenModeChange.NO_CHANGE) {
int newZenMode;
switch (doNotDistrubChange) {
case ALARMS:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
newZenMode = NotificationListenerService.INTERRUPTION_FILTER_ALARMS;
} else {
newZenMode = NotificationListenerService.INTERRUPTION_FILTER_PRIORITY;
}
break;
case PRIORITY:
newZenMode = NotificationListenerService.INTERRUPTION_FILTER_PRIORITY;
break;
default:
newZenMode = NotificationListenerService.INTERRUPTION_FILTER_NONE;
}
previousZenMode = service.getCurrentInterruptionFilter();
service.requestInterruptionFilterSafe(newZenMode);
}
}
示例2: onNotificationPosted
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
@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);
}
示例3: startCountDownActivity
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
private void startCountDownActivity(int timer, long startTimeCurrentTime) {
NotificationListenerService listenerService = new NotificationListenerService() {
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
super.onNotificationRemoved(sbn);
}
};
WearableTimer wearableTimer = appData.getTimer(timer);
Intent intent = new Intent(Constants.START_ACTIVITY, Uri.parse(timer + ""), getApplicationContext(), CountDownActivity.class)
.putExtra(Constants.TIMER_N, timer)
.putExtra(Constants.TIMER_NAME, wearableTimer.getName())
.putExtra(Constants.TIMER_DURATION, wearableTimer.getDuration())
.putExtra(Constants.TIMER_COLOR, wearableTimer.getColor().color)
.putExtra(Constants.TIMER_CURRENT_TIME, startTimeCurrentTime)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
示例4: onInterruptionFilterChanged
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
@Override
public void onInterruptionFilterChanged(final int interruptionFilter) {
boolean inPriority =
interruptionFilter != NotificationListenerService.INTERRUPTION_FILTER_ALL;
SharedPreferences prefs = getSharedPreferences("audio_setting", Context.MODE_PRIVATE);
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
if (BuildConfig.DEBUG) Logger.log("onInterruptionFilterChanged " + interruptionFilter);
if (inPriority) {
int currentVolume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
if (BuildConfig.DEBUG) Logger.log(
"NotificationListener - in priority mode, current volume: " + currentVolume);
if (currentVolume > 0) {
prefs.edit().putInt("media_volume", currentVolume).apply();
if (BuildConfig.DEBUG)
Logger.log("NotificationListener - changing STREAM_MUSIC volume to 0");
am.setStreamVolume(AudioManager.STREAM_MUSIC, 0,
AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
}
} else {
if (BuildConfig.DEBUG) Logger.log(
"NotificationListener - changing STREAM_MUSIC volume to : " +
prefs.getInt("media_volume", 128));
am.setStreamVolume(AudioManager.STREAM_MUSIC, prefs.getInt("media_volume", 128), 0);
}
}
示例5: setSensitive
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
public boolean setSensitive(String pkg, int uid, boolean sensitive) {
try {
sINM.setPackageVisibilityOverride(pkg, uid,
sensitive ? Notification.VISIBILITY_PRIVATE
: NotificationListenerService.Ranking.VISIBILITY_NO_OVERRIDE);
return true;
} catch (Exception e) {
Log.w(TAG, "Error calling NoMan", e);
return false;
}
}
示例6: getNotificationListenerConfig
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
private static Config getNotificationListenerConfig() {
final Config c = new Config();
c.tag = TAG;
c.setting = Settings.Secure.ENABLED_NOTIFICATION_LISTENERS;
c.intentAction = NotificationListenerService.SERVICE_INTERFACE;
c.permission = android.Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE;
c.noun = "notification listener";
c.warningDialogTitle = R.string.notification_listener_security_warning_title;
c.warningDialogSummary = R.string.notification_listener_security_warning_summary;
c.emptyText = R.string.no_notification_listeners;
return c;
}
示例7: onReceive
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
return;
if (intent.getAction().equals(ACTION_SET_STATE)) {
int state = intent.getIntExtra(EXTRA_STATE, 1);
//INTERRUPTION_FILTER_ALL
if (state != NotificationListenerService.INTERRUPTION_FILTER_ALL)
state = NotificationListenerService.INTERRUPTION_FILTER_PRIORITY;
if (state == getCurrentInterruptionFilter())
return;
Log.d(TAG, "Set state: " + state);
//Also force the audio mode for some devices
//AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
//audioManager.setRingerMode(state == INTERRUPTION_FILTER_ALL ? AudioManager.RINGER_MODE_NORMAL : AudioManager.RINGER_MODE_SILENT);
//requestInterruptionFilter(state);
}
if (intent.getAction().equals(ACTION_CONNECTED)) {
if (mStateTime == 0)
mStateTime = System.currentTimeMillis();
int interruptionFilter = getCurrentInterruptionFilter();
SettingsService.sendState(mGoogleApiClient, interruptionFilter, mStateTime);
mStateTime = System.currentTimeMillis();
}
}
示例8: isNotificationFilteredByDoNotInterrupt
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
public boolean isNotificationFilteredByDoNotInterrupt(StatusBarNotification statusBarNotification) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return true;
}
NotificationListenerService.RankingMap rankingMap = service.getCurrentRanking();
if (rankingMap == null) {
return false;
}
NotificationListenerService.Ranking ranking = new NotificationListenerService.Ranking();
return rankingMap.getRanking(statusBarNotification.getKey(), ranking) && !ranking.matchesInterruptionFilter();
}
示例9: NotificationHandler
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
public NotificationHandler(NotificationListenerService notificationListener) {
// Instantiate SQLite3 DB accessor
mDB = new DB(notificationListener);
// Save for later
mNotificationListener = notificationListener;
}
示例10: removeNotification
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private void removeNotification(String pkg, String tag, int id) {
NotificationListenerService service = QcpNotificationListenerService.getInstance();
if(service != null) {
service.cancelNotification(pkg, tag, id);
}
if(mRemoveIntent != null) {
try {
mRemoveIntent.send();
} catch (CanceledException e) {
Log.e(TAG, "CanceledException while sending remove intent");
}
}
}
示例11: getZenModeListenerInterruptionFilter
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
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;
}
}
示例12: zenModeFromListenerInterruptionFilter
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
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;
}
}
示例13: RemoteControlLollipop
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
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;
}
示例14: requestInterruptionFilter
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
/** 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;
}
//Log.e(TAG, "requestInterruptionFilter(" + interruptionFilter + ')');
Intent request = getInterruptionFilterRequestIntent(interruptionFilter, context);
context.sendBroadcast(request);
}
}
}
示例15: onListenerConnected
import android.service.notification.NotificationListenerService; //导入依赖的package包/类
@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);
}