Search in sources :

Example 61 with NotificationManager

use of android.app.NotificationManager in project Gadgetbridge by Freeyourgadget.

the class DebugActivity method testNotification.

private void testNotification() {
    Intent notificationIntent = new Intent(getApplicationContext(), DebugActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
    NotificationManager nManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_REPLY).build();
    Intent replyIntent = new Intent(ACTION_REPLY);
    PendingIntent replyPendingIntent = PendingIntent.getBroadcast(this, 0, replyIntent, 0);
    NotificationCompat.Action action = new NotificationCompat.Action.Builder(android.R.drawable.ic_input_add, "Reply", replyPendingIntent).addRemoteInput(remoteInput).build();
    NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender().addAction(action);
    NotificationCompat.Builder ncomp = new NotificationCompat.Builder(this).setContentTitle(getString(R.string.test_notification)).setContentText(getString(R.string.this_is_a_test_notification_from_gadgetbridge)).setTicker(getString(R.string.this_is_a_test_notification_from_gadgetbridge)).setSmallIcon(R.drawable.ic_notification).setAutoCancel(true).setContentIntent(pendingIntent).extend(wearableExtender);
    nManager.notify((int) System.currentTimeMillis(), ncomp.build());
}
Also used : RemoteInput(android.support.v4.app.RemoteInput) NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 62 with NotificationManager

use of android.app.NotificationManager in project AndroidChromium by JackyAndroid.

the class DownloadSnackbarController method onAction.

@Override
public void onAction(Object actionData) {
    if (!(actionData instanceof ActionDataInfo)) {
        DownloadManagerService.openDownloadsPage(mContext);
        return;
    }
    final ActionDataInfo download = (ActionDataInfo) actionData;
    if (download.downloadInfo.isOfflinePage()) {
        OfflinePageDownloadBridge.openDownloadedPage(download.downloadInfo.getDownloadGuid());
        return;
    }
    DownloadManagerService manager = DownloadManagerService.getDownloadManagerService(mContext);
    manager.openDownloadedContent(download.downloadInfo, download.systemDownloadId);
    if (download.notificationId != INVALID_NOTIFICATION_ID) {
        NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(DownloadNotificationService.NOTIFICATION_NAMESPACE, download.notificationId);
    }
}
Also used : NotificationManager(android.app.NotificationManager)

Example 63 with NotificationManager

use of android.app.NotificationManager in project AntennaPod by AntennaPod.

the class DownloadService method postAuthenticationNotification.

private void postAuthenticationNotification(final DownloadRequest downloadRequest) {
    handler.post(() -> {
        final String resourceTitle = (downloadRequest.getTitle() != null) ? downloadRequest.getTitle() : downloadRequest.getSource();
        NotificationCompat.Builder builder = new NotificationCompat.Builder(DownloadService.this);
        builder.setTicker(getText(R.string.authentication_notification_title)).setContentTitle(getText(R.string.authentication_notification_title)).setContentText(getText(R.string.authentication_notification_msg)).setStyle(new NotificationCompat.BigTextStyle().bigText(getText(R.string.authentication_notification_msg) + ": " + resourceTitle)).setSmallIcon(R.drawable.ic_stat_authentication).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_authentication)).setAutoCancel(true).setContentIntent(ClientConfig.downloadServiceCallbacks.getAuthentificationNotificationContentIntent(DownloadService.this, downloadRequest)).setVisibility(Notification.VISIBILITY_PUBLIC);
        Notification n = builder.build();
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.notify(downloadRequest.getSource().hashCode(), n);
    });
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Notification(android.app.Notification)

Example 64 with NotificationManager

use of android.app.NotificationManager in project AntennaPod by AntennaPod.

the class DownloadService method updateReport.

/**
     * Creates a notification at the end of the service lifecycle to notify the
     * user about the number of completed downloads. A report will only be
     * created if there is at least one failed download excluding images
     */
private void updateReport() {
    // check if report should be created
    boolean createReport = false;
    int successfulDownloads = 0;
    int failedDownloads = 0;
    // (excluding failed image downloads)
    for (DownloadStatus status : reportQueue) {
        if (status.isSuccessful()) {
            successfulDownloads++;
        } else if (!status.isCancelled()) {
            if (status.getFeedfileType() != FeedImage.FEEDFILETYPE_FEEDIMAGE) {
                createReport = true;
            }
            failedDownloads++;
        }
    }
    if (createReport) {
        Log.d(TAG, "Creating report");
        // create notification object
        Notification notification = new NotificationCompat.Builder(this).setTicker(getString(R.string.download_report_title)).setContentTitle(getString(R.string.download_report_content_title)).setContentText(String.format(getString(R.string.download_report_content), successfulDownloads, failedDownloads)).setSmallIcon(R.drawable.stat_notify_sync_error).setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.stat_notify_sync_error)).setContentIntent(ClientConfig.downloadServiceCallbacks.getReportNotificationContentIntent(this)).setAutoCancel(true).setVisibility(Notification.VISIBILITY_PUBLIC).build();
        NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nm.notify(REPORT_ID, notification);
    } else {
        Log.d(TAG, "No report is created");
    }
    reportQueue.clear();
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) SuppressLint(android.annotation.SuppressLint) Notification(android.app.Notification)

Example 65 with NotificationManager

use of android.app.NotificationManager in project AntennaPod by AntennaPod.

the class PlaybackService method setupNotification.

/**
     * Prepares notification and starts the service in the foreground.
     */
private void setupNotification(final PlaybackServiceMediaPlayer.PSMPInfo info) {
    final PendingIntent pIntent = PendingIntent.getActivity(this, 0, PlaybackService.getPlayerActivityIntent(this), PendingIntent.FLAG_UPDATE_CURRENT);
    if (notificationSetupThread != null) {
        notificationSetupThread.interrupt();
    }
    Runnable notificationSetupTask = new Runnable() {

        Bitmap icon = null;

        @Override
        public void run() {
            Log.d(TAG, "Starting background work");
            if (android.os.Build.VERSION.SDK_INT >= 11) {
                if (info.playable != null) {
                    int iconSize = getResources().getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
                    try {
                        icon = Glide.with(PlaybackService.this).load(info.playable.getImageLocation()).asBitmap().diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).centerCrop().into(iconSize, iconSize).get();
                    } catch (Throwable tr) {
                        Log.e(TAG, "Error loading the media icon for the notification", tr);
                    }
                }
            }
            if (icon == null) {
                icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext()));
            }
            if (mediaPlayer == null) {
                return;
            }
            PlayerStatus playerStatus = mediaPlayer.getPlayerStatus();
            final int smallIcon = ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext());
            if (!Thread.currentThread().isInterrupted() && started && info.playable != null) {
                String contentText = info.playable.getEpisodeTitle();
                String contentTitle = info.playable.getFeedTitle();
                Notification notification;
                // Builder is v7, even if some not overwritten methods return its parent's v4 interface
                NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(PlaybackService.this).setContentTitle(contentTitle).setContentText(contentText).setOngoing(false).setContentIntent(pIntent).setLargeIcon(icon).setSmallIcon(smallIcon).setWhen(// we don't need the time
                0).setPriority(// set notification priority
                UserPreferences.getNotifyPriority());
                IntList compactActionList = new IntList();
                // we start and 0 and then increment by 1 for each call to addAction
                int numActions = 0;
                if (isCasting) {
                    Intent stopCastingIntent = new Intent(PlaybackService.this, PlaybackService.class);
                    stopCastingIntent.putExtra(EXTRA_CAST_DISCONNECT, true);
                    PendingIntent stopCastingPendingIntent = PendingIntent.getService(PlaybackService.this, numActions, stopCastingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                    notificationBuilder.addAction(R.drawable.ic_media_cast_disconnect, getString(R.string.cast_disconnect_label), stopCastingPendingIntent);
                    numActions++;
                }
                // always let them rewind
                PendingIntent rewindButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_REWIND, numActions);
                notificationBuilder.addAction(android.R.drawable.ic_media_rew, getString(R.string.rewind_label), rewindButtonPendingIntent);
                if (UserPreferences.showRewindOnCompactNotification()) {
                    compactActionList.add(numActions);
                }
                numActions++;
                if (playerStatus == PlayerStatus.PLAYING) {
                    PendingIntent pauseButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_PAUSE, numActions);
                    //pause action
                    notificationBuilder.addAction(//pause action
                    android.R.drawable.ic_media_pause, getString(R.string.pause_label), pauseButtonPendingIntent);
                    compactActionList.add(numActions++);
                } else {
                    PendingIntent playButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_PLAY, numActions);
                    //play action
                    notificationBuilder.addAction(//play action
                    android.R.drawable.ic_media_play, getString(R.string.play_label), playButtonPendingIntent);
                    compactActionList.add(numActions++);
                }
                // ff follows play, then we have skip (if it's present)
                PendingIntent ffButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD, numActions);
                notificationBuilder.addAction(android.R.drawable.ic_media_ff, getString(R.string.fast_forward_label), ffButtonPendingIntent);
                if (UserPreferences.showFastForwardOnCompactNotification()) {
                    compactActionList.add(numActions);
                }
                numActions++;
                if (UserPreferences.isFollowQueue()) {
                    PendingIntent skipButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_NEXT, numActions);
                    notificationBuilder.addAction(android.R.drawable.ic_media_next, getString(R.string.skip_episode_label), skipButtonPendingIntent);
                    if (UserPreferences.showSkipOnCompactNotification()) {
                        compactActionList.add(numActions);
                    }
                    numActions++;
                }
                PendingIntent stopButtonPendingIntent = getPendingIntentForMediaAction(KeyEvent.KEYCODE_MEDIA_STOP, numActions);
                notificationBuilder.setStyle(new android.support.v7.app.NotificationCompat.MediaStyle().setMediaSession(mediaSession.getSessionToken()).setShowActionsInCompactView(compactActionList.toArray()).setShowCancelButton(true).setCancelButtonIntent(stopButtonPendingIntent)).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setColor(NotificationCompat.COLOR_DEFAULT);
                notification = notificationBuilder.build();
                if (playerStatus == PlayerStatus.PLAYING || playerStatus == PlayerStatus.PREPARING || playerStatus == PlayerStatus.SEEKING || isCasting) {
                    startForeground(NOTIFICATION_ID, notification);
                } else {
                    stopForeground(false);
                    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                    mNotificationManager.notify(NOTIFICATION_ID, notification);
                }
                Log.d(TAG, "Notification set up");
            }
        }
    };
    notificationSetupThread = new Thread(notificationSetupTask);
    notificationSetupThread.start();
}
Also used : NotificationManager(android.app.NotificationManager) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Notification(android.app.Notification) IntList(de.danoeh.antennapod.core.util.IntList) Bitmap(android.graphics.Bitmap) NotificationCompat(android.support.v7.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Aggregations

NotificationManager (android.app.NotificationManager)930 Intent (android.content.Intent)400 PendingIntent (android.app.PendingIntent)397 Notification (android.app.Notification)276 NotificationCompat (android.support.v4.app.NotificationCompat)267 NotificationChannel (android.app.NotificationChannel)129 Uri (android.net.Uri)62 Context (android.content.Context)59 SharedPreferences (android.content.SharedPreferences)41 Bitmap (android.graphics.Bitmap)41 Resources (android.content.res.Resources)39 Bundle (android.os.Bundle)36 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)35 SuppressLint (android.annotation.SuppressLint)27 TargetApi (android.annotation.TargetApi)26 TaskStackBuilder (android.app.TaskStackBuilder)25 StatusBarNotification (android.service.notification.StatusBarNotification)24 IOException (java.io.IOException)22 File (java.io.File)20 IntentFilter (android.content.IntentFilter)18