Search in sources :

Example 66 with NotificationManager

use of android.app.NotificationManager in project acra by ACRA.

the class ReportExecutor method createNotification.

/**
     * Creates a status bar notification.
     *
     * The action triggered when the notification is selected is to start the
     * {@link CrashReportDialog} Activity.
     *
     * @param reportFile    Report file to send.
     */
private void createNotification(@NonNull File reportFile, @NonNull ReportBuilder reportBuilder) {
    final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    // Default notification icon is the warning symbol
    final int icon = config.resNotifIcon();
    final CharSequence tickerText = context.getText(config.resNotifTickerText());
    final long when = System.currentTimeMillis();
    if (ACRA.DEV_LOGGING)
        ACRA.log.d(LOG_TAG, "Creating Notification for " + reportFile);
    final Intent crashReportDialogIntent = createCrashReportDialogIntent(reportFile, reportBuilder);
    final PendingIntent contentIntent = PendingIntent.getActivity(context, mNotificationCounter++, crashReportDialogIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    final CharSequence contentTitle = context.getText(config.resNotifTitle());
    final CharSequence contentText = context.getText(config.resNotifText());
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    final Notification notification = builder.setSmallIcon(icon).setTicker(tickerText).setWhen(when).setAutoCancel(true).setContentTitle(contentTitle).setContentText(contentText).setContentIntent(contentIntent).build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    // The deleteIntent is invoked when the user swipes away the Notification.
    // In this case we invoke the CrashReportDialog with EXTRA_FORCE_CANCEL==true
    // which will cause BaseCrashReportDialog to clear the crash report and finish itself.
    final Intent deleteIntent = createCrashReportDialogIntent(reportFile, reportBuilder);
    deleteIntent.putExtra(ACRAConstants.EXTRA_FORCE_CANCEL, true);
    notification.deleteIntent = PendingIntent.getActivity(context, -1, deleteIntent, 0);
    // Send new notification
    notificationManager.notify(ACRAConstants.NOTIF_CRASH_ID, notification);
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 67 with NotificationManager

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

the class GpodnetSyncService method updateErrorNotification.

private void updateErrorNotification(GpodnetServiceException exception) {
    Log.d(TAG, "Posting error notification");
    GpodnetPreferences.setLastSyncAttempt(false, System.currentTimeMillis());
    final String title;
    final String description;
    final int id;
    if (exception instanceof GpodnetServiceAuthenticationException) {
        title = getString(R.string.gpodnetsync_auth_error_title);
        description = getString(R.string.gpodnetsync_auth_error_descr);
        id = R.id.notification_gpodnet_sync_autherror;
    } else {
        if (UserPreferences.gpodnetNotificationsEnabled()) {
            title = getString(R.string.gpodnetsync_error_title);
            description = getString(R.string.gpodnetsync_error_descr) + exception.getMessage();
            id = R.id.notification_gpodnet_sync_error;
        } else {
            return;
        }
    }
    PendingIntent activityIntent = ClientConfig.gpodnetCallbacks.getGpodnetSyncServiceErrorNotificationPendingIntent(this);
    Notification notification = new NotificationCompat.Builder(this).setContentTitle(title).setContentText(description).setContentIntent(activityIntent).setSmallIcon(R.drawable.stat_notify_sync_error).setAutoCancel(true).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).build();
    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(id, notification);
}
Also used : GpodnetServiceAuthenticationException(de.danoeh.antennapod.core.gpoddernet.GpodnetServiceAuthenticationException) NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 68 with NotificationManager

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

the class GpodnetSyncService method clearErrorNotifications.

private void clearErrorNotifications() {
    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.cancel(R.id.notification_gpodnet_sync_error);
    nm.cancel(R.id.notification_gpodnet_sync_autherror);
}
Also used : NotificationManager(android.app.NotificationManager)

Example 69 with NotificationManager

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

the class FlattrClickWorker method postFlattrFailedNotification.

private void postFlattrFailedNotification() {
    int failed = countFailed.get();
    if (failed == 0) {
        return;
    }
    PendingIntent contentIntent = ClientConfig.flattrCallbacks.getFlattrFailedNotificationContentIntent(context);
    String title;
    String subtext;
    if (failed == 1) {
        title = context.getString(R.string.flattrd_failed_label);
        String exceptionMsg = (exception.getMessage() != null) ? exception.getMessage() : "";
        subtext = context.getString(R.string.flattr_click_failure, extraFlattrThing.getTitle()) + "\n" + exceptionMsg;
    } else {
        title = context.getString(R.string.flattrd_label);
        subtext = context.getString(R.string.flattr_click_success_count, countSuccess.get()) + "\n" + context.getString(R.string.flattr_click_failure_count, failed);
    }
    Notification notification = new NotificationCompat.Builder(context).setStyle(new NotificationCompat.BigTextStyle().bigText(subtext)).setContentIntent(contentIntent).setContentTitle(title).setTicker(title).setSmallIcon(R.drawable.stat_notify_sync_error).setOngoing(false).setAutoCancel(true).build();
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, notification);
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 70 with NotificationManager

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

the class FlattrClickWorker method postNoTokenNotification.

private void postNoTokenNotification() {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, ClientConfig.flattrCallbacks.getFlattrAuthenticationActivityIntent(context), 0);
    Notification notification = new NotificationCompat.Builder(context).setStyle(new NotificationCompat.BigTextStyle().bigText(context.getString(R.string.no_flattr_token_notification_msg))).setContentIntent(contentIntent).setContentTitle(context.getString(R.string.no_flattr_token_title)).setTicker(context.getString(R.string.no_flattr_token_title)).setSmallIcon(R.drawable.stat_notify_sync_error).setOngoing(false).setAutoCancel(true).build();
    ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, notification);
}
Also used : NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

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