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.talkback.TalkBackUpdateHelper.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_talkback_gestures_changed);
    final String contentTitle = mService.getString(R.string.notification_title_talkback_gestures_changed);
    final String contentText = mService.getString(R.string.notification_message_talkback_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();//from  ww w. j  av a2  s . c om

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

From source file:cl.iluminadoschile.pako.floatingdiv.CustomOverlayService.java

@Override
protected Notification foregroundNotification(int notificationId) {
    Notification notification;/*from  ww w.j  a v  a2s.co  m*/

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            && activation_method.equals(Constants.SETTINGS.ACTIVATION_METHOD_MANUAL)) {
        Intent settingsIntent = new Intent(Intent.ACTION_MAIN);
        settingsIntent.setClassName(Constants.ACTION.prefix, Constants.ACTION.prefix + ".SettingsActivity");
        settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, settingsIntent, 0);

        Intent startFgIntent = new Intent(this, CustomOverlayService.class);
        startFgIntent.setAction(Constants.ACTION.STARTFOREGROUND_ACTION);
        PendingIntent pstartFgIntent = PendingIntent.getService(this, 0, startFgIntent, 0);

        Intent pauseFgIntent = new Intent(this, CustomOverlayService.class);
        pauseFgIntent.setAction(Constants.ACTION.PAUSEFOREGROUND_ACTION);
        PendingIntent ppauseFgIntent = PendingIntent.getService(this, 0, pauseFgIntent, 0);

        Intent stopFgIntent = new Intent(this, CustomOverlayService.class);
        stopFgIntent.setAction(Constants.ACTION.STOPFOREGROUND_ACTION);
        PendingIntent pstopFgIntent = PendingIntent.getService(this, 0, stopFgIntent, 0);

        Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

        notification = new NotificationCompat.Builder(this)
                .setContentTitle(getString(R.string.title_notification))
                .setTicker(getString(R.string.title_notification))
                .setContentText(getString(R.string.message_notification)).setSmallIcon(R.drawable.ic_launcher)
                .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setContentIntent(pendingIntent)
                .setOngoing(true).addAction(android.R.drawable.ic_media_play, "Start", pstartFgIntent)
                .addAction(android.R.drawable.ic_media_pause, "Pause", ppauseFgIntent)
                .addAction(android.R.drawable.ic_delete, "Stop", pstopFgIntent).build();

    } else {
        notification = new Notification(R.drawable.ic_launcher, getString(R.string.title_notification),
                System.currentTimeMillis());

        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT
                | Notification.FLAG_ONLY_ALERT_ONCE;

        notification.setLatestEventInfo(this, getString(R.string.title_notification),
                getString(R.string.message_notification_manual), notificationIntent());
    }
    return notification;
}

From source file:fi.hut.soberit.sensors.services.BatchDataUploadService.java

private void showBatchUploadNotification(String text, int progress, boolean noClear) {
    if (notification == null) {
        notification = new Notification(R.drawable.ic_icon_export, text, System.currentTimeMillis());

        // final Intent appIntent = new Intent(this, SIDE.class);
        final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, null, 0);

        notification.setLatestEventInfo(this, getString(R.string.app_name), text, contentIntent);

        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.batch_upload_notification_layout);
        contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_icon_export);
        notification.contentView = contentView;
    }/*  w  w w .java2s  .  co  m*/

    notification.contentView.setTextViewText(R.id.status_text, text);
    notification.contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS, progress, false);

    if (noClear) {
        notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    } else {
        notificationManager.cancel(R.id.batch_upload);

        notification.flags ^= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    }
    notificationManager.notify(R.id.batch_upload, notification);
}

From source file:org.sipdroid.sipua.ui.Receiver.java

