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.tenforwardconsulting.cordova.bgloc.LocationService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(TAG, "Received start id " + startId + ": " + intent);

    // config = Config.fromByteArray(intent.getByteArrayExtra("config"));
    if (intent.hasExtra("config")) {
        config = (Config) intent.getParcelableExtra("config");
    } else {/*  www . j av a  2  s  .c o m*/
        config = new Config();
    }

    ServiceProviderFactory spf = new ServiceProviderFactory(this, config);
    provider = spf.getInstance(config.getServiceProvider());
    provider.onCreate();

    if (config.getStartForeground()) {
        // Build a Notification required for running service in foreground.
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        builder.setContentTitle(config.getNotificationTitle());
        builder.setContentText(config.getNotificationText());
        if (config.getSmallNotificationIcon() != null) {
            builder.setSmallIcon(getPluginResource(config.getSmallNotificationIcon()));
        } else {
            builder.setSmallIcon(android.R.drawable.ic_menu_mylocation);
        }
        if (config.getLargeNotificationIcon() != null) {
            builder.setLargeIcon(BitmapFactory.decodeResource(getApplication().getResources(),
                    getPluginResource(config.getLargeNotificationIcon())));
        }
        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);
    }

    provider.startRecording();

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

From source file:com.oldsneerjaw.sleeptimer.CountdownNotifierTest.java

public void testPostNotification() {
    Date countdownEnds = new Date(0);

    notifier.postNotification(countdownEnds);

    Mockito.verify(mockCountdownTimeFormatFactory).getTimeFormat();
    Mockito.verify(mockNotificationManager).notify(Mockito.eq(NOTIFICATION_ID),
            Mockito.argThat(new BaseMatcher<Notification>() {
                @Override/*from w  w  w  .  ja v a 2 s.c  om*/
                public boolean matches(Object o) {
                    if (!(o instanceof Notification)) {
                        return false;
                    }

                    Notification candidate = (Notification) o;

                    return TextUtils.equals(NOTIFICATION_TITLE, candidate.tickerText)
                            && (candidate.icon == R.drawable.ic_launcher)
                            && (candidate.priority == NotificationCompat.PRIORITY_DEFAULT)
                            && (candidate.contentIntent != null)
                            && ((candidate.flags & Notification.FLAG_ONGOING_EVENT) != 0)
                            && ((candidate.flags & Notification.FLAG_AUTO_CANCEL) == 0);
                }

                @Override
                public void describeTo(Description description) {
                    // Describe the notification that was expected in the event of test failure
                    description.appendText(
                            "a notification with the correct title, icon, default priority, a pending intent, set to ongoing and NOT auto cancel");
                }
            }));
}

From source file:com.andrew.apollo.NotificationHelper.java

/**
 * Call this to build the {@link Notification}.
 *//*from   w  w  w .jav  a  2s . c  om*/
public void buildNotification(final String albumName, final String artistName, final String trackName,
        final Long albumId, final Bitmap albumArt) {

    // Default notfication layout
    mNotificationTemplate = new RemoteViews(mService.getPackageName(), R.layout.notification_template_base);

    // Set up the content view
    initCollapsedLayout(trackName, artistName, albumArt);

    if (ApolloUtils.hasHoneycomb()) {
        // Notification Builder
        mNotification = new NotificationCompat.Builder(mService).setSmallIcon(R.drawable.stat_notify_music)
                .setContentIntent(getPendingIntent()).setPriority(Notification.PRIORITY_DEFAULT)
                .setContent(mNotificationTemplate).build();
        // Control playback from the notification
        initPlaybackActions();
        if (ApolloUtils.hasJellyBean()) {
            // Expanded notifiction style
            mExpandedView = new RemoteViews(mService.getPackageName(),
                    R.layout.notification_template_expanded_base);
            mNotification.bigContentView = mExpandedView;
            // Control playback from the notification
            initExpandedPlaybackActions();
            // Set up the expanded content view
            initExpandedLayout(trackName, albumName, artistName, albumArt);
        }
        mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
    } else {
        // FIXME: I do not understand why this happens, but the
        // NotificationCompat
        // API does not work on Gingerbread. Specifically, {@code
        // #mBuilder.setContent()} won't apply the custom RV in Gingerbread.
        // So,
        // until this is fixed I'll just use the old way.
        mNotification = new Notification();
        mNotification.contentView = mNotificationTemplate;
        mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
        mNotification.icon = R.drawable.stat_notify_music;
        mNotification.contentIntent = getPendingIntent();
        mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
    }
}

