private NotificationManager getNotificationManager() { return (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } }
private void removeNotification() { NotificationManager notificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(NOTIFICATION_ID); }
private void notifyNothingPlaying() { NotificationManager notificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, mNothingPlayingNotification); } }
@NonNull private static String createChannel(Service context) { // Create a channel. NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); CharSequence channelName = "Playback channel"; int importance = NotificationManager.IMPORTANCE_DEFAULT; NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, channelName, importance); notificationManager.createNotificationChannel(notificationChannel); return CHANNEL_ID; } }
public void onCreate() { windowManager = (WindowManager) service.getSystemService(Context.WINDOW_SERVICE); if (PreferenceData.STATUS_ENABLED.getValue(service)) setUp(false); }
@TargetApi(Build.VERSION_CODES.O) private void buildNotificationChannel() { NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL, mService.getString(R.string.app_name), NotificationManager.IMPORTANCE_LOW); channel.enableLights(false); channel.enableVibration(false); channel.setShowBadge(false); NotificationManager notificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.createNotificationChannel(channel); }
private void showNotification(Bitmap bitmap) { collapsedRV.setImageViewBitmap(R.id.icon, bitmap); if (Utils.isJellybeanOrLater()) { notification.bigContentView = expandedRV; expandedRV.setImageViewBitmap(expandedIconResId, bitmap); } NotificationManager notificationManager = (NotificationManager) mService.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notification); picassoTarget = null; } };
@Override protected Map<String,String> authenticateWeb(URI uri, String realm, String authUrl, String completeUrl, String verificationUrl) { final NotificationManager notificationManager = (NotificationManager)myService.getSystemService(Context.NOTIFICATION_SERVICE); final Intent intent = new Intent(myService, WebAuthorisationScreen.class); intent.setData(Uri.parse(authUrl)); intent.putExtra(WebAuthorisationScreen.COMPLETE_URL_KEY, completeUrl); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_FROM_BACKGROUND); final PendingIntent pendingIntent = PendingIntent.getActivity(myService, 0, intent, 0); final String text = ZLResource.resource("dialog") .getResource("backgroundAuthentication") .getResource("message") .getValue(); final Notification notification = new NotificationCompat.Builder(myService) .setSmallIcon(R.drawable.fbreader) .setTicker(text) .setContentTitle(realm) .setContentText(text) .setContentIntent(pendingIntent) .setAutoCancel(true) .build(); notificationManager.notify(0, notification); return errorMap("Notification sent"); } }
public static void update(final Service service, Station station, MediaSessionCompat session) { // session can be null on update - happens when currently playing station was renamed if (session != null) { // update mSession mSession = session; } // build notification mNotification = getNotificationBuilder(service, station).build(); // display updated notification NotificationManager notificationManager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(PLAYER_SERVICE_NOTIFICATION_ID, mNotification); if (station.getPlaybackState() == PLAYBACK_STATE_STOPPED) { // make notification swipe-able service.stopForeground(false); } }