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:com.android.screenspeak.ScreenSpeakUpdateHelper.java

private Notification buildGestureChangeNotification(Intent clickIntent) {
    final PendingIntent pendingIntent = PendingIntent.getActivity(mService, 0, clickIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    final String ticker = mService.getString(R.string.notification_title_screenspeak_gestures_changed);
    final String contentTitle = mService.getString(R.string.notification_title_screenspeak_gestures_changed);
    final String contentText = mService.getString(R.string.notification_message_screenspeak_gestures_changed);
    final Notification notification = new NotificationCompat.Builder(mService)
            .setSmallIcon(R.drawable.ic_stat_info).setTicker(ticker).setContentTitle(contentTitle)
            .setContentText(contentText).setContentIntent(pendingIntent).setAutoCancel(false).setWhen(0)
            .build();//w w w .  ja  v  a2  s  . com

    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    return notification;
}

From source file:com.keithandthegirl.services.download.DownloadService.java

@SuppressWarnings("deprecation")
private void sendNotification(String description) {

    mContentTitle = description;/*from   w w  w . ja v  a2  s  .c o  m*/

    long when = System.currentTimeMillis();
    notificationId = (int) when;

    mNotification = new Notification(android.R.drawable.stat_sys_download,
            getResources().getString(R.string.app_name), when);

    Intent notificationIntent = new Intent();
    mContentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    mNotification.setLatestEventInfo(this, getResources().getString(R.string.app_name), mContentTitle,
            mContentIntent);

    mNotification.flags = Notification.FLAG_ONGOING_EVENT;

    mNotificationManager.notify(notificationId, mNotification);

}

From source file:com.webkey.Ipc.java

public void notiyShow(Context pContext, String message) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(pContext);
    if (!prefs.getBoolean("statusbar", true)) {
        notiyDestroy(pContext);//from   w w  w  .j  a  va  2s  . c o  m
        return;
    }
    Notification notification;

    //      Log.d("Webkey","START_notify");      
    if (manager == null)
        manager = (NotificationManager) pContext.getSystemService(Context.NOTIFICATION_SERVICE);

    notification = new Notification();
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    notification.icon = R.drawable.icon;
    //notification.tickerText = "Service is running";      
    notification.when = System.currentTimeMillis();
    //Intent notificationIntent = new Intent();
    //PendingIntent contentIntent = PendingIntent.getActivity(pContext, 0, notificationIntent, 0);
    //notification.setLatestEventInfo(pContext, "Webkey", "NotificationContent", contentIntent);
    Intent notifyIntent = new Intent(pContext, Webkey.class);
    notification.setLatestEventInfo(pContext, "Webkey", message,
            PendingIntent.getActivity(pContext, 0, notifyIntent, 0));
    manager.notify(1, notification);
}

From source file:net.micode.soundrecorder.RecorderService.java

private void showLowStorageNotification(int minutes) {
    if (mKeyguardManager.inKeyguardRestrictedInputMode()) {
        // it's not necessary to show this notification in lock-screen
        return;/*w ww . jav a 2  s .  com*/
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.stat_sys_call_record_full).setContentTitle(getString(R.string.app_name))
            .setWhen(System.currentTimeMillis()).setContentText(getString(R.string.notification_warning));
    Intent notificationIntent = new Intent(this, SoundRecorder.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(contentIntent);
    Notification noti = mBuilder.build();
    noti.flags = Notification.FLAG_ONGOING_EVENT;
    NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(notifyID, noti);
}

From source file:com.gdpi.app.UpdateManager.java

/**
 * ??//from  w  w w  . jav a2 s  . co  m
 */
@SuppressWarnings({ "deprecation", "unused" })
private void showNotify() {
    mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = R.drawable.icon;
    CharSequence tickerText = "";
    long when = System.currentTimeMillis();
    nitify = new Notification(icon, tickerText, when);

    // "?"?
    nitify.flags = Notification.FLAG_ONGOING_EVENT;
    RemoteViews contentView = new RemoteViews(mContext.getPackageName(), R.layout.view_custom_progress);
    contentView.setTextViewText(R.id.tv_custom_progress_title, name);
    // 
    nitify.contentView = contentView;
    Intent intent = new Intent(mContext, MainFragment.class);
    PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0);
    // ?
    nitify.contentIntent = contentIntent;
    mNotificationManager.notify(notifyId, nitify);
}

From source file:com.bluelinelabs.logansquare.typeconverters.NotificationConverter.java

@TargetApi(Build.VERSION_CODES.KITKAT)
@NonNull//from  www .j a v a2 s . c o  m
public static SimpleNotification toSimpleNotification(@NonNull Notification notification) {
    SimpleNotification simpleNotification = new SimpleNotification();

    simpleNotification.autoCancel = (notification.flags
            & Notification.FLAG_AUTO_CANCEL) == Notification.FLAG_AUTO_CANCEL;
    android.util.Log.d("json2notification", "autoCancel:" + simpleNotification.autoCancel);

    //simpleNotification.bigPictureStyle // TODO

    simpleNotification.category = notification.category;
    simpleNotification.color = notification.color > 0 ? notification.color : null;
    simpleNotification.contentInfo = notification.extras.getString(Notification.EXTRA_INFO_TEXT);
    simpleNotification.contentIntent = notification.contentIntent;
    simpleNotification.contentTitle = notification.extras.getString(Notification.EXTRA_TITLE);
    simpleNotification.contentText = notification.extras.getString(Notification.EXTRA_TEXT);
    simpleNotification.defaults = notification.defaults > 0 ? notification.defaults : null;
    simpleNotification.deleteIntent = notification.deleteIntent;
    //simpleNotification.extras;
    simpleNotification.groupKey = notification.getGroup();
    if (simpleNotification.groupKey != null) {
        simpleNotification.groupSummary = (notification.flags
                & Notification.FLAG_GROUP_SUMMARY) == Notification.FLAG_GROUP_SUMMARY;
    }
    Bitmap bitmap = notification.extras.getParcelable(Notification.EXTRA_LARGE_ICON);
    if (bitmap != null)
        simpleNotification.largeIcon = Bitmaps.base64(bitmap);
    if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) == Notification.FLAG_SHOW_LIGHTS) {
        simpleNotification.lights = Arrays.asList(notification.ledARGB, notification.ledOnMS,
                notification.ledOffMS);
    }
    simpleNotification.localOnly = (notification.flags
            & Notification.FLAG_LOCAL_ONLY) == Notification.FLAG_LOCAL_ONLY;
    simpleNotification.number = notification.number > 0 ? notification.number : null;
    simpleNotification.ongoing = (notification.flags
            & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT;
    simpleNotification.onlyAlertOnce = (notification.flags
            & Notification.FLAG_ONLY_ALERT_ONCE) == Notification.FLAG_ONLY_ALERT_ONCE;
    String[] people = notification.extras.getStringArray(Notification.EXTRA_PEOPLE);
    if (people != null) {
        simpleNotification.people = Arrays.asList(people);
    }
    simpleNotification.priority = notification.priority > 0 ? notification.priority : null;
    //simpleNotification.progress;
    simpleNotification.publicVersion = notification.publicVersion;
    simpleNotification.showWhen = notification.extras.getBoolean(Notification.EXTRA_SHOW_WHEN);
    if (simpleNotification.showWhen) {
        simpleNotification.when = notification.when;
    }
    simpleNotification.smallIcon = String.valueOf(notification.extras.getInt(Notification.EXTRA_SMALL_ICON)); // TODO getResourceNameById()
    android.util.Log.d("json2notification", "simpleNotification.smallIcon" + simpleNotification.smallIcon);
    simpleNotification.sortKey = notification.getSortKey();
    simpleNotification.sound = notification.sound;
    simpleNotification.subText = notification.extras.getString(Notification.EXTRA_SUB_TEXT);
    simpleNotification.tickerText = notification.tickerText;
    simpleNotification.usesChronometer = notification.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER);
    simpleNotification.visibility = notification.visibility > 0 ? notification.visibility : null;
    return simpleNotification;
}

From source file:com.ubergeek42.WeechatAndroid.service.RelayService.java

private void showNotification(String tickerText, String content) {
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, WeechatActivity.class),
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(getString(R.string.app_version)).setContentText(content).setTicker(tickerText)
            .setWhen(System.currentTimeMillis());

    Notification notification = builder.getNotification();
    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
    notificationManger.notify(NOTIFICATION_ID, notification);
}

From source file:com.mobiperf.MeasurementScheduler.java

/**
 * Create notification that indicates the service is running.
 *//*w w w .ja  va  2 s .  c o  m*/
private Notification createServiceRunningNotification() {
    // The intent to launch when the user clicks the expanded notification
    Intent intent = new Intent(this, SpeedometerApp.class);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    // This constructor is deprecated in 3.x. But most phones still run 2.x systems
    Notification notice = new Notification(R.drawable.icon_statusbar,
            getString(R.string.notificationSchedulerStarted), System.currentTimeMillis());
    notice.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    // This is deprecated in 3.x. But most phones still run 2.x systems
    notice.setLatestEventInfo(this, getString(R.string.app_name),
            getString(R.string.notificationServiceRunning), pendIntent);
    return notice;
}

From source file:com.inloc.dr.StepService.java

/**
 * Show a notification while this service is running.
 *//*from   w ww  .ja  va 2s . c  o m*/
private void showNotification() {
    CharSequence text = getText(R.string.app_name);
    Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    Intent pedometerIntent = new Intent();
    pedometerIntent.setComponent(new ComponentName(this, DeadReckoning.class));
    pedometerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, pedometerIntent, 0);
    notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent);

    mNM.notify(R.string.app_name, notification);
}