From source file:com.makotosan.vimeodroid.TransferService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    counter++;/*from ww w .  j a  va 2s.c  om*/
    transfer = new Transfer();
    final String videoUri = intent.getStringExtra("videouri");
    final TransferType transferType = TransferType.valueOf(intent.getStringExtra("transferType"));
    final String fileName = intent.getStringExtra("fileName");
    Bitmap bitmapThumbnail = null;
    int transferIcon = android.R.drawable.stat_sys_download;

    if (transferType == TransferType.Upload) {
        // Get the resource ID for the video
        final long resourceId = ContentUris.parseId(Uri.parse(videoUri));

        bitmapThumbnail = android.provider.MediaStore.Video.Thumbnails.getThumbnail(getContentResolver(),
                resourceId, android.provider.MediaStore.Video.Thumbnails.MICRO_KIND, null);
        transfer.setIcon(bitmapThumbnail);
        transferIcon = android.R.drawable.stat_sys_upload;
    }

    // Initialize our notification
    final Notification notification = new Notification(transferIcon, "Transferring...",
            System.currentTimeMillis());
    notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
    notification.contentView = new RemoteViews(this.getPackageName(), R.layout.transferprogress);

    final Intent manageIntent = new Intent(this, ManageTransfersActivity.class);

    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, manageIntent, 0);

    notification.contentIntent = pendingIntent;
    if (bitmapThumbnail != null) {
        notification.contentView.setImageViewBitmap(R.id.transferprogressIcon, bitmapThumbnail);
    } else {
        notification.contentView.setImageViewResource(R.id.transferprogressIcon, R.drawable.icon);
    }

    notification.contentView.setProgressBar(R.id.transferprogressBar, 100, 0, false);
    notification.contentView.setTextViewText(R.id.transferprogressText, "Transferring... ");
    notification.contentView.setOnClickPendingIntent(R.layout.transferprogress, pendingIntent);

    // Add it to the collection of notifications
    notifications.put(counter, notification);

    // Add our notification to the notification tray
    notificationManager.notify(counter, notification);

    // Initialize our asynchronous transfer task
    final TransferTask task = new TransferTask(counter, transferType);

    task.execute(videoUri, fileName);
    return Service.START_STICKY;
}

From source file:com.ad.mediasharing.ADUploadMediaTask.java

@SuppressWarnings("deprecation")
protected void onPreExecute() {

    Intent intent = new Intent();
    pendingIntent = PendingIntent.getActivity(mActivity, 0, intent, 0);

    contentTitle = "Uploading Story...";
    CharSequence contentText = uploadProgress + "% complete";

    // Show the notification progress 
    if (isPreferenceProgressEnabled) {
        notification = new Notification(R.drawable.ic_launcher_ctv, contentTitle, System.currentTimeMillis());
        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT;
        notification.contentIntent = pendingIntent;
        notification.setLatestEventInfo(mActivity, contentTitle, contentText, pendingIntent);

        notificationManager.notify(NOTIFICATION_ID, notification);
    }/*  w w  w .j av a 2  s. co  m*/

    // Show the alert progress bar 
    if (isProgressBarEnabled) {
        pd = new ProgressDialog(mActivity);
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        pd.setMessage(contentTitle);
        pd.setCancelable(false);
        pd.show();
    }
}

From source file:com.emsitel.emsivoz.MainActivity.java

private Notification createRunningNotification(int titleResId, int contentResId, int tickerResId) {
    PendingIntent notificationTapIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);
    nBuilder.setSmallIcon(R.drawable.icon2).setContentIntent(notificationTapIntent).setOnlyAlertOnce(true)
            .setTicker(getString(tickerResId)).setContentTitle(getString(titleResId))
            .setContentText(getString(contentResId));

    Notification runningNotification = nBuilder.build();
    runningNotification.flags |= Notification.FLAG_ONGOING_EVENT;
    return runningNotification;
}

From source file:com.oasisfeng.nevo.StatusBarNotificationEvo.java

@Override
public boolean isOngoing() {
    try {/*from  ww  w. j  a v  a  2s.  c  o  m*/
        return (notification().getFlags() & Notification.FLAG_ONGOING_EVENT) != 0;
    } catch (final RemoteException e) {
        throw new IllegalStateException(e);
    }
}

From source file:menion.android.whereyougo.gui.extension.activity.CustomActivity.java

public static void setStatusbar(Activity activity) {
    try {// w ww  .  j  a  va 2 s.c o m
        NotificationManager mNotificationManager = (NotificationManager) activity
                .getSystemService(Context.NOTIFICATION_SERVICE);
        // set statusbar
        if (Preferences.APPEARANCE_STATUSBAR) {
            Context context = activity.getApplicationContext();
            Intent intent = new Intent(context, menion.android.whereyougo.gui.activity.MainActivity.class);
            // intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setAction(Intent.ACTION_MAIN);
            PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
            final int sdkVersion = Integer.parseInt(android.os.Build.VERSION.SDK);
            Notification notif = null;
            if (sdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
                notif = new Notification(R.drawable.ic_title_logo, A.getAppName(), System.currentTimeMillis());
                notif.setLatestEventInfo(activity, A.getAppName(), "", pIntent);
            } else {
                NotificationCompat.Builder builder = new NotificationCompat.Builder(activity)
                        .setContentTitle(A.getAppName()).setSmallIcon(R.drawable.ic_title_logo)
                        .setContentIntent(pIntent);
                notif = builder.build();
            }
            notif.flags = Notification.FLAG_ONGOING_EVENT;
            mNotificationManager.notify(0, notif);
        } else {
            mNotificationManager.cancel(0);
        }
    } catch (Exception e) {
        // Logger.e(TAG, "setStatusbar(" + activity + ")", e);
    }
}

From source file:uk.co.gidley.clockRadio.RadioPlayerService.java

private void showNotification() {
    // In this sample, we'll use the same text for the ticker and the
    // expanded notification
    CharSequence text = getText(R.string.local_service_started);

    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.icon, text, System.currentTimeMillis());

    // The PendingIntent to launch our activity if the user selects this
    // notification
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ClockRadioActivity.class),
            0);/*from   ww  w.  jav a 2s .c o  m*/

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(this, getText(R.string.local_service_label), text, contentIntent);
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(NOTIFICATION, notification);

    Log.d(TAG, "Show Notification Complete");

}

From source file:com.developer.shade.sensors.SensorService.java

private void initNotification() {
    Log.v("Running initNot", "Method To Create Notification For Monitoring Service");
    NotificationCompat.Builder notiBuilder = new NotificationCompat.Builder(this);
    notiBuilder.setContentTitle("Running Fall Detection");
    notiBuilder.setSmallIcon(R.mipmap.ic_launcher);
    notiBuilder.setAutoCancel(false);// www .  j  a v  a 2s  .c  om

    Notification noti = notiBuilder.build();
    noti.flags = Notification.FLAG_ONGOING_EVENT;

    notiManager = NotificationManagerCompat.from(this);
    notiManager.notify(NOTIFICATION_ID, noti);
}