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.mowares.massagerexpressclient.GCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *///  www . j  ava 2 s.c o m

private void generateNotification(Context context, String message) {
    // System.out.println("this is message " + message);
    // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + message);
    int icon = R.drawable.ic_launcher;
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(icon, message, when);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, MainDrawerActivity.class);
    notificationIntent.putExtra("fromNotification", "notification");
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    //notification.setLatestEventInfo(context, title, message, intent);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    System.out.println("notification====>" + message);
    notification.defaults |= Notification.DEFAULT_SOUND;
    notification.defaults |= Notification.DEFAULT_VIBRATE;
    // notification.defaults |= Notification.DEFAULT_LIGHTS;
    notification.flags |= Notification.FLAG_SHOW_LIGHTS;
    notification.ledARGB = 0x00000000;
    notification.ledOnMS = 0;
    notification.ledOffMS = 0;
    notificationManager.notify(0, notification);
    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wakeLock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
            "WakeLock");
    wakeLock.acquire();
    wakeLock.release();
}

From source file:com.hedgehog.smdb.ActionBarControlScrollViewActivity.java

private void showNotification() {
    Notification notification = null;
    Intent toLive = new Intent(this, ActionBarControlScrollViewActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), toLive, 0);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        notification = new Notification.Builder(this).setContentTitle("Time to Check the new Show!")
                .setContentInfo("").setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pIntent)
                .setPriority(Notification.PRIORITY_MAX).setDefaults(Notification.DEFAULT_VIBRATE)
                .setAutoCancel(true).setOnlyAlertOnce(true)
                //                    .setTicker("Show running!")
                //                    .addAction(R.mipmap.ic_launcher, "View", pIntent)
                .build();//from   w  ww.  j  a  v  a  2  s.com
    }
    NotificationManager NM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    NM.notify(0, notification);
}

From source file:com.gdglab.iot.gcm.GcmIntentService.java

private void sendNotification(String msg) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, GdglabActivity.class);

    resultIntent.putExtra("msgText", msg);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    //Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(GdglabActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("GCM Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg);
    mBuilder.setContentIntent(resultPendingIntent);

    Notification note = mBuilder.build();

    note.flags |= Notification.FLAG_AUTO_CANCEL;

    mNotificationManager.notify(NOTIFICATION_ID, note);
}

From source file:ro.softronic.mihai.ro.papamia.Services.MyFirebaseMessagingService.java

/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 *//*from   ww w  .ja v a  2  s . c o  m*/
private void sendNotification(NotificationData notificationData) {

    //        Intent intent = new Intent(this, CategoriiActivity.class);
    Intent intent = new Intent().setClass(this, CategoriiActivity.class);
    //        intent.putExtra(NotificationData.TEXT, notificationData.getTextMessage());
    intent.putExtra("flag", 1);
    //        intent.setAction(Intent.ACTION_SEARCH);
    ////        intent.addCategory(Intent.CATEGORY_LAUNCHER);
    //
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    //        intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder notificationBuilder = null;
    try {

        notificationBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.ic_launcher)
                //                    .setContentTitle(URLDecoder.decode("aslkas", "UTF-8"))
                .setContentText(URLDecoder.decode("alskalsk", "UTF-8"))
                //                    .setAutoCancel(true)
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))

                .setContentIntent(pendingIntent).addAction(R.drawable.arrows_right_icon, "Call", pendingIntent);

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    if (notificationBuilder != null) {
        NotificationManager notificationManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);
        Notification noti = notificationBuilder.build();
        noti.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL;
        notificationManager.notify(0, noti);
    } else {
        Log.d(TAG, "No foi possvel criar objeto notificationBuilder");
    }
}

From source file:net.frygo.findmybuddy.GCMIntentService.java

private static void generateAcceptfriendNotification(Context context, String message, String status) {

    Random rand = new Random();
    int x = rand.nextInt();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    String title = context.getString(R.string.app_name);
    Intent notificationIntent = new Intent(context, customlistview.class);
    if (status.equalsIgnoreCase("accept"))
        message = message + " added you as buddy";
    else/*from  ww  w.  ja  v  a  2  s.  co m*/
        message = message + " rejected you as buddy";
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT);

    Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis());
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notification.setLatestEventInfo(context, title, message, intent);
    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(x, notification);

    PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
    final PowerManager.WakeLock mWakelock = pm
            .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title);
    mWakelock.acquire();

    // Timer before putting Android Device to sleep mode.
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
        public void run() {
            mWakelock.release();
        }
    };
    timer.schedule(task, 5000);

}

From source file:com.ph1ash.dexter.beeplepaper.BeeplePaperService.java

protected void displayLoginNotification() {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.common_full_open_on_phone).setContentTitle("BeeplePaper - Verify Login")
            .setContentText("Verify your Facebook login for to allow BeeplePaper to update.");

    Intent resultIntent = new Intent(this, MainActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addParentStack(MainActivity.class);

    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT);
    mBuilder.setContentIntent(resultPendingIntent);
    Notification notif = mBuilder.build();
    notif.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, notif);
}

From source file:fr.RivaMedia.alertes.GcmIntentService.java

private void sendNotification(String titre, String message) {
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

    //TODO: remplir
    //Intent de lancement
    Intent lancement = new Intent(this, SplashScreenActivity.class);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, lancement, 0);

    Bitmap large_100 = BitmapFactory.decodeResource(getResources(), R.drawable.splash_screen_v2_logo_petit);
    Bitmap large = BitmapFactory.decodeResource(getResources(), R.drawable.splash_screen_v2_logo);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.splash_screen_v2_logo_petit).setLargeIcon(large_100).setContentTitle(titre)
            .setContentText(message)/* w w w  .j  a  v a2s.  co m*/

            .setStyle(new NotificationCompat.BigPictureStyle().setBigContentTitle(titre).setSummaryText(message)
                    .bigPicture(large).bigLargeIcon(large_100));

    mBuilder.setContentIntent(contentIntent);
    Notification notif = mBuilder.build();
    notif.flags |= Notification.FLAG_AUTO_CANCEL;
    mNotificationManager.notify(NOTIFICATION_ID, notif);
}

From source file:com.google.android.apps.chrometophone.C2DMReceiver.java

private void generateNotification(Context context, String msg, String title, Intent intent) {
    int icon = R.drawable.status_icon;
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, title, when);
    notification.setLatestEventInfo(context, title, msg, PendingIntent.getActivity(context, 0, intent, 0));
    notification.defaults = Notification.DEFAULT_SOUND;
    notification.flags |= Notification.FLAG_AUTO_CANCEL;

    SharedPreferences settings = Prefs.get(context);
    int notificatonID = settings.getInt("notificationID", 0); // allow multiple notifications

    NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    nm.notify(notificatonID, notification);

    SharedPreferences.Editor editor = settings.edit();
    editor.putInt("notificationID", ++notificatonID % 32);
    editor.commit();//from www  .j  a va 2 s .  c  o m
}

From source file:com.cloverstudio.spika.GCMIntentService.java

@SuppressWarnings("deprecation")
public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras) {

    if (fromName != null) {
        final NotificationManager notificationManager = (NotificationManager) getSystemService(
                NOTIFICATION_SERVICE);/*from  www  .j  ava  2s. co  m*/
        Notification notification = new Notification(R.drawable.icon_notification, message,
                System.currentTimeMillis());
        notification.number = mNotificationCounter + 1;
        mNotificationCounter = mNotificationCounter + 1;

        Intent intent = new Intent(this, SplashScreenActivity.class);
        intent.replaceExtras(pushExtras);
        intent.putExtra(Const.PUSH_INTENT, true);
        intent.setAction(Long.toString(System.currentTimeMillis()));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND
                | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notification.setLatestEventInfo(this, context.getString(R.string.app_name), message, pendingIntent);
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        String notificationId = Double.toString(Math.random());
        notificationManager.notify(notificationId, 0, notification);
    }
}

From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.SystemMonitor.java

private int systemNotice() {
    int t = START_STICKY;
    Log.e(SystemMonitor.class.getSimpleName(), "call me redundant BABY!  onStartCommand service");

    int myID = android.os.Process.myPid();
    // The intent to launch when the user clicks the expanded notification
    Intent intent = new Intent(this, MyHealthHubWithFragments.class);
    // Intent intent = new Intent();
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

    Notification notice = new Notification.Builder(getApplicationContext()).setSmallIcon(R.drawable.ic_launcher)
            .setWhen(System.currentTimeMillis()).setContentTitle(getPackageName())
            .setContentText("System Monitor running").setContentIntent(pendIntent).getNotification();

    notice.flags |= Notification.FLAG_AUTO_CANCEL;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(myID, notice);

    return t;/*from   w  ww  .  ja  va2 s .  c o  m*/
}