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.teclib.service.NotificationPasswordPolicies.java

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

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

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_white_stork).setOngoing(true)
            .setTicker(getString(R.string.passwordPoliciesNotification_string)).setContentIntent(pIntent)
            .setContent(remoteViews);//from w  ww  .j  ava 2  s  .  c  om

    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.passwordPoliciesNotification_string));

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

}

From source file:net.bither.util.SystemUtil.java

public static void nmNotifyDefault(NotificationManager nm, Context context, int notifyId, Intent intent,
        String title, String contentText, int iconId) {
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setSmallIcon(iconId);/*from   w  ww  .j a v a  2  s  .  c om*/
    builder.setContentText(contentText);
    builder.setContentTitle(title);

    builder.setContentIntent(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT));

    builder.setWhen(System.currentTimeMillis());
    Notification notification = null;

    notification = builder.build();
    notification.defaults = Notification.DEFAULT_SOUND;
    notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0xFF84E4FA;
    notification.ledOnMS = 3000;
    notification.ledOffMS = 2000;
    nm.notify(notifyId, notification);

}

From source file:org.totschnig.myexpenses.service.AutoBackupService.java

@Override
protected void doWakefulWork(Intent intent) {
    String action = intent.getAction();
    if (ACTION_AUTO_BACKUP.equals(action)) {
        Log.i("DEBUG", "now doing backup");
        Result result = GenericTask.doBackup();
        String notifTitle = Utils.concatResStrings(this, " ", R.string.app_name,
                R.string.contrib_feature_auto_backup_label);
        if (result.success) {
            int remaining = ContribFeature.AUTO_BACKUP.recordUsage();
            if (remaining < 1) {
                CharSequence content = TextUtils.concat(getText(R.string.warning_auto_backup_limit_reached),
                        " ", ContribFeature.AUTO_BACKUP.buildRemoveLimitation(this, true));
                Intent contribIntent = new Intent(this, ContribInfoDialogActivity.class);
                contribIntent.putExtra(ContribInfoDialogActivity.KEY_FEATURE, ContribFeature.AUTO_BACKUP);
                NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_home_dark).setContentTitle(notifTitle)
                        .setContentText(content)
                        .setContentIntent(PendingIntent.getActivity(this, 0, contribIntent,
                                PendingIntent.FLAG_CANCEL_CURRENT))
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(content));
                Notification notification = builder.build();
                notification.flags = Notification.FLAG_AUTO_CANCEL;
                ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification);
            }/*from w  w w  . j a  v a 2  s  .  com*/
        } else {
            String content = result.print(this);
            Intent preferenceIntent = new Intent(this, MyPreferenceActivity.class);
            preferenceIntent.putExtra(MyPreferenceActivity.KEY_OPEN_PREF_KEY, PrefKey.APP_DIR.getKey());
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_home_dark).setContentTitle(notifTitle).setContentText(content)
                    .setContentIntent(PendingIntent.getActivity(this, 0, preferenceIntent,
                            PendingIntent.FLAG_CANCEL_CURRENT))
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(content));
            Notification notification = builder.build();
            notification.flags = Notification.FLAG_AUTO_CANCEL;
            ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification);
        }
    } else if (ACTION_SCHEDULE_AUTO_BACKUP.equals(action)) {
        DailyAutoBackupScheduler.updateAutoBackupAlarms(this);
    }
}

From source file:de.dev.eth0.rssreader.app.util.NotificationManagerImpl.java

@Override
public void sendFeedUpdatedNotification(List<FeedEntry> newFeeds) {
    Timber.d("sendFeedUpdatedNotifications %d", newFeeds.size());
    if (isNotificationDisabled() || newFeeds.isEmpty()) {
        return;/*from   w w  w.  j av  a2s.  com*/
    }
    android.app.NotificationManager notificationManager = (android.app.NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.icon_empty_18dp)
            .setContentTitle(context.getString(R.string.notification_title))
            .setContentText(context.getString(R.string.notification_text, newFeeds.size()));

    if (newFeeds.size() > 1) {
        NotificationCompat.InboxStyle extended = new NotificationCompat.InboxStyle();
        extended.setBigContentTitle(context.getString(R.string.notification_title_extended));
        for (FeedEntry summary : newFeeds) {
            extended.addLine(summary.getMetadata().getTitle());
        }
        builder.setStyle(extended);
    }

    Intent resultIntent = new Intent(context, MainActivity.class);
    if (newFeeds.size() == 1) {
        builder.setContentText(newFeeds.get(0).getMetadata().getTitle());
        resultIntent.putExtra(FeedEntryTable.COLUMN_ID, newFeeds.get(0).getMetadata().getId());
    }
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addNextIntentWithParentStack(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(resultPendingIntent);

    builder.setAutoCancel(true);
    Notification notification = builder.build();
    notification.flags = Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(ID_NEW_FEEDS, notification);
}

From source file:se.kth.ssvl.tslab.wsn.service.bpf.ActionReceiver.java

@Override
public void notify(String header, String description) {
    PendingIntent resultPendingIntent = PendingIntent.getActivity(mContext, 0,
            new Intent(mContext, se.kth.ssvl.tslab.wsn.app.StatisticsActivity.class),
            PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mContext)
            .setSmallIcon(se.kth.ssvl.tslab.wsn.R.drawable.ic_stat_notify).setContentTitle(header)
            .setContentText(description).setContentIntent(resultPendingIntent).setTicker(header);

    Notification notification = mBuilder.build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    mNotificationManager.notify((appId++ % 5), notification);

}

From source file:com.ubikod.urbantag.NotificationHelper.java

/**
 * Notify a new content(place or event)/* w  w  w  .j  a v  a2  s. c  o  m*/
 * @param contentId Id of content
 * @param content Content name
 * @param placeName Place name it will happend
 * @param type type of notification
 */
private void notify(int contentId, String content, String placeName, int type) {

    String title = content;
    String text = placeName;
    int icon = content_icon;
    if (type == NEW_PLACE_NOTIF) {
        title = placeName;
        text = mContext.getResources().getString(R.string.new_place);
        icon = place_icon;
    }
    /* Modify intent to transmit id */
    Intent intent;
    intent = new Intent(mContext, ContentViewerActivity.class);
    intent.putExtra(ContentViewerActivity.CONTENT_ID, contentId);

    /* Add the from notification extra info and create the pending intent */
    intent.putExtra(FROM_NOTIFICATION, type);
    PendingIntent activity = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    /* Create notification */
    Notification newNotification = new NotificationCompat.Builder(mContext).setSmallIcon(icon)
            .setContentText(text).setContentTitle(title).setContentIntent(activity).setTicker(title)
            .getNotification();

    // newNotification.contentView = contentView;
    newNotification.flags |= Notification.FLAG_AUTO_CANCEL;
    newNotification.defaults |= Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;

    /* notify */
    mNotificationManager.notify(type, newNotification);
}

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

public void testPostNotification() {
    notifier.postNotification();//  w w w .  j a  va2s  . co m

    Mockito.verify(mockNotificationManager).notify(Mockito.eq(NOTIFICATION_ID),
            Mockito.argThat(new BaseMatcher<Notification>() {
                @Override
                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_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 and set to auto cancel");
                }
            }));
}

From source file:com.eyc.statusBarNotification.StatusBarNotification.java

/**
 * Helper method that returns a flag value to be used for notification
 * by default it will return 16 representing FLAG_NO_CLEAR
 * /*  ww w .  ja  v  a 2s  .  co m*/
 * @param flag
 * @return int value of the flag
 */
private int getFlagValue(String flag) {
    int flagVal = Notification.FLAG_AUTO_CANCEL;

    // We trust the flag value as it comes from our JS constant.
    // This is also backwards compatible as it will be emtpy.
    if (!flag.isEmpty()) {
        flagVal = Integer.parseInt(flag);
    }

    return flagVal;
}

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

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

    Intent intent = new Intent(this, MQTTNotifierActivity.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.installAsk_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.installAsk_string));

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

}

From source file:org.liberty.android.fantastischmemo.service.AnyMemoService.java

@SuppressWarnings("deprecation")
private void showNotification() {
    try {//from  w ww .j ava 2s.  co  m
        DatabaseInfo dbInfo = new DatabaseInfo(this);
        if (dbInfo.getRevCount() < 10) {
            return;
        }
        Intent myIntent = new Intent(this, AnyMemo.class);
        myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        NotificationManager notificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Notification notification = new Notification(R.drawable.anymemo_notification_icon,
                getString(R.string.app_name), System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        PendingIntent pIntent = PendingIntent.getActivity(this, NOTIFICATION_REQ, myIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);
        notification.setLatestEventInfo(this, dbInfo.getDbName(),
                getString(R.string.stat_scheduled) + " " + dbInfo.getRevCount(), pIntent);

        notificationManager.notify(NOTIFICATION_ID, notification);
        Log.v(TAG, "Notification Invoked!");
    } catch (Exception e) {
        /* Do not show notification when AnyMemo can not
         * fetch the into
         */
    }
}