use of androidx.core.app.NotificationManagerCompat in project RSAndroidApp by RailwayStations.
the class NearbyNotificationService method onDestroy.
@Override
public void onDestroy() {
Log.i(TAG, "Service gets destroyed");
try {
cancelNotification();
unregisterLocationManager();
} catch (final Throwable t) {
Log.wtf(TAG, "Unknown problem when trying to de-register from GPS updates", t);
}
// Cancel the ongoing notification
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.cancel(ONGOING_NOTIFICATION_ID);
super.onDestroy();
}
use of androidx.core.app.NotificationManagerCompat in project RSAndroidApp by RailwayStations.
the class NearbyBahnhofNotificationManager method onNotificationReady.
/**
* Called back once the notification was built up ready.
*/
protected void onNotificationReady(final Notification notification) {
if (context == null) {
// we're already destroyed
return;
}
// Get an instance of the NotificationManager service
final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
// Build the notification and issues it with notification manager.
notificationManager.notify(NOTIFICATION_ID, notification);
}
use of androidx.core.app.NotificationManagerCompat in project zype-android by zype.
the class PlayerService method createNotificationChannel.
@RequiresApi(Build.VERSION_CODES.O)
private void createNotificationChannel(String channelId, String channelName, String videoTitle, String videoId, MediaSessionCompat.Token mediaSessionToken, Boolean isPlay) {
Intent resultIntent = new Intent(this, VideoDetailActivity.class);
Bundle bundle = new Bundle();
bundle.putString(BundleConstants.VIDEO_ID, videoId);
resultIntent.putExtras(bundle);
resultIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
// Create the TaskStackBuilder and add the intent, which inflates the back stack
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntentWithParentStack(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationChannel chan = new NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT);
chan.enableVibration(false);
chan.setSound(null, null);
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
assert manager != null;
manager.createNotificationChannel(chan);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId);
notificationBuilder.setContentIntent(resultPendingIntent).setContentTitle(this.getString(R.string.app_name)).setContentText(videoTitle).setSmallIcon(R.drawable.ic_background_playback).setPriority(NotificationCompat.PRIORITY_MAX).setCategory(Notification.CATEGORY_SERVICE).setAutoCancel(true).setOngoing(true).setWhen(0);
if (isPlay) {
notificationBuilder.addAction(new NotificationCompat.Action(R.drawable.ic_pause_black_24dp, "Pause", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)));
} else {
notificationBuilder.addAction(new NotificationCompat.Action(R.drawable.ic_play_arrow_black_24dp, "Play", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE)));
}
notificationBuilder.setStyle(new androidx.media.app.NotificationCompat.MediaStyle().setMediaSession(mediaSessionToken).setShowCancelButton(true).setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_STOP)));
Notification notification = notificationBuilder.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(ZypeApp.NOTIFICATION_ID, notificationBuilder.build());
startForeground(ZypeApp.NOTIFICATION_ID, notification);
}
use of androidx.core.app.NotificationManagerCompat in project zype-android by zype.
the class PlayerFragment method showNotification.
public void showNotification(boolean isLive, int mediaType) {
Logger.d("showNotification()");
if (player == null || TextUtils.isEmpty(fileId)) {
return;
}
VideoData video = VideoHelper.getVideo(getActivity().getContentResolver(), fileId);
String title = "";
if (video != null) {
title = video.getTitle();
} else {
title = "Live";
}
Intent notificationIntent;
Bundle bundle = new Bundle();
bundle.putInt(BundleConstants.MEDIA_TYPE, mediaType);
bundle.putString(BundleConstants.VIDEO_ID, fileId);
if (isLive) {
notificationIntent = new Intent(getActivity(), LivePlayerActivity.class);
title = "Live";
} else {
notificationIntent = new Intent(getActivity(), VideoDetailActivity.class);
}
notificationIntent.putExtras(bundle);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
PendingIntent intent = PendingIntent.getActivity(getActivity(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity(), ZypeApp.NOTIFICATION_CHANNEL_ID);
builder.setContentIntent(intent).setContentTitle(getActivity().getString(R.string.app_name)).setContentText(title).setSmallIcon(R.drawable.ic_background_playback).setPriority(NotificationCompat.PRIORITY_MAX).setAutoCancel(true).setOngoing(true).setWhen(0);
// builder.addAction(R.drawable.ic_stop_black_24px, "Stop", pendingIntentStop);
if (player != null) {
if (player.getPlayerControl().isPlaying()) {
builder.addAction(new NotificationCompat.Action(R.drawable.ic_pause_black_24dp, "Pause", MediaButtonReceiver.buildMediaButtonPendingIntent(getActivity(), PlaybackStateCompat.ACTION_PLAY_PAUSE)));
} else {
builder.addAction(new NotificationCompat.Action(R.drawable.ic_play_arrow_black_24dp, "Play", MediaButtonReceiver.buildMediaButtonPendingIntent(getActivity(), PlaybackStateCompat.ACTION_PLAY_PAUSE)));
}
}
builder.setStyle(new MediaStyle().setMediaSession(mediaSession.getSessionToken()).setShowCancelButton(true).setCancelButtonIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(getActivity(), PlaybackStateCompat.ACTION_STOP)));
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity());
notificationManager.notify(ZypeApp.NOTIFICATION_ID, builder.build());
}
use of androidx.core.app.NotificationManagerCompat in project zype-android by zype.
the class PlayerFragment method hideNotification.
public void hideNotification() {
Logger.d("hideNotification()");
if (getActivity() != null) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity());
notificationManager.cancel(ZypeApp.NOTIFICATION_ID);
} else {
Logger.d("hideNotification(): Activity is not exist");
}
}
Aggregations