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:org.linphone.compatibility.ApiElevenPlus.java

@SuppressWarnings("deprecation")
public static Notification createInCallNotification(Context context, String title, String msg, int iconID,
        Bitmap contactIcon, String contactName, PendingIntent intent) {

    Notification notif = new Notification.Builder(context).setContentTitle(contactName).setContentText(msg)
            .setSmallIcon(iconID).setAutoCancel(false).setContentIntent(intent)
            .setWhen(System.currentTimeMillis()).setLargeIcon(contactIcon).getNotification();
    notif.flags |= Notification.FLAG_ONGOING_EVENT;

    return notif;
}

From source file:com.ademsha.appnotifico.NotificationHelper.java

public static void notifyForForegroundService(final Service service,
        final PreparedNotification preparedNotification) {

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(preparedNotification.getContext())
            .setPriority(NotificationCompat.PRIORITY_MIN).setOngoing(true).setAutoCancel(false)
            .setOnlyAlertOnce(true);/*from  w  w  w. ja  v  a 2  s .  c om*/

    if (preparedNotification.getPendingIntentForActivity() != null) {
        builder.setContentIntent(preparedNotification.getPendingIntentForService());
    }

    builder.setContentTitle(preparedNotification.getTitle());
    builder.setContentText(preparedNotification.getText());

    if (preparedNotification.getLargeIcon() != null) {
        builder.setLargeIcon(preparedNotification.getLargeIcon());
    }

    if (preparedNotification.getSmallIcon() > 0) {
        builder.setSmallIcon(preparedNotification.getSmallIcon());
    }

    builder.setTicker(preparedNotification.getTicker());

    if (!preparedNotification.getExpanded().equals("")
            && !preparedNotification.getExpandedSummary().equals("")) {
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(preparedNotification.getExpanded())
                .setBigContentTitle(preparedNotification.getTitle())
                .setSummaryText(preparedNotification.getExpandedSummary()));
    }

    if (preparedNotification.getPendingIntentForActivity() != null) {
        builder.setContentIntent(preparedNotification.getPendingIntentForActivity());
    }

    Notification notification;
    notification = builder.build();
    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE
            | Notification.FLAG_NO_CLEAR;
    service.startForeground(10000, notification);
}

From source file:com.gelakinetic.mtgfam.helpers.DbUpdaterService.java

@Override
public void onCreate() {
    super.onCreate();
    mPrefAdapter = new PreferencesAdapter(this);
    try {//from   w w w. ja  va  2s. c  o m
        mDbHelper = new CardDbAdapter(this);
    } catch (FamiliarDbException e) {
        mDbHelper = null;
        return; // couldnt open the db, might as well return
    }
    mDbHelper.close(); // close the newly opened db so we can transact it later
    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Intent intent = new Intent(this, MainActivity.class);
    mNotificationIntent = PendingIntent.getActivity(this, 0, intent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this.getApplicationContext());
    mUpdateNotification = builder.setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.update_notification))
            .setSmallIcon(R.drawable.rt_notification_icon).setContentIntent(mNotificationIntent)
            .setWhen(System.currentTimeMillis()).build();

    mUpdateNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    mUpdateNotification.flags |= Notification.FLAG_ONLY_ALERT_ONCE;
}

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

@SuppressWarnings("deprecation")
@Override/*from w  ww  . j a  v a 2 s .com*/
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);
    }
}

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

@AnyThread
@Cat/*from   w  w w.jav  a  2 s  .co  m*/
static void showMain(@NonNull RelayService relay, @NonNull String content) {
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
            new Intent(context, WeechatActivity.class), PendingIntent.FLAG_CANCEL_CURRENT);

    boolean authenticated = relay.state.contains(AUTHENTICATED);
    int icon = authenticated ? R.drawable.ic_connected : R.drawable.ic_disconnected;

    Builder builder = new Builder(context, NOTIFICATION_CHANNEL_CONNECTION_STATUS);
    builder.setContentIntent(contentIntent).setSmallIcon(icon)
            .setContentTitle("Weechat-Android " + BuildConfig.VERSION_NAME).setContentText(content)
            .setWhen(System.currentTimeMillis());

    builder.setPriority(Notification.PRIORITY_MIN);

    if (P.notificationTicker)
        builder.setTicker(content);

    String disconnectText = context.getString(authenticated ? R.string.disconnect : R.string.stop_connecting);

    builder.addAction(android.R.drawable.ic_menu_close_clear_cancel, disconnectText, PendingIntent.getService(
            context, 0, new Intent(RelayService.ACTION_STOP, null, context, RelayService.class), 0));

    Notification notification = builder.build();
    notification.flags |= Notification.FLAG_ONGOING_EVENT;

    relay.startForeground(NOTIFICATION_MAIN_ID, notification);
}

From source file:com.vanhacks.vandroid.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_container);
    ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.SEND_SMS }, 1);
    ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, 1);
    ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 1);

    // start of notif stuff
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notif_icon_test).setContentTitle("Android Local Update is Available")
            .setContentText("Replace Current Version");
    int mId = 001;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    //        set the intent stuff
    Intent resultIntent = new Intent(this, HomeActivity.class);
    // Because clicking the notification opens a new ("special") activity, there's
    // no need to create an artificial back stack.
    PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);

    Notification not = mBuilder.build();
    not.flags = Notification.FLAG_ONGOING_EVENT;
    mNotificationManager.notify(mId, not);
    // end of notif stuff
}

From source file:com.tenforwardconsulting.cordova.bgloc.AbstractLocationService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(TAG, "Received start id " + startId + ": " + intent);
    if (intent != null) {
        config = (Config) intent.getParcelableExtra("config");
        activity = intent.getStringExtra("activity");
        Log.d(TAG, "Got activity" + activity);

        // Build a Notification required for running service in foreground.
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle(config.getNotificationTitle());
        builder.setContentText(config.getNotificationText());
        builder.setSmallIcon(android.R.drawable.ic_menu_mylocation);
        if (config.getNotificationIcon() != null) {
            builder.setSmallIcon(getPluginResource(config.getSmallNotificationIcon()));
            builder.setLargeIcon(BitmapFactory.decodeResource(getApplication().getResources(),
                    getPluginResource(config.getLargeNotificationIcon())));
        }/*ww w .  j  a  v  a2s.co  m*/
        if (config.getNotificationIconColor() != null) {
            builder.setColor(this.parseNotificationIconColor(config.getNotificationIconColor()));
        }

        setClickEvent(builder);

        Notification notification = builder.build();
        notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE
                | Notification.FLAG_NO_CLEAR;
        startForeground(startId, notification);
    }
    Log.i(TAG, config.toString());
    Log.i(TAG, "- activity: " + activity);

    //We want this service to continue running until it is explicitly stopped
    return START_STICKY;
}

From source file:com.perm.DoomPlay.DownloadNotifBuilder.java

private Notification createStartingNew() {
    Notification notification = new Notification();
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.notif_download);

    views.setProgressBar(R.id.progressDownload, 100, 0, true);
    views.setTextViewText(R.id.notifTitle, context.getResources().getString(R.string.Downloading));
    views.setTextViewText(R.id.notifArtist, track.getArtist() + "-" + track.getTitle());
    views.setImageViewResource(R.id.notifPause, R.drawable.widget_pause);

    ComponentName componentName = new ComponentName(context, DownloadingService.class);

    Intent intentClose = new Intent(PlayingService.actionClose);
    intentClose.putExtra("aid", track.getAid());
    intentClose.setComponent(componentName);

    Intent intentPause = new Intent(PlayingService.actionIconPause);
    intentPause.putExtra("aid", track.getAid());
    intentPause.setComponent(componentName);

    views.setOnClickPendingIntent(R.id.notifClose,
            PendingIntent.getService(context, notificationId, intentClose, PendingIntent.FLAG_UPDATE_CURRENT));

    views.setOnClickPendingIntent(R.id.notifPause,
            PendingIntent.getService(context, notificationId, intentPause, PendingIntent.FLAG_UPDATE_CURRENT));

    notification.contentView = views;//www  . j  a  va 2s  .  co  m
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    notification.icon = R.drawable.download_icon;

    return notification;

}

From source file:org.linphone.compatibility.ApiElevenPlus.java

@SuppressWarnings("deprecation")
public static Notification createNotification(Context context, String title, String message, int icon,
        int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) {
    Notification notif;//  w  w  w.j  ava2 s.  c om

    if (largeIcon != null) {
        notif = new Notification.Builder(context).setContentTitle(title).setContentText(message)
                .setSmallIcon(icon, level).setLargeIcon(largeIcon).setContentIntent(intent)
                .setWhen(System.currentTimeMillis()).getNotification();
    } else {
        notif = new Notification.Builder(context).setContentTitle(title).setContentText(message)
                .setSmallIcon(icon, level).setContentIntent(intent).setWhen(System.currentTimeMillis())
                .getNotification();
    }
    if (isOngoingEvent) {
        notif.flags |= Notification.FLAG_ONGOING_EVENT;
    }

    return notif;
}

From source file:android.support.v7.app.NotificationCompatImplBase.java

public static <T extends NotificationCompatBase.Action> void overrideBigContentView(Notification n,
        Context context, CharSequence contentTitle, CharSequence contentText, CharSequence contentInfo,
        int number, Bitmap largeIcon, CharSequence subText, boolean useChronometer, long when, List<T> actions,
        boolean showCancelButton, PendingIntent cancelButtonIntent) {
    n.bigContentView = generateBigContentView(context, contentTitle, contentText, contentInfo, number,
            largeIcon, subText, useChronometer, when, actions, showCancelButton, cancelButtonIntent);
    if (showCancelButton) {
        n.flags |= Notification.FLAG_ONGOING_EVENT;
    }// w w w.  java 2  s.c  o  m
}