public static void onText(int type, String text, int mInCallResId, long base) {
    if (mSipdroidEngine != null && type == REGISTER_NOTIFICATION + mSipdroidEngine.pref) {
        cache_text = text;/*from   ww w. j  a v  a  2  s  .  co m*/
        cache_res = mInCallResId;
    }
    if (type >= REGISTER_NOTIFICATION && mInCallResId == R.drawable.sym_presence_available
            && !PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getBoolean(
                    org.sipdroid.sipua.ui.Settings.PREF_REGISTRATION,
                    org.sipdroid.sipua.ui.Settings.DEFAULT_REGISTRATION))
        text = null;
    NotificationManager mNotificationMgr = (NotificationManager) mContext
            .getSystemService(Context.NOTIFICATION_SERVICE);
    if (text != null) {
        Notification notification = new Notification();
        NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);

        notification.icon = mInCallResId;
        if (type == MISSED_CALL_NOTIFICATION) {
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            //TODO
            /*notification.setLatestEventInfo(mContext, text, mContext.getString(R.string.app_name),
                  PendingIntent.getActivity(mContext, 0, createCallLogIntent(), 0));
            if (PreferenceManager.getDefaultSharedPreferences(Receiver.mContext).getBoolean(org.sipdroid.sipua.ui.Settings.PREF_NOTIFY, org.sipdroid.sipua.ui.Settings.DEFAULT_NOTIFY)) {
               notification.flags |= Notification.FLAG_SHOW_LIGHTS;
               notification.ledARGB = 0xff0000ff;  blue 
               notification.ledOnMS = 125;
               notification.ledOffMS = 2875;
            }*/
        } else {
            switch (type) {
            case MWI_NOTIFICATION:
                notification.flags |= Notification.FLAG_AUTO_CANCEL;
                notification.contentIntent = PendingIntent.getActivity(mContext, 0, createMWIIntent(), 0);
                notification.flags |= Notification.FLAG_SHOW_LIGHTS;
                notification.ledARGB = 0xff00ff00; /* green */
                notification.ledOnMS = 125;
                notification.ledOffMS = 2875;
                break;
            case AUTO_ANSWER_NOTIFICATION:
                notification.contentIntent = PendingIntent.getActivity(mContext, 0,
                        createIntent(AutoAnswer.class), 0);
                break;
            default:
                if (type >= REGISTER_NOTIFICATION && mSipdroidEngine != null
                        && type != REGISTER_NOTIFICATION + mSipdroidEngine.pref
                        && mInCallResId == R.drawable.sym_presence_available) {
                    int key = type - REGISTER_NOTIFICATION;
                    Intent in = createIntent(ChangeAccount.class);
                    in.setAction(Long.toString(type));
                    in.putExtra(ChangeAccount.ChangeAccountKey, key);
                    in.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    notification.contentIntent = PendingIntent.getActivity(mContext, key, in,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                } else
                    notification.contentIntent = PendingIntent.getActivity(mContext, 0,
                            createIntent(Sipdroid.class), 0);
                if (mInCallResId == R.drawable.sym_presence_away) {
                    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
                    notification.ledARGB = 0xffff0000; /* red */
                    notification.ledOnMS = 125;
                    notification.ledOffMS = 2875;
                }
                notification.flags |= Notification.FLAG_ONGOING_EVENT;
                break;
            }

            RemoteViews contentView = new RemoteViews(mContext.getPackageName(),
                    R.layout.ongoing_call_notification);
            contentView.setImageViewResource(R.id.icon, notification.icon);
            if (base != 0) {
                contentView.setChronometer(R.id.text1, base, text + " (%s)", true);
            } else if (type >= REGISTER_NOTIFICATION) {
                if (PreferenceManager.getDefaultSharedPreferences(mContext).getBoolean(
                        org.sipdroid.sipua.ui.Settings.PREF_POS, org.sipdroid.sipua.ui.Settings.DEFAULT_POS))
                    contentView.setTextViewText(R.id.text2,
                            text + "/" + mContext.getString(R.string.settings_pos3));
                else
                    contentView.setTextViewText(R.id.text2, text);
                if (mSipdroidEngine != null)
                    contentView.setTextViewText(R.id.text1,
                            mSipdroidEngine.user_profiles[type - REGISTER_NOTIFICATION].username + "@"
                                    + mSipdroidEngine.user_profiles[type - REGISTER_NOTIFICATION].realm_orig);
            } else
                contentView.setTextViewText(R.id.text1, text);
            notification.contentView = contentView;
        }
        mNotificationMgr.notify(type, notification);
    } else {
        mNotificationMgr.cancel(type);
    }
    if (type != AUTO_ANSWER_NOTIFICATION)
        updateAutoAnswer();
    if (mSipdroidEngine != null && type >= REGISTER_NOTIFICATION
            && type != REGISTER_NOTIFICATION + mSipdroidEngine.pref)
        onText(REGISTER_NOTIFICATION + mSipdroidEngine.pref, cache_text, cache_res, 0);
}

