Search in sources :

Example 6 with NotificationManagerCompat

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();
}
Also used : NotificationManagerCompat(androidx.core.app.NotificationManagerCompat)

Example 7 with NotificationManagerCompat

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);
}
Also used : NotificationManagerCompat(androidx.core.app.NotificationManagerCompat)

Example 8 with NotificationManagerCompat

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);
}
Also used : NotificationManager(android.app.NotificationManager) Bundle(android.os.Bundle) TaskStackBuilder(android.app.TaskStackBuilder) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) NotificationChannel(android.app.NotificationChannel) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent) TaskStackBuilder(android.app.TaskStackBuilder) RequiresApi(androidx.annotation.RequiresApi)

Example 9 with NotificationManagerCompat

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());
}
Also used : LivePlayerActivity(com.zype.android.ui.chromecast.LivePlayerActivity) MediaStyle(androidx.media.app.NotificationCompat.MediaStyle) Bundle(android.os.Bundle) NotificationManagerCompat(androidx.core.app.NotificationManagerCompat) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) VideoData(com.zype.android.webapi.model.video.VideoData) VideoDetailActivity(com.zype.android.ui.video_details.VideoDetailActivity) NotificationCompat(androidx.core.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 10 with NotificationManagerCompat

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");
    }
}
Also used : NotificationManagerCompat(androidx.core.app.NotificationManagerCompat)

Aggregations

NotificationManagerCompat (androidx.core.app.NotificationManagerCompat)26 PendingIntent (android.app.PendingIntent)6 Notification (android.app.Notification)5 Intent (android.content.Intent)5 NotificationCompat (androidx.core.app.NotificationCompat)5 NotificationChannel (android.app.NotificationChannel)2 NotificationManager (android.app.NotificationManager)2 Bundle (android.os.Bundle)2 NotificationChannelCompat (androidx.core.app.NotificationChannelCompat)2 TaskStackBuilder (android.app.TaskStackBuilder)1 Bitmap (android.graphics.Bitmap)1 RequiresApi (androidx.annotation.RequiresApi)1 NotificationChannelGroupCompat (androidx.core.app.NotificationChannelGroupCompat)1 WearableExtender (androidx.core.app.NotificationCompat.WearableExtender)1 RemoteInput (androidx.core.app.RemoteInput)1 TaskStackBuilder (androidx.core.app.TaskStackBuilder)1 MediaStyle (androidx.media.app.NotificationCompat.MediaStyle)1 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)1 MobiComConversationService (com.applozic.mobicomkit.api.conversation.MobiComConversationService)1 ApplozicException (com.applozic.mobicomkit.exception.ApplozicException)1