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.oasisfeng.nevo.StatusBarNotificationEvo.java

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

From source file:net.bible.android.device.ProgressNotificationManager.java

/** find the Progress object in our map to the associated Notifications
 * //from   w  w w. ja  v a  2 s.c  o  m
 * @param prog
 * @return
 */
private Notification findOrCreateNotification(Progress prog) {
    Notification notification = progressMap.get(prog);
    if (notification == null) {
        Log.d(TAG, "Creating Notification for progress Hash:" + prog.hashCode());
        // configure the intent
        Intent intent = new Intent(BibleApplication.getApplication(), ProgressStatus.class);
        final PendingIntent pendingIntent = PendingIntent.getActivity(BibleApplication.getApplication(), 0,
                intent, 0);

        notification = new Notification(R.drawable.bible, prog.getJobName(), System.currentTimeMillis());
        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT
                | Notification.FLAG_AUTO_CANCEL;
        notification.contentView = new RemoteViews(SharedConstants.PACKAGE_NAME,
                R.layout.progress_notification);
        notification.contentIntent = pendingIntent;
        notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.bible);
        notification.contentView.setTextViewText(R.id.status_text, "");
        notification.contentView.setProgressBar(R.id.status_progress, 100, prog.getWork(), false);

        progressMap.put(prog, notification);

        androidNotificationManager.notify(prog.hashCode(), notification);
    }

    return notification;
}

From source file:net.bible.service.device.ProgressNotificationManager.java

/** find the Progress object in our map to the associated Notifications
 * /* w w w  .j  a  va  2  s .c om*/
 * @param prog
 * @return
 */
private Notification findOrCreateNotification(Progress prog) {
    Notification notification = progressMap.get(prog);
    if (notification == null) {
        Log.d(TAG, "Creating Notification for progress Hash:" + prog.hashCode());
        // configure the intent
        Intent intent = new Intent(BibleApplication.getApplication(), ProgressStatus.class);
        final PendingIntent pendingIntent = PendingIntent.getActivity(BibleApplication.getApplication(), 0,
                intent, 0);

        notification = new Notification(R.drawable.ic_stat_ichthys, prog.getJobName(),
                System.currentTimeMillis());
        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT
                | Notification.FLAG_AUTO_CANCEL;
        notification.contentView = new RemoteViews(SharedConstants.PACKAGE_NAME,
                R.layout.progress_notification);
        notification.contentIntent = pendingIntent;
        notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ichthys);
        notification.contentView.setTextViewText(R.id.status_text, "");
        notification.contentView.setProgressBar(R.id.status_progress, 100, prog.getWork(), false);

        progressMap.put(prog, notification);

        androidNotificationManager.notify(prog.hashCode(), notification);
    }

    return notification;
}

From source file:com.evandroid.musica.services.BatchDownloaderService.java

private void updateProgress() {
    NotificationManager manager = ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE));
    if (count < total) {
        NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
        notifBuilder.setSmallIcon(android.R.drawable.stat_sys_download)
                .setContentTitle(getString(R.string.app_name))
                .setContentText(String.format(getString(R.string.dl_progress), count, total))
                .setProgress(total, count, false).setShowWhen(false);
        Notification notif = notifBuilder.build();
        notif.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
        if (count == 0)
            startForeground(1, notif);// w  w w  .j  a v  a2s  . c  om
        else
            manager.notify(1, notif);
    } else {
        stopForeground(true);
        Intent refreshIntent = new Intent("com.geecko.QuickLyric.updateDBList");
        PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 4, refreshIntent,
                PendingIntent.FLAG_ONE_SHOT);
        String text = getResources().getQuantityString(R.plurals.dl_finished_desc, successCount, successCount);
        NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
        notifBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done);
        notifBuilder.setContentIntent(pendingIntent);
        notifBuilder.setContentTitle(getString(R.string.dl_finished));
        notifBuilder.setContentText(text);
        Notification notif = notifBuilder.build();
        notif.flags |= Notification.FLAG_AUTO_CANCEL;
        manager.notify(1, notif);
        stopSelf();
    }
}

From source file:com.bellman.bible.service.device.ProgressNotificationManager.java

/**
 * find the Progress object in our map to the associated Notifications
 *
 * @param prog/*from   ww w.  ja  v a2  s  .co  m*/
 * @return
 */
private Notification findOrCreateNotification(Progress prog) {
    Notification notification = progressMap.get(prog);
    if (notification == null) {
        Log.d(TAG, "Creating Notification for progress Hash:" + prog.hashCode());
        // configure the intent
        Intent intent = new Intent(CurrentActivityHolder.getInstance().getApplication(), ProgressStatus.class);
        final PendingIntent pendingIntent = PendingIntent
                .getActivity(CurrentActivityHolder.getInstance().getApplication(), 0, intent, 0);

        notification = new Notification(R.drawable.ic_stat_ichthys, prog.getJobName(),
                System.currentTimeMillis());
        notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT
                | Notification.FLAG_AUTO_CANCEL;
        notification.contentView = new RemoteViews(SharedConstants.PACKAGE_NAME,
                R.layout.progress_notification);
        notification.contentIntent = pendingIntent;
        notification.contentView.setImageViewResource(R.id.status_icon, R.drawable.ichthys);
        notification.contentView.setTextViewText(R.id.status_text, "");
        notification.contentView.setProgressBar(R.id.status_progress, 100, prog.getWork(), false);

        progressMap.put(prog, notification);

        androidNotificationManager.notify(prog.hashCode(), notification);
    }

    return notification;
}

From source file:step.StepService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    if (Build.VERSION.SDK_INT < 18) {

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.step_launcher).setContentTitle("??")
                .setContentText("??");

        Notification notification = mBuilder.build();

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, StepCountActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);

        notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
        mBuilder.setContentIntent(contentIntent);
        startForeground(GRAY_SERVICE_ID, notification);//API < 18 ??Notification
    } else {/*from  w ww  .j a va2  s.c om*/
        Intent innerIntent = new Intent(this, GrayInnerService.class);
        startService(innerIntent);
        startForeground(GRAY_SERVICE_ID, new Notification());
    }

    return Service.START_STICKY;
}

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

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

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

    Intent intentClose = new Intent(PlayingService.actionClose);
    intentClose.putExtra("aid", track.getAid());
    intentClose.setComponent(new ComponentName(context, DownloadingService.class));

    Intent intentPause = new Intent(PlayingService.actionIconPlay);
    intentPause.putExtra("aid", track.getAid());
    intentPause.setComponent(new ComponentName(context, DownloadingService.class));

    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;/*from  w  ww  .j a v  a2 s  .c  o  m*/
    notification.flags = Notification.FLAG_ONGOING_EVENT;
    notification.icon = R.drawable.download_icon;

    return notification;
}

From source file:net.kseek.camtest.ui.CamtestActivity.java

public void onStart() {
    super.onStart();

    // Lock screen
    mWakeLock.acquire();//from  w  ww  . ja  va 2 s.  c om

    // Did the user disabled the notification ?
    if (mApplication.notificationEnabled) {
        Intent notificationIntent = new Intent(this, CamtestActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        Notification notification = builder.setContentIntent(pendingIntent).setWhen(System.currentTimeMillis())
                .setTicker(getText(R.string.notification_title)).setSmallIcon(R.drawable.icon)
                .setContentTitle(getText(R.string.notification_title))
                .setContentText(getText(R.string.notification_content)).build();
        notification.flags |= Notification.FLAG_ONGOING_EVENT;
        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification);
    } else {
        removeNotification();
    }

    bindService(new Intent(this, CustomHttpServer.class), mHttpServiceConnection, Context.BIND_AUTO_CREATE);
    bindService(new Intent(this, CustomRtspServer.class), mRtspServiceConnection, Context.BIND_AUTO_CREATE);

}

From source file:pct.droid.base.torrent.TorrentService.java

public void startForeground() {
    Timber.d("startForeground");
    if (mInForeground)
        return;/*from w w w  .  j  a  v a  2  s . c o  m*/

    Intent notificationIntent = new Intent(this, mCurrentActivityClass);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(pct.droid.base.R.drawable.ic_notif_logo)
            .setContentTitle("Popcorn Time - " + getString(pct.droid.base.R.string.running))
            .setContentText(getString(R.string.tap_to_resume)).setOngoing(true).setContentIntent(pendingIntent)
            .setCategory(NotificationCompat.CATEGORY_SERVICE);

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

    startForeground(mId, notification);
    mInForeground = true;
}

From source file:de.wikilab.android.friendica01.FileUploadService.java

@Override
protected void onHandleIntent(Intent intent) {
    Log.i("Andfrnd/UploadFile", "onHandleIntent exec");

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    //Instantiate the Notification:
    CharSequence tickerText = "Uploading...";
    Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_ONGOING_EVENT;

    //Define the Notification's expanded message and Intent:
    Context context = getApplicationContext();
    PendingIntent nullIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
    notification.setLatestEventInfo(context, "Upload in progress...", "You are notified here when it completes",
            nullIntent);/*from w  w w  . ja  v a2 s.co  m*/

    //Pass the Notification to the NotificationManager:
    mNotificationManager.notify(UPLOAD_PROGRESS_ID, notification);
    /*
    final TwLogin login = new TwLogin();
    login.initialize(FileUploadService.this);
    login.doLogin(FileUploadService.this, null, false);
            
    if (!login.isLoginOK()) {
       showFailMsg(FileUploadService.this, "Invalid login data or no network connection");
       return;
    }
    */
    Bundle intentPara = intent.getExtras();
    fileToUpload = (Uri) intentPara.getParcelable(Intent.EXTRA_STREAM);
    descText = intentPara.getString(EXTRA_DESCTEXT);
    subject = intentPara.getString(Intent.EXTRA_SUBJECT);

    if (targetFilename == null || targetFilename.equals(""))
        targetFilename = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()) + ".txt";

    String fileSpec = Max.getRealPathFromURI(FileUploadService.this, fileToUpload);

    String tempFile = Max.IMG_CACHE_DIR + "/imgUploadTemp_" + System.currentTimeMillis() + ".jpg";
    Max.resizeImage(fileSpec, tempFile, 1024, 768);

    try {
        Log.i("Andfrnd/UploadFile", "before uploadFile");
        final TwAjax uploader = new TwAjax(FileUploadService.this, true, true);
        uploader.addPostFile(new TwAjax.PostFile("media", targetFilename, tempFile));
        uploader.addPostData("status", descText);
        uploader.addPostData("title", subject);
        uploader.addPostData("source",
                "<a href='http://friendica-for-android.wiki-lab.net'>Friendica for Android</a>");
        uploader.uploadFile(Max.getServer(this) + "/api/statuses/update", null);
        Log.i("Andfrnd/UploadFile", "after uploadFile");
        Log.i("Andfrnd/UploadFile", "isSuccess() = " + uploader.isSuccess());
        Log.i("Andfrnd/UploadFile", "getError() = " + uploader.getError());

        mNotificationManager.cancel(UPLOAD_PROGRESS_ID);
        if (uploader.isSuccess() && uploader.getError() == null) {
            JSONObject result = null;
            try {
                Log.i("Andfrnd/UploadFile", "JSON RESULT: " + uploader.getHttpCode());
                result = (JSONObject) uploader.getJsonResult();

                String postedText = result.getString("text");
                showSuccessMsg(FileUploadService.this);

            } catch (Exception e) {
                String errMes = e.getMessage() + " | " + uploader.getResult();
                if (result != null)
                    try {
                        errMes = result.getString("error");
                    } catch (JSONException fuuuuJava) {
                    }

                showFailMsg(FileUploadService.this, errMes);

                e.printStackTrace();
            }
        } else if (uploader.getError() != null) {
            showFailMsg(FileUploadService.this, uploader.getError().toString());
        } else {
            showFailMsg(FileUploadService.this, uploader.getResult());
        }

    } finally {
        new File(tempFile).delete();
    }
}