From source file:fm.krui.kruifm.StreamService.java

/**
 * Launches a foreground service with minimal information -- should be updated using updateNotification as soon as
 * track information is available./*from  w  w w  .j a  va2s.c om*/
 */
private void startForegoundService() {

    // Build the notification to be displayed during foreground execution
    notificationBuilder.setSmallIcon(R.drawable.play_icon_white);

    Notification notification = notificationBuilder.build();
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(NOTIFICATION_ID, notification);
    Log.v(TAG, "Started foreground streaming service.");
}

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

@Override
public void onHighlight(String bufferName, String message) {
    Intent i = new Intent(this, WeechatActivity.class);
    i.putExtra("buffer", bufferName);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

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

    Notification notification = builder.getNotification();
    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;

    // Default notification sound if enabled
    if (prefs.getBoolean("notification_sounds", false)) {
        notification.defaults |= Notification.DEFAULT_SOUND;
    }/*  w  w  w  .jav a2  s.c o m*/

    notificationManger.notify(NOTIFICATION_ID, notification);
}

From source file:be.ugent.zeus.hydra.util.audiostream.MusicService.java

/**
 * Configures service as a foreground service. A foreground service is a service that's doing
 * something the user is actively aware of (such as playing music), and must appear to the user
 * as a notification. That's why we create the notification here.
 *//*from   w w w  . j a  va 2  s.  c  o m*/
void setUpAsForeground(String text) {
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(getApplicationContext(), Urgent.class), PendingIntent.FLAG_UPDATE_CURRENT);

    mNotification = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.urgent_icon)
            .setTicker(text).setContentTitle("Urgent.fm livestream").setContentText(text).setContentIntent(pi)
            .build();

    mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(NOTIFICATION_ID, mNotification);
}

From source file:com.trogdan.nanospotify.service.MusicService.java

/**
 * Configures service as a foreground service. A foreground service is a service that's doing
 * something the user is actively aware of (such as playing music), and must appear to the
 * user as a notification. That's why we create the notification here.
 *//*from  ww  w .  j ava  2  s.c  o  m*/
void setUpAsForeground(String text) {
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,
            new Intent(getApplicationContext(), MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
    mNotification = new Notification();
    mNotification.tickerText = text;
    mNotification.icon = R.mipmap.ic_launcher;
    mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    mNotification.setLatestEventInfo(getApplicationContext(), getString(R.string.app_name), text, pi);
    startForeground(NOTIFICATION_ID, mNotification);
}

From source file:org.gaeproxy.GAEProxyService.java

private void notifyAlert(String title, String info) {
    notification.icon = R.drawable.ic_stat_gaeproxy;
    notification.tickerText = title;/*from w ww  . j av a2  s.com*/
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    initSoundVibrateLights(notification);
    // notification.defaults = Notification.DEFAULT_SOUND;
    notification.setLatestEventInfo(this, getString(R.string.app_name), info, pendIntent);
    startForegroundCompat(1, notification);
}

From source file:com.dmbstream.android.util.Util.java

public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService,
        Handler handler, Track song) {

    // Use the same text for the ticker and the expanded notification
    String title = song.title;//  w  ww.  j  av a 2  s .c  o m
    String text = song.artist;

    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.notify_playing, title,
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.partial_notification);

    // set the text for the notifications
    contentView.setTextViewText(R.id.notification_title, title);
    contentView.setTextViewText(R.id.notification_artist, text);

    Pair<Integer, Integer> colors = getNotificationTextColors(context);
    if (colors.getFirst() != null) {
        contentView.setTextColor(R.id.notification_title, colors.getFirst());
    }
    if (colors.getSecond() != null) {
        contentView.setTextColor(R.id.notification_artist, colors.getSecond());
    }

    notification.contentView = contentView;

    // Send them to the main menu when if they click the notification
    // TODO: Send them to the concert, playlist, compilation details or chat page?
    Intent notificationIntent = new Intent(context, MainMenuActivity.class);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    // Send the notification and put the service in the foreground.
    handler.post(new Runnable() {
        @Override
        public void run() {
            startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification);
        }
    });

    // Update widget
    DmbstreamAppWidgetProvider.getInstance().notifyChange(context, downloadService, true);
}