Example usage for android.app Notification FLAG_AUTO_CANCEL

List of usage examples for android.app Notification FLAG_AUTO_CANCEL

Introduction

In this page you can find the example usage for android.app Notification FLAG_AUTO_CANCEL.

Prototype

int FLAG_AUTO_CANCEL

To view the source code for android.app Notification FLAG_AUTO_CANCEL.

Click Source Link

Document

Bit to be bitwise-ored into the #flags field that should be set if the notification should be canceled when it is clicked by the user.

Usage

From source file:com.odoo.util.ONotificationHelper.java

public void setResultIntent(Intent intent, Context context) {
    this.notificationIntent = intent;
    pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL);
}

From source file:org.cesar.geofencesdemo.managers.NotificationsManager.java

/**
 * This notification it has to be launched when we enter or exit from a
 * location we've sepcified before in the {@link MainActivity}
 * /*w ww  .j  a v  a 2  s. c o m*/
 * @param geofence
 */
public void showLocationReminderNotification(final SimpleGeofence geofence) {

    mNotification = new NotificationCompat.Builder(mContext)
            .setTicker(mContext.getString(R.string.location_reminder_label))
            .setSmallIcon(R.drawable.ic_launcher)
            .setContentTitle(mContext.getString(R.string.location_reminder_label))
            .setContentText(geofence.getAddress()).setOnlyAlertOnce(true).setContentIntent(null).build();

    mNotification.flags = Notification.FLAG_AUTO_CANCEL;
    mNotification.defaults |= Notification.DEFAULT_LIGHTS;
    mNotification.defaults |= Notification.DEFAULT_VIBRATE;
    mNotification.defaults |= Notification.DEFAULT_SOUND;

    // Launch notification
    mNotificationManager.notify(Integer.valueOf(geofence.getPlaceId()), mNotification);
}

From source file:org.ancode.alivelib.notification.AliveNotification.java

public void show(Intent intent) {
    CharSequence tickerText;/*w  w  w . ja  va 2 s  .c o  m*/
    CharSequence contentTitle;
    CharSequence contentText;
    Bitmap largeIcon;
    tickerText = tickerTextStr;
    contentTitle = titleStr;
    contentText = textStr;
    if (mLargeIcon == -1) {
        largeIcon = bLargeIcon;
    } else {

        largeIcon = ((BitmapDrawable) HelperConfig.CONTEXT.getResources().getDrawable(mLargeIcon)).getBitmap();
    }

    try {
        if (intent != null)
            setIntent(intent);
        Notification notification = createBuilder(largeIcon, mSmallIcon, contentTitle, contentText, tickerText,
                System.currentTimeMillis(), true, false, true, pendingIntent);
        //??
        notification.flags = Notification.FLAG_AUTO_CANCEL;
        manager.notify(notifyFlag, notification);
        AliveLog.v(TAG, "notification is show");
    } catch (Exception e) {
        AliveLog.e(TAG, "notification is error\n" + e.getLocalizedMessage());
    }

}

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

private void showFailMsg(Context ctx, String txt) {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);

    Log.e("Andfrnd/UploadFile", "Upload FAILED: " + txt);

    //Instantiate the Notification:
    CharSequence tickerText = "Upload failed, please retry!";
    Notification notification = new Notification(R.drawable.arrow_up, tickerText, System.currentTimeMillis());
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    //Define the Notification's expanded message and Intent:
    Context context = getApplicationContext();
    CharSequence contentTitle = "Upload failed, click to retry!";
    CharSequence contentText = txt;
    Intent notificationIntent = new Intent(this, FriendicaImgUploadActivity.class);
    Bundle b = new Bundle();
    b.putParcelable(Intent.EXTRA_STREAM, fileToUpload);
    b.putString(Intent.EXTRA_SUBJECT, subject);
    b.putString(EXTRA_DESCTEXT, descText);

    notificationIntent.putExtras(b);//from w  w w  . j  ava  2  s . co m
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    //Pass the Notification to the NotificationManager:
    mNotificationManager.notify(UPLOAD_FAILED_ID, notification);
    //Toast.makeText(ctx, "Upload failed, please retry:\n" + txt, Toast.LENGTH_LONG).show();
}

From source file:br.ufrn.dimap.pubshare.download.service.DownloaderService.java

/**
* The IntentService calls this method from the default worker thread with
* the intent that started the service. When this method returns, IntentService
* stops the service, as appropriate.//from  w w  w.  j a  va2 s.  co  m
*/
@Override
protected void onHandleIntent(Intent intent) {
    Log.d(TAG, "onHandleIntent on DownloadService");

    Article selectedArticle = (Article) intent.getSerializableExtra(Article.KEY_INSTANCE);

    if (!AndroidUtils.isExternalStorageAvailable()) {
        // Generate Menssages
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_menu_notifications)
                .setContentTitle(getResources().getString(R.string.external_storage_unavailable))
                .setContentText(getResources().getString(R.string.check_media_availability));
        Notification notification = mBuilder.build();
        // Set the Notification as ongoing
        notification.flags = notification.flags | Notification.FLAG_AUTO_CANCEL;

        NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        nManager.notify(0, notification);
        return;
    }

    DownloadManager dowloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); // since API level 9

    Request request = new Request(Uri.parse(selectedArticle.getRemoteLocation()));
    request.setAllowedNetworkTypes(Request.NETWORK_WIFI | Request.NETWORK_MOBILE);
    request.setTitle(selectedArticle.getTitle());
    request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,
            selectedArticle.generateFileName());
    request.setVisibleInDownloadsUi(true);

    long enqueue = dowloadManager.enqueue(request);

    Log.d(TAG, "Download enqueue..." + enqueue);

    ArticleDownloaded articleDownloaded = new ArticleDownloaded();
    articleDownloaded.setDownloadKey(enqueue);

    DownloadDao downloadDao = new DownloadDao(this);
    downloadDao.insert(articleDownloaded);

    Log.d(TAG, "Insert " + articleDownloaded + " in SqLite: OK");
}

From source file:com.fn.reunion.app.xmpp.Notifier.java

public void notify(String notificationId, String apiKey, String title, String message, String uri) {
    Log.d(LOGTAG, "notify()...");

    Log.d(LOGTAG, "notificationId=" + notificationId);
    Log.d(LOGTAG, "notificationApiKey=" + apiKey);
    Log.d(LOGTAG, "notificationTitle=" + title);
    Log.d(LOGTAG, "notificationMessage=" + message);
    Log.d(LOGTAG, "notificationUri=" + uri);

    if (isNotificationEnabled()) {
        // Show the toast
        if (isNotificationToastEnabled()) {
            Toast.makeText(context, message, Toast.LENGTH_LONG).show();
        }// w  ww  . j a va  2s . c o  m

        Notification notification = new Notification();
        notification.icon = getNotificationIcon();
        notification.defaults = Notification.DEFAULT_LIGHTS;

        if (isNotificationSoundEnabled()) {
            notification.defaults |= Notification.DEFAULT_SOUND;
        }

        if (isNotificationVibrateEnabled()) {
            notification.defaults |= Notification.DEFAULT_VIBRATE;
        }

        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.when = System.currentTimeMillis();
        notification.tickerText = message;

        Intent intent = new Intent(context, NotificationDetailsActivity.class);
        intent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        intent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        intent.putExtra(Constants.NOTIFICATION_TITLE, title);
        intent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
        intent.putExtra(Constants.NOTIFICATION_URI, uri);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        /*      notification.setLatestEventInfo(context, notficationMessage , message , contentIntent);
              notificationManager.notify(Consts.NOTIFICATION_ID, notification);*/

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(getNotificationIcon()).setContentTitle("").setContentText("");

        Notification n = mBuilder.setContentIntent(contentIntent).setSmallIcon(getNotificationIcon())
                .setTicker("").setWhen(System.currentTimeMillis()).setAutoCancel(true).setContentTitle(title)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message.replaceAll("[\t\n\r]", "\n")))
                .setContentText(message).build();

        if (isNotificationSoundEnabled()) {
            n.defaults |= Notification.DEFAULT_SOUND;
        }

        if (isNotificationVibrateEnabled()) {
            n.defaults |= Notification.DEFAULT_VIBRATE;
        }
        notificationManager.notify(Consts.NOTIFICATION_ID, n);
        // Notification
    } else {
        Log.w(LOGTAG, "Notificaitons disabled.");
    }
}

From source file:com.fremontunified.ifusdandroid.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//*from w ww .  j  a v a 2  s  . c om*/
private static void generateNotification(Context context, String message) {
    Intent notificationIntent = new Intent(context, FremontUnified.class);
    PendingIntent pIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    Notification noti = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_stat_gcm)
            .setContentTitle(context.getString(R.string.app_name)).setContentText(message)
            .setContentIntent(pIntent).build();

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    noti.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, noti);
}

From source file:com.teclib.service.NotificationRemoveService.java

public void CustomNotification() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_install_apps);

    Intent intent = new Intent(this, RemoveApplicationActivity.class);

    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setTicker(getString(R.string.removeAsk_string))
            .setOngoing(true).setContentIntent(pIntent).setAutoCancel(true).setContent(remoteViews);

    Notification notificationInstall = builder.build();
    notificationInstall.flags |= Notification.FLAG_AUTO_CANCEL;

    remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_install_apps);

    remoteViews.setTextViewText(R.id.title, getString(R.string.app_name));
    remoteViews.setTextViewText(R.id.text, getString(R.string.removeAsk_string));

    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationmanager.notify(3, builder.build());
}

From source file:com.teclib.service.NotificationGPSActivation.java

public void CustomNotification() {
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.notification_install_apps);

    Intent intent = new Intent(this, ActiveGPSActivity.class);

    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setTicker(getString(R.string.gpsAsk_string)).setOngoing(true)
            .setContentIntent(pIntent).setAutoCancel(true).setContent(remoteViews);

    Notification notificationInstall = builder.build();
    notificationInstall.flags |= Notification.FLAG_AUTO_CANCEL;

    remoteViews.setImageViewResource(R.id.imagenotileft, R.mipmap.ic_notification_install_apps);

    remoteViews.setTextViewText(R.id.title, getString(R.string.app_name));
    remoteViews.setTextViewText(R.id.text, getString(R.string.gpsAsk_string));

    NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationmanager.notify(4, builder.build());

}

From source file:com.molice.oneingdufs.androidpn.Notifier.java

public void notify(String notificationId, String apiKey, String title, String message, String uri) {
    Log.d(LOGTAG, "notify()...");

    Log.d(LOGTAG, "notificationId=" + notificationId);
    Log.d(LOGTAG, "notificationApiKey=" + apiKey);
    Log.d(LOGTAG, "notificationTitle=" + title);
    Log.d(LOGTAG, "notificationMessage=" + message);
    Log.d(LOGTAG, "notificationUri=" + uri);

    if (SettingsActivity.getNotificationEnabled(context)) {
        // Show the toast
        //            if (isNotificationToastEnabled()) {
        //                Toast.makeText(context, message, Toast.LENGTH_LONG).show();
        //            }

        // Notification
        Notification notification = new Notification();
        notification.icon = getNotificationIcon();
        //            notification.defaults = Notification.DEFAULT_LIGHTS;
        if (SettingsActivity.getNotificationSound(context)) {
            notification.defaults |= Notification.DEFAULT_SOUND;
        }// w ww . ja va  2s.c  o m
        if (SettingsActivity.getNotificationVibrate(context)) {
            notification.defaults |= Notification.DEFAULT_VIBRATE;
        }
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.when = System.currentTimeMillis();
        notification.tickerText = message;

        //            Intent intent;
        //            if (uri != null
        //                    && uri.length() > 0
        //                    && (uri.startsWith("http:") || uri.startsWith("https:")
        //                            || uri.startsWith("tel:") || uri.startsWith("geo:"))) {
        //                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        //            } else {
        //                String callbackActivityPackageName = sharedPrefs.getString(
        //                        Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, "");
        //                String callbackActivityClassName = sharedPrefs.getString(
        //                        Constants.CALLBACK_ACTIVITY_CLASS_NAME, "");
        //                intent = new Intent().setClassName(callbackActivityPackageName,
        //                        callbackActivityClassName);
        //                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //                intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            }

        Intent intent = new Intent(context, MessageDetailActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        JSONObject data = formatMetaFromTitle(title);
        try {
            data.putOpt("id", notificationId);
            data.putOpt("content", message);
        } catch (Exception e) {
            Log.d("JSON", "Notifier#notify, e=" + e.toString());
        }
        intent.putExtra("data", data.toString());
        intent.putExtra("fromNotification", true);
        //            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //            intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
        //            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
        //            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
        //            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        PendingIntent contentIntent = PendingIntent.getActivity(context, random.nextInt(), intent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        notification.setLatestEventInfo(context, data.optString("title"), message, contentIntent);
        notificationManager.notify(random.nextInt(), notification);

        //            Intent clickIntent = new Intent(
        //                    Constants.ACTION_NOTIFICATION_CLICKED);
        //            clickIntent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        //            clickIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        //            clickIntent.putExtra(Constants.NOTIFICATION_TITLE, title);
        //            clickIntent.putExtra(Constants.NOTIFICATION_MESSAGE, message);
        //            clickIntent.putExtra(Constants.NOTIFICATION_URI, uri);
        //            //        positiveIntent.setData(Uri.parse((new StringBuilder(
        //            //                "notif://notification.adroidpn.org/")).append(apiKey).append(
        //            //                "/").append(System.currentTimeMillis()).toString()));
        //            PendingIntent clickPendingIntent = PendingIntent.getBroadcast(
        //                    context, 0, clickIntent, 0);
        //
        //            notification.setLatestEventInfo(context, title, message,
        //                    clickPendingIntent);
        //
        //            Intent clearIntent = new Intent(
        //                    Constants.ACTION_NOTIFICATION_CLEARED);
        //            clearIntent.putExtra(Constants.NOTIFICATION_ID, notificationId);
        //            clearIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey);
        //            //        negativeIntent.setData(Uri.parse((new StringBuilder(
        //            //                "notif://notification.adroidpn.org/")).append(apiKey).append(
        //            //                "/").append(System.currentTimeMillis()).toString()));
        //            PendingIntent clearPendingIntent = PendingIntent.getBroadcast(
        //                    context, 0, clearIntent, 0);
        //            notification.deleteIntent = clearPendingIntent;
        //
        //            notificationManager.notify(random.nextInt(), notification);

    } else {
        Log.w(LOGTAG, "Notificaitons disabled.");
    }
}