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:Main.java

public static void notify(Context context, int id, String title, String detail) {
    Notification notification = new NotificationCompat.Builder(context).setContentTitle(title).setTicker(detail)
            .setContentText(detail).setDefaults(Notification.DEFAULT_ALL)
            .setSmallIcon(android.R.drawable.ic_dialog_alert)
            .setLargeIcon(//  w w  w  . java  2 s  . c o  m
                    BitmapFactory.decodeResource(context.getResources(), android.R.drawable.ic_dialog_alert))
            .build();
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(id, notification);
}

From source file:Main.java

public static void showNotification(long id, String titleString, String messageString, int iconResId,
        Context context, Class<?> className) {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setSmallIcon(iconResId)
            .setContentTitle(titleString).setStyle(new NotificationCompat.BigTextStyle().bigText(messageString))
            .setContentText(messageString);
    Intent intent = new Intent(context, className);
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addParentStack(className);
    stackBuilder.addNextIntent(intent);/*from w w  w. j  av  a2  s  .  c  o m*/
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    mBuilder.setContentIntent(resultPendingIntent);
    mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = mBuilder.build();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify((int) id, notification);
}

From source file:gcm.GcmMessageHandler.java

private void createNotification(String title, String body) {
    Context context = getBaseContext();

    int defaults = 0;
    defaults = defaults | Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE
            | Notification.DEFAULT_SOUND | Notification.FLAG_AUTO_CANCEL;

    Intent notificationIntent = new Intent(context, ConversationActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIndent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setContentText(body)
            .setDefaults(defaults).setStyle(new NotificationCompat.BigTextStyle().bigText(body))
            .setContentIntent(contentIndent).setAutoCancel(true);
    NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}

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

@SuppressWarnings("deprecation")
public void showNotification(Context context, String title, String subtitle, String authority, int icon) {
    mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notification = new Notification(icon, title, System.currentTimeMillis());
    if (notificationIntent != null) {
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.setLatestEventInfo(context, title, subtitle, pendingIntent);
    }// w  ww . j a  va  2 s  .c o m
    mNotifyManager.notify(0, notification);
}

From source file:com.codemobiles.util.CMNotification.java

public static void notify(final Context ctx, final int iconResID, final String remote_image_url,
        final String title, final String desc, final Class<?> receiver) {
    final Handler handler = new Handler();
    new Thread(new Runnable() {

        @Override//from  w w w  .  j  av  a  2s. c  om
        public void run() {
            try {
                remote_picture = BitmapFactory
                        .decodeStream((InputStream) new URL(remote_image_url).getContent());
                // remote_picture = BitmapFactory.decodeResource(ctx.getResources(), R.drawable.ic_launcher);
            } catch (IOException e) {
                e.printStackTrace();
            }

            handler.post(new Runnable() {

                @Override
                public void run() {
                    // TODO Auto-generated method stub
                    mNotificationManager = (NotificationManager) ctx
                            .getSystemService(Context.NOTIFICATION_SERVICE);

                    Notification noti = setNormalNotification(ctx, iconResID, remote_picture, title, desc,
                            receiver);
                    // Notification noti = setBigTextStyleNotification(ctx);
                    noti.defaults |= Notification.DEFAULT_LIGHTS;
                    noti.defaults |= Notification.DEFAULT_VIBRATE;
                    noti.defaults |= Notification.DEFAULT_SOUND;
                    noti.defaults |= Notification.FLAG_AUTO_CANCEL;
                    noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE;

                    final int notificationID = new Random().nextInt();
                    noti.when = System.currentTimeMillis() + 1000 * 60;
                    mNotificationManager.notify(notificationID, noti);
                }
            });

        }
    }).start();

}

From source file:org.hansel.myAlert.StopScheduleActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
    am.cancel(Util.getReminderPendingIntennt(getApplicationContext()));
    PreferenciasHancel.setAlarmStartDate(getApplicationContext(), 0);
    //ya se termino el tiempo de la programacin cancelamos alarma y salimos
    Log.v("Fin de la programacin");
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Rastreo Finalizado")
            .setContentText("Gracias por usar Hancel");

    Notification notif = mBuilder.build();
    notif.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationManager.notify(0, notif);
    finish();/*from  w  ww .  j av  a  2s  .c  o  m*/
    return;
}

From source file:com.mattermost.gcm.GcmMessageHandler.java

private void createNotification(boolean doAlert) {
    Context context = getBaseContext();

    int defaults = 0;
    defaults = defaults | Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;

    if (doAlert) {
        defaults = defaults | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;
    }//from ww w.  j  ava2  s.com

    Intent notificationIntent = new Intent(context, SplashScreenActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent contentIndent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    PendingIntent deleteIntent = PendingIntent.getBroadcast(context, 0,
            new Intent(context, NotificationDismissReceiver.class), 0);

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

    if (channelIdToNotification.size() == 0) {
        mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID);
        return;
    }

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.mipmap.ic_launcher).setGroup(GROUP_KEY_MESSAGES).setDefaults(defaults)
            .setContentIntent(contentIndent).setDeleteIntent(deleteIntent).setAutoCancel(true);

    if (channelIdToNotification.size() == 1) {
        Bundle data = channelIdToNotification.entrySet().iterator().next().getValue();
        String body = data.getString("message");
        mBuilder.setContentTitle("Mattermost").setContentText(body)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(body));
    } else {
        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

        String summaryTitle = String.format("Mattermost (%d)", channelIdToNotification.size());
        mBuilder.setContentTitle(summaryTitle);

        for (Bundle data : channelIdToNotification.values()) {
            style.addLine(data.getString("message"));
        }

        style.setBigContentTitle(summaryTitle);
        mBuilder.setStyle(style);
    }

    mNotificationManager.cancel(MESSAGE_NOTIFICATION_ID);
    mNotificationManager.notify(MESSAGE_NOTIFICATION_ID, mBuilder.build());
}

From source file:ti.modules.titanium.android.notificationmanager.NotificationProxy.java

public NotificationProxy() {
    super();//from www.  jav  a2  s. c o  m
    notificationBuilder = new NotificationCompat.Builder(TiApplication.getInstance().getApplicationContext())
            .setSmallIcon(android.R.drawable.stat_sys_warning).setWhen(System.currentTimeMillis());

    //set up default values
    flags = Notification.FLAG_AUTO_CANCEL;
    audioStreamType = Notification.STREAM_DEFAULT;
}

From source file:de.incoherent.suseconferenceclient.app.AlarmReceiver.java

@SuppressWarnings({ "deprecation" })
@Override/*  w  w w  .  java2 s.c  om*/
public void onReceive(Context context, Intent intent) {
    Intent notificationIntent = new Intent(context, HomeActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    String title = intent.getStringExtra("title");
    String room = intent.getStringExtra("room");
    String time = intent.getStringExtra("timetext");
    String message = time + ", " + room;

    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = context.getResources().getColor(R.color.dark_suse_green);
    notification.ledOffMS = 1000;
    notification.ledOnMS = 300;
    notification.setLatestEventInfo(context, title, message, contentIntent);
    manager.notify(13572, notification);
}

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

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

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

    builder.setWhen(System.currentTimeMillis());
    Notification notification = null;
    if (ServiceUtil.isNoPrompt(System.currentTimeMillis())) {
        notification = builder.build();
        notification.flags = Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONLY_ALERT_ONCE;
        notification.sound = null;
    } else {
        builder.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + rawId));
        notification = builder.build();
        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);

}