Example usage for android.app Notification FLAG_ONGOING_EVENT

List of usage examples for android.app Notification FLAG_ONGOING_EVENT

Introduction

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

Prototype

int FLAG_ONGOING_EVENT

To view the source code for android.app Notification FLAG_ONGOING_EVENT.

Click Source Link

Document

Bit to be bitwise-ored into the #flags field that should be set if this notification is in reference to something that is ongoing, like a phone call.

Usage

From source file:edu.mit.viral.shen.DroidFish.java

/** Set/clear the "heavy CPU usage" notification. */
private final void setNotification(boolean show) {
    if (notificationActive == show)
        return;/*from w w w  . j  a  va 2s .  co  m*/
    notificationActive = show;
    final int cpuUsage = 1;
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    if (show) {
        int icon = R.drawable.icon;
        CharSequence tickerText = getString(R.string.heavy_cpu_usage);
        long when = System.currentTimeMillis();
        Notification notification = new Notification(icon, tickerText, when);
        notification.flags |= Notification.FLAG_ONGOING_EVENT;

        Context context = getApplicationContext();
        CharSequence contentTitle = getString(R.string.background_processing);
        CharSequence contentText = getString(R.string.lot_cpu_power);
        Intent notificationIntent = new Intent(this, CPUWarning.class);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

        mNotificationManager.notify(cpuUsage, notification);
    } else {
        mNotificationManager.cancel(cpuUsage);
    }
}