Example usage for android.app Notification Notification

List of usage examples for android.app Notification Notification

Introduction

In this page you can find the example usage for android.app Notification Notification.

Prototype

@Deprecated
public Notification(int icon, CharSequence tickerText, long when) 

Source Link

Document

Constructs a Notification object with the information needed to have a status bar icon without the standard expanded view.

Usage

From source file:de.incoherent.suseconferenceclient.app.AlarmReceiver.java

@SuppressWarnings({ "deprecation" })
@Override/*from  www. j  a  v a  2  s .c  o m*/
public void onReceive(Context context, Intent intent) {
    Intent notificationIntent = new Intent(context, HomeActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    String title = intent.getStringExtra("title");
    String room = intent.getStringExtra("room");
    String time = intent.getStringExtra("timetext");
    String message = time + ", " + room;

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = context.getResources().getColor(R.color.dark_suse_green);
    notification.ledOffMS = 1000;
    notification.ledOnMS = 300;
    notification.setLatestEventInfo(context, title, message, contentIntent);
    manager.notify(13572, notification);
}

From source file:org.ametro.util.WebUtil.java

public static void downloadFileAsync(final Context appContext, final File path, final URI uri,
        final File temp) {

    final DownloadContext context = new DownloadContext();
    context.Path = path;/* ww  w. j a  v a 2 s  .c  om*/
    context.IsCanceled = false;
    context.IsUnpackFinished = false;
    context.IsFailed = false;

    final NotificationManager notificationManager = (NotificationManager) appContext
            .getSystemService(Context.NOTIFICATION_SERVICE);

    final Handler handler = new Handler();

    final Runnable updateProgress = new Runnable() {
        public void run() {
            if (context.Notification == null) {
                context.Notification = new Notification(android.R.drawable.stat_sys_download,
                        "Downloading icons", System.currentTimeMillis());
                context.Notification.flags = Notification.FLAG_NO_CLEAR;
                Intent notificationIntent = new Intent();
                context.ContentIntent = PendingIntent.getActivity(appContext, 0, notificationIntent, 0);
            }
            if (context.IsFailed) {
                notificationManager.cancelAll();
                context.Notification = new Notification(android.R.drawable.stat_sys_warning,
                        "Icons download failed", System.currentTimeMillis());
                context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons downloaded failed",
                        context.ContentIntent);
                notificationManager.notify(2, context.Notification);

            } else if (context.IsUnpackFinished) {
                notificationManager.cancelAll();
                context.Notification = new Notification(android.R.drawable.stat_sys_download_done,
                        "Icons unpacked", System.currentTimeMillis());
                context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons downloaded and unpacked.",
                        context.ContentIntent);
                notificationManager.notify(3, context.Notification);

            } else if (context.Position == 0 && context.Total == 0) {
                context.Notification.setLatestEventInfo(appContext, "aMetro",
                        "Download icons: connecting server", context.ContentIntent);
                notificationManager.notify(1, context.Notification);
            } else if (context.Position < context.Total) {
                context.Notification.setLatestEventInfo(appContext, "aMetro",
                        "Download icons: " + context.Position + "/" + context.Total, context.ContentIntent);
                notificationManager.notify(1, context.Notification);
            } else {
                context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons unpacking",
                        context.ContentIntent);
                notificationManager.notify(1, context.Notification);
            }
        }
    };

    final Thread async = new Thread() {
        public void run() {
            WebUtil.downloadFile(context, uri, temp, false, new IDownloadListener() {

                public void onBegin(Object context, File file) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.Total = 0;
                    downloadContext.Position = 0;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

                public boolean onUpdate(Object context, long position, long total) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.Total = total;
                    downloadContext.Position = position;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                    return !downloadContext.IsCanceled;
                }

                public void onDone(Object context, File file) throws Exception {
                    DownloadContext downloadContext = (DownloadContext) context;
                    File path = downloadContext.Path;
                    ZipUtil.unzip(file, path);
                    downloadContext.IsUnpackFinished = true;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

                public void onCanceled(Object context, File file) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.IsCanceled = true;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

                public void onFailed(Object context, File file, Throwable reason) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.IsFailed = true;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

            });
        };
    };
    async.start();
}

From source file:org.telegram.kleegram.autoanswer.AutoAnswerNotifier.java

private void enableNotification() {
    // Intent to call to turn off AutoAnswer
    Intent notificationIntent = new Intent(mContext, AutoAnswerPreferenceActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);

    // Create the notification
    Notification notification = new Notification(R.drawable.stat_sys_autoanswer, null, 0);
    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    notification = builder.setContentIntent(pendingIntent).setSmallIcon(R.drawable.stat_sys_autoanswer)
            .setAutoCancel(true).setContentTitle(mContext.getString(R.string.notification_title))
            .setContentText(mContext.getString(R.string.notification_text)).build();
    mNotificationManager.notify(NOTIFICATION_ID, notification);

}

From source file:com.networkmanagerapp.SettingBackgroundUploader.java

/**
 * Create a notification to inform the user of progress in the system notification area
 *///from  w  w w  .ja  va2s.c  o  m
private void showNotification() {
    CharSequence text = getText(R.string.upload_service_started);
    Notification notification = new Notification(R.drawable.ic_stat_networkman, text,
            System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, NetworkManagerMainActivity.class), 0);
    notification.setLatestEventInfo(this, text, text, contentIntent);
    mNM.notify(R.string.upload_service_started, notification);
}

From source file:com.networkmanagerapp.JSONBackgroundDownloaderService.java

/**
 * Displays a notification in the system notification area
 *///from  www.  ja va  2  s .co  m
private void showNotification() {
    CharSequence text = getText(R.string.download_service_started);
    Notification notification = new Notification(R.drawable.ic_stat_networkman, text,
            System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, NetworkManagerMainActivity.class), 0);
    notification.setLatestEventInfo(this, text, text, contentIntent);
    mNM.notify(R.string.download_service_started, notification);
}

From source file:justforcommunity.radiocom.utils.StreamingService.java

private void showNotification(String paramString1, String paramString2) {
    String str = paramString2;/*from ww  w .  java 2s .co  m*/
    Notification localNotification = new Notification(R.drawable.logo_nav_header, str,
            System.currentTimeMillis());

    Intent localIntent = new Intent(getApplicationContext(), Home.class);
    localIntent.putExtra("servicio", true);
    localIntent.putExtra("text", this.text);
    localIntent.putExtra("title", this.title);
    localIntent.putExtra("notificationSkip", true);
    localIntent.putExtra("stopService", true);

    PendingIntent localPendingIntent = PendingIntent.getActivity(this, 1, localIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    localNotification.flags = 32;

    //stop intent
    Intent stopIntent = new Intent(getApplicationContext(), Home.class);
    stopIntent.putExtra("stopService", false);
    PendingIntent stopIntentPending = PendingIntent.getActivity(this, 2, stopIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    //stop intent
    Intent pauseIntent = new Intent(getApplicationContext(), Home.class);
    pauseIntent.putExtra("stopService", true);
    PendingIntent pauseIntentPending = PendingIntent.getActivity(this, 3, pauseIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Bitmap myIcon;
    if (logo != null) {
        myIcon = BitmapFactory.decodeByteArray(logo, 0, logo.length);
    } else {
        myIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    }

    int smallIconId = 0;
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        smallIconId = R.drawable.notification_transparent;
    } else {
        smallIconId = R.drawable.notification;
    }

    NotificationCompat.Builder noti = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(smallIconId).setLargeIcon(myIcon)
            .setColor(getResources().getColor(R.color.colorPrimary)).setContentIntent(localPendingIntent)
            .setContentTitle(this.title).setContentText(this.text)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(this.text)).setAutoCancel(false)
            .addAction(R.drawable.stoppodcast, getResources().getString(R.string.drawer_item_streaming_stop),
                    pauseIntentPending)
            .addAction(R.drawable.exitpodcast, getResources().getString(R.string.drawer_item_streaming_close),
                    stopIntentPending);

    this.mNM.notify(this.NOTIFICATION, noti.build());

}

From source file:de.wikilab.android.friendica01.FileUploadService.java

private void showFailMsg(Context ctx, String txt) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    Log.e("Andfrnd/UploadFile", "Upload FAILED: " + txt);

    //Instantiate the Notification:
    CharSequence tickerText = "Upload failed, please retry!";
    Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    //Define the Notification's expanded message and Intent:
    Context context = getApplicationContext();
    CharSequence contentTitle = "Upload failed, click to retry!";
    CharSequence contentText = txt;
    Intent notificationIntent = new Intent(this, FriendicaImgUploadActivity.class);
    Bundle b = new Bundle();
    b.putParcelable(Intent.EXTRA_STREAM, fileToUpload);
    b.putString(Intent.EXTRA_SUBJECT, subject);
    b.putString(EXTRA_DESCTEXT, descText);

    notificationIntent.putExtras(b);//from w  ww  .j av  a  2s  .c o  m
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    //Pass the Notification to the NotificationManager:
    mNotificationManager.notify(UPLOAD_FAILED_ID, notification);
    //Toast.makeText(ctx, "Upload failed, please retry:\n" + txt, Toast.LENGTH_LONG).show();
}

From source file:justforcommunity.radiocom.utils.PodcastingService.java

private void showNotification(String paramString1, String paramString2) {
    String str = paramString2;/*from   w ww  .  ja  va  2  s.  c o m*/
    Notification localNotification = new Notification(R.drawable.logo_nav_header, str,
            System.currentTimeMillis());

    Intent localIntent = new Intent(getApplicationContext(), Podcast.class);
    localIntent.putExtra("servicio", true);
    localIntent.putExtra("text", this.text);
    localIntent.putExtra("title", this.title);
    localIntent.putExtra("notificationSkip", true);
    localIntent.putExtra("stopService", true);

    PendingIntent localPendingIntent = PendingIntent.getActivity(this, 1, localIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    localNotification.flags = 32;

    //stop intent
    Intent pauseIntent = new Intent(getApplicationContext(), Podcast.class);
    pauseIntent.putExtra("stopService", true);
    PendingIntent pauseIntentPending = PendingIntent.getActivity(this, 3, pauseIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    Bitmap myIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    int smallIconId = 0;
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        smallIconId = R.drawable.notification_transparent;
    } else {
        smallIconId = R.drawable.notification;
    }

    NotificationCompat.Builder noti = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(smallIconId).setLargeIcon(myIcon).setContentIntent(localPendingIntent)
            .setContentTitle(this.title).setContentText(this.text)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(this.text)).setAutoCancel(false)
            .addAction(R.drawable.stoppodcast, getResources().getString(R.string.drawer_item_podcasting_stop),
                    pauseIntentPending);

    this.mNM.notify(this.NOTIFICATION, noti.build());

}

From source file:org.openplans.rcavl.LocationService.java

public void realStart(Intent intent) {
    String url = intent.getStringExtra("pingUrl");
    String email = intent.getStringExtra("email");
    String password = intent.getStringExtra("password");
    pingInterval = intent.getIntExtra("pingInterval", 60);

    Notification notification = new Notification(R.drawable.icon, "Ridepilot Mobile",
            System.currentTimeMillis());
    Intent appIntent = new Intent(this, RCAVL.class);

    appIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pi = PendingIntent.getActivity(this, 0, appIntent, 0);

    notification.setLatestEventInfo(this, "Ridepilot Mobile", "connected", pi);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(66786, notification);

    thread = new LocationServiceThread(url, email, password);
    new Thread(thread).start();
}

From source file:saphion.fragment.alarm.alert.AlarmAlertReceiver.java

@SuppressWarnings("deprecation")
@Override//from www. ja  v  a 2 s  .co m
public void onReceive(final Context context, final Intent intent) {
    String action = intent.getAction();
    int pos = intent.getIntExtra(PreferenceHelper.BAT_VALS, 0);
    level = intent.getIntExtra(PreferenceHelper.CURR_RING, 72);

    //Log.Toast(context, level + " in receiver", Toast.LENGTH_LONG);
    // int id = intent.getIntExtra(Intents.EXTRA_ID, -1);

    if (action.equals(Intents.ALARM_ALERT_ACTION)) {
        /* Close dialogs and window shade */
        Intent closeDialogs = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        context.sendBroadcast(closeDialogs);

        // Decide which activity to start based on the state of the
        // keyguard.
        /*
         * KeyguardManager km = (KeyguardManager)
         * context.getSystemService(Context.KEYGUARD_SERVICE); if
         * (km.inKeyguardRestrictedInputMode()) { // Use the full screen
         * activity for security. c = AlarmAlertFullScreen.class; }
         */

        // Trigger a notification that, when clicked, will show the alarm
        // alert
        // dialog. No need to check for fullscreen since this will always be
        // launched from a user action.

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            Intent notify = new Intent(context, saphion.fragments.alarm.AlarmAlert.class);
            notify.putExtra(PreferenceHelper.BAT_VALS, pos);
            PendingIntent pendingNotify = PendingIntent.getActivity(context, ID, notify, 0);

            // Alarm alarm = AlarmsManager.getAlarmsManager().getAlarm(id);
            Notification n = new Notification(R.drawable.stat_notify_alarm, "abc", System.currentTimeMillis());
            n.setLatestEventInfo(context, "Battery Alarm", "Battery Level is " + level, pendingNotify);
            n.flags |= Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONGOING_EVENT;
            n.defaults |= Notification.DEFAULT_LIGHTS;

            // NEW: Embed the full-screen UI here. The notification manager
            // will // take care of displaying it if it's OK to do so.
            Intent alarmAlert = new Intent(context, saphion.fragments.alarm.AlarmAlert.class);
            alarmAlert.putExtra(PreferenceHelper.CURR_RING, level);
            alarmAlert.putExtra(PreferenceHelper.BAT_VALS, pos);
            alarmAlert.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_USER_ACTION);
            n.fullScreenIntent = PendingIntent.getActivity(context, ID, alarmAlert, 0);

            // Send the notification using the alarm id to easily identify
            // the // correct notification.
            NotificationManager nm = (NotificationManager) context
                    .getSystemService(Context.NOTIFICATION_SERVICE);
            // Log.Toast(context, "Recieved", Toast.LENGTH_LONG);
            // mNotificationManager.notify(ID, builder.build());
            nm.notify(ID, n);
        } else {
            // Log.Toast(context, "Recieved", Toast.LENGTH_LONG);
            newMethod(context, pos);
        }

    } else if (action.equals(Intents.ALARM_DISMISS_ACTION)) {
        NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        nm.cancel(ID);
    }
}