List of usage examples for android.app TaskStackBuilder create
public static TaskStackBuilder create(Context context)
From source file:com.abhijitvalluri.android.fitnotifications.setup.AppIntroActivity.java
private void addDemoSlide() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); final boolean dismissPlaceholderNotif = preferences .getBoolean(getString(R.string.dismiss_placeholder_notif_key), false); final int placeholderNotifDismissDelayMillis = preferences .getInt(getString(R.string.placeholder_dismiss_delay_key), Constants.DEFAULT_DELAY_SECONDS) * 1000; final Handler handler = new Handler(); // Demo//from w w w . j av a 2 s. c o m addSlide(new SimpleSlide.Builder().layout(R.layout.fragment_intro).title(R.string.intro_done_title) .description(R.string.intro_done_desc).image(R.drawable.intro_done).background(R.color.colorAccent) .backgroundDark(R.color.colorAccentDark).buttonCtaLabel(R.string.test_notification) .buttonCtaClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bundle newExtra = new Bundle(); NotificationCompat.Builder builder = new NotificationCompat.Builder(AppIntroActivity.this); String notificationText = "Sample notification subject"; String notificationBigText = "Sample notification body. This is where the details of the notification will be shown."; StringBuilder sb = new StringBuilder(); sb.append("[").append("example").append("] "); sb.append(notificationText); if (notificationBigText.length() > 0) { sb.append(" -- ").append(notificationBigText); } RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification); contentView.setTextViewText(R.id.customNotificationText, getString(R.string.placeholder_notification_text)); builder.setSmallIcon(R.drawable.ic_sms_white_24dp).setContentText(sb.toString()) .setExtras(newExtra).setContentTitle("Sample Notification Title") .setContent(contentView); // Creates an explicit intent for the SettingsActivity in the app Intent settingsIntent = new Intent(AppIntroActivity.this, SettingsActivity.class); // 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 // the application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(AppIntroActivity.this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(SettingsActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(settingsIntent); PendingIntent settingsPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(settingsPendingIntent).setAutoCancel(true); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, builder.build()); Toast.makeText(AppIntroActivity.this, getString(R.string.test_notification_sent), Toast.LENGTH_LONG).show(); if (dismissPlaceholderNotif) { handler.postDelayed(new Runnable() { @Override public void run() { ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)) .cancel(NOTIFICATION_ID); } }, placeholderNotifDismissDelayMillis); } } }).build()); }
From source file:com.dogtim.recommendation.MainFragment.java
private PendingIntent buildPendingIntent() { Intent detailsIntent = new Intent(); TaskStackBuilder stackBuilder = TaskStackBuilder.create(getActivity()); stackBuilder.addNextIntent(detailsIntent); return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }
From source file:com.hmatalonga.greenhub.util.Notifier.java
public static void batteryLowAlert(final Context context) { if (sNotificationManager == null) { sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); }// w w w.j ava 2 s. c om NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_alert_circle_white_24dp) .setContentTitle(context.getString(R.string.notif_battery_low)) .setContentText(context.getString(R.string.notif_connect_power)).setAutoCancel(true) .setOngoing(false).setLights(Color.RED, 500, 2000).setVibrate(new long[] { 0, 400, 1000 }) .setPriority(SettingsUtils.fetchNotificationsPriority(context)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC); } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainActivity.class); // 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(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(InboxActivity.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); mBuilder.setContentIntent(resultPendingIntent); // Because the ID remains unchanged, the existing notification is updated. sNotificationManager.notify(Config.NOTIFICATION_BATTERY_LOW, mBuilder.build()); }
From source file:com.PrivacyGuard.Application.Network.FakeVPN.MyVpnService.java
void buildNotification(int notifyId, int frequency, LeakReport leak) { String msg = leak.appName + " is leaking " + leak.category.name() + " information"; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_spam) .setContentTitle(leak.appName).setContentText(msg).setNumber(frequency).setTicker(msg) .setAutoCancel(true);/*from w w w . jav a 2s . c om*/ Intent ignoreIntent = new Intent(this, ActionReceiver.class); ignoreIntent.setAction("Ignore"); ignoreIntent.putExtra("notificationId", notifyId); // use System.currentTimeMillis() to have a unique ID for the pending intent PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), (int) System.currentTimeMillis(), ignoreIntent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.addAction(R.drawable.ic_cancel, "Ignore this kind of leaks", pendingIntent); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, AppSummaryActivity.class); resultIntent.putExtra(PrivacyGuard.EXTRA_PACKAGE_NAME, leak.packageName); resultIntent.putExtra(PrivacyGuard.EXTRA_APP_NAME, leak.appName); resultIntent.putExtra(PrivacyGuard.EXTRA_IGNORE, 0); // 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 home screen TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(AppSummaryActivity.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); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // builds the notification and sends it mNotificationManager.notify(notifyId, mBuilder.build()); }
From source file:com.firescar96.nom.GCMIntentService.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private static void Notify(String notificationTitle, String notificationMessage, Bundle data, int id, boolean annoy) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(thisService) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(notificationTitle) .setContentText(notificationMessage).setAutoCancel(true); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(thisService, MainActivity.class); resultIntent.putExtras(data);// w w w . j a v a 2 s .com // 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(thisService); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainActivity.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); mBuilder.setContentIntent(resultPendingIntent); if (annoy) { Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); long[] pattern = { 50, 100, 10, 100, 10, 200 }; mBuilder.setVibrate(pattern); } NotificationManager mNotificationManager = (NotificationManager) thisService .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(id, mBuilder.build()); }
From source file:org.travey.travey.LocationIntentService.java
public void createNotification() { //create a notification that prompts the user to fill out a form about the trip Log.i("**************", "Notifying"); if (travey.LOG_TO_DATABASE) { logToDatabase("notifying"); }// w w w .j a v a2 s . c om Resources res = getResources(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); mBuilder.setContentTitle(res.getString(R.string.trip_notification_title)); mBuilder.setContentText(res.getString(R.string.trip_notification_body)); mBuilder.setTicker(res.getString(R.string.trip_notification_ticker)); mBuilder.setSmallIcon(R.drawable.ic_traveyd); mBuilder.setAutoCancel(true); //make intent for launching survey if they click on the notification Intent mainIntent = new Intent(this, MainActivity.class); //Pass along trip data (maybe can do this better with Parcelable) mainIntent.putExtra("tab", "surveys"); mainIntent.putExtra("fromNotify", "true"); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(mainIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_ONE_SHOT); mBuilder.setContentIntent(resultPendingIntent); //TESTING TO SEE IF FOLLOWING CAN BE REMOVED ALONG WITH RECEIVER CLASS //make intent for cleaning up if they dismiss the notification Intent dismissIntent = new Intent(this, NotificationDismissedReceiver.class); dismissIntent.putExtra("com.my.app.notificationId", travey.NOTIFY_ID); PendingIntent dismissPendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), travey.NOTIFY_ID, dismissIntent, 0); mBuilder.setDeleteIntent(dismissPendingIntent); //launch the notification NotificationManager myNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); myNotificationManager.notify(0, mBuilder.build()); //handle preferences Log.i("**************", "Setting notification pref to true"); //reset the trip myPrefs = this.getSharedPreferences("myPrefs", MODE_PRIVATE); myPrefsEditor = myPrefs.edit(); currentTrip = null; myPrefsEditor.putBoolean("isNotified", true); myPrefsEditor.commit(); }
From source file:com.hollandhaptics.babyapp.BabyService.java
/** * @param _message The message to show./* ww w . j a va 2 s .com*/ * @brief Makes a notification for the user */ private void notifyUser(String _message) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Baby App").setContentText(_message); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainActivity.class); // 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(MainActivity.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); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. // mId = 0 mNotificationManager.notify(0, mBuilder.build()); }
From source file:com.hmatalonga.greenhub.util.Notifier.java
public static void batteryWarningTemperature(final Context context) { if (sNotificationManager == null) { sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); }// w w w . ja va 2 s .co m NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_alert_circle_white_24dp) .setContentTitle(context.getString(R.string.notif_battery_warning)) .setContentText(context.getString(R.string.notif_battery_warm)).setAutoCancel(true) .setOngoing(false).setLights(Color.YELLOW, 500, 2000).setVibrate(new long[] { 0, 400, 1000 }) .setPriority(SettingsUtils.fetchNotificationsPriority(context)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC); } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.putExtra("tab", 2); // 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(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(InboxActivity.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); mBuilder.setContentIntent(resultPendingIntent); // Because the ID remains unchanged, the existing notification is updated. Notification notification = mBuilder.build(); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; sNotificationManager.notify(Config.NOTIFICATION_TEMPERATURE_WARNING, notification); }
From source file:com.y59song.PrivacyGuard.MyVpnService.java
@Override public void notify(String appName, String msg) { isLocation(appName, msg);/*from w w w . j a v a 2s . c o m*/ boolean ignored = false; if (isIgnored(appName, msg)) { ignored = true; } if (findNotificationId(appName, msg) >= 0) { updateNotification(appName, msg); return; } // ----------------------------------------------------------------------- // Database Entry DatabaseHandler db = new DatabaseHandler(this); db.addLeak(new DataLeak(mId, appName, msg, 1, dateFormat.format(new Date()))); // ----------------------------------------------------------------------- if (ignored) { return; } int notifyId = findNotificationId(appName, msg); int generalNotifyId = findGeneralNotificationId(appName); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.notify) .setContentTitle("Privacy Guard").setTicker(appName + " " + msg) .setContentText(appName + " " + msg); if (DEBUG) Log.i(TAG, msg); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, DetailsActivity.class); List<LocationLeak> leakList = db.getLocationLeaks(appName); resultIntent.putExtra(EXTRA_APP, appName); resultIntent.putExtra(EXTRA_SIZE, String.valueOf(leakList.size())); for (int i = 0; i < leakList.size(); i++) { resultIntent.putExtra(EXTRA_DATA + i, leakList.get(i).getLocation()); // to pass values between activities } // ------------------------------------------------ Intent intent = new Intent(this, ActionReceiver.class); intent.setAction("Ignore"); intent.putExtra("appName", appName); intent.putExtra("notificationId", notifyId); // use System.currentTimeMillis() to have a unique ID for the pending intent PendingIntent pendingIntent = PendingIntent.getBroadcast(this.getApplicationContext(), (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.addAction(R.drawable.ignore, "Ignore", pendingIntent); // ------------------------------------------------ // 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 home screen TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(DetailsActivity.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); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // mId updates the notification later on. mNotificationManager.notify(generalNotifyId, mBuilder.build()); mId++; }
From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java
/** * sends the service notification/*from w w w . j a v a 2 s.co m*/ */ private void handleServiceNotification() { NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //filtering archived notification list List<StatusBarNotification> filteredArchivedNotificationList = baseNotificationFilter .applyFilter(archivedNotificationMap.values(), notificationGroups, true); int filteredArchiveddSize = filteredArchivedNotificationList.size(); //should show notification only if there are notifications to be shown if (filteredArchiveddSize > 0) { NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this); nBuilder.setContentTitle( String.format(getString(R.string.service_notification_text), filteredArchiveddSize)); nBuilder.setSmallIcon(R.drawable.ic_notification); //gets the correct color resource, based on android version if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) nBuilder.setColor(getResources().getColor(R.color.app_background, null)); else //noinspection deprecation nBuilder.setColor(getResources().getColor(R.color.app_background)); //setting the intent Intent resultIntent = new Intent(this, MainActivity.class); //setting the extra containing the archived notifications resultIntent.putExtra(ARCHIVED_NOTIFICATIONS_EXTRA, new HashSet<>(archivedNotificationMap.keySet())); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); nBuilder.setContentIntent(resultPendingIntent); //low priority, not min, as it has to show in the lockscreen nBuilder.setPriority(Notification.PRIORITY_LOW); Notification notification = nBuilder.build(); //this notification should be sticky notification.flags |= Notification.FLAG_NO_CLEAR; nManager.notify(SERVICE_NOTIFICATION, 0, notification); } //else I should remove the notification else nManager.cancel(SERVICE_NOTIFICATION, 0); }