List of usage examples for android.app TaskStackBuilder create
public static TaskStackBuilder create(Context context)
From source file:io.northernlights.logcleaner.Notifier.java
public static void showNotification(String title, String text, Context context) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(title).setContentText(text); Intent resultIntent = new Intent(context, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(0, mBuilder.build()); }
From source file:com.jackie.notifyingUser.ResultActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_result); getSupportActionBar().setDisplayHomeAsUpEnabled(true); Intent resultIntent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(resultIntent); // Gets a PendingIntent containing the entire back stack PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Sets an ID for the notification, so it can be updated NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentIntent(pendingIntent); builder.setContentTitle("Now Result Activity"); builder.setContentText("in Main Activity"); builder.setSmallIcon(R.mipmap.ic_launcher); builder.setProgress(100, 20, true);//from w w w.jav a 2s .c o m int numMessages = 0; builder.setNumber(numMessages); // Because the ID remains unchanged, the existing notification is updated. notificationManager.notify(CommonConstants.NOTIFICATION_ID, builder.build()); }
From source file:io.digibyte.tools.manager.BRNotificationManager.java
public static void sendNotification(Context ctx, int icon, String title, String message, int mId) { if (ctx == null) return;//from w w w .ja v a 2s . c om android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx) .setSmallIcon(icon).setContentTitle(title).setContentText(message); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(ctx, BreadActivity.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(ctx); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(BreadActivity.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) ctx .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(mId, mBuilder.build()); }
From source file:com.breadwallet.tools.manager.BRNotificationManager.java
public static void sendNotification(Activity ctx, int icon, String title, String message, int mId) { if (ctx == null) return;//from w w w.j av a 2 s . c o m android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx) .setSmallIcon(icon).setContentTitle(title).setContentText(message); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(ctx, 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(ctx); // 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) ctx .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(mId, mBuilder.build()); }
From source file:hmatalonga.greenhub.util.Notifier.java
public static void startStatusBar(final Context context) { if (isStatusBarShown) return;/*from w w w .j av a 2 s . c o m*/ // At this moment Inspector still doesn't have a current level assigned DataEstimator estimator = new DataEstimator(); estimator.getCurrentStatus(context); int now = Battery.getBatteryCurrentNow(context); int level = estimator.getLevel(); String title = "Now: " + now + " mA"; String text = "GreenHub is running"; sBuilder = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(text) .setAutoCancel(false).setOngoing(true) .setPriority(SettingsUtils.fetchNotificationsPriority(context)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { sBuilder.setVisibility(Notification.VISIBILITY_PUBLIC); } if (level < 100) { sBuilder.setSmallIcon(R.drawable.ic_stat_00_pct_charged + level); } else { sBuilder.setSmallIcon(R.drawable.ic_stat_z100_pct_charged); } // 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(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); sBuilder.setContentIntent(resultPendingIntent); sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. sNotificationManager.notify(Config.NOTIFICATION_BATTERY_STATUS, sBuilder.build()); isStatusBarShown = true; }
From source file:com.hmatalonga.greenhub.util.Notifier.java
public static void startStatusBar(final Context context) { if (isStatusBarShown) return;/* w w w .j a va2s .c o m*/ // At this moment Inspector still doesn't have a current level assigned DataEstimator estimator = new DataEstimator(); estimator.getCurrentStatus(context); int now = Battery.getBatteryCurrentNow(context); int level = estimator.getLevel(); String title = context.getString(R.string.now) + ": " + now + " mA"; String text = context.getString(R.string.notif_batteryhub_running); sBuilder = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(text) .setAutoCancel(false).setOngoing(true) .setPriority(SettingsUtils.fetchNotificationsPriority(context)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { sBuilder.setVisibility(Notification.VISIBILITY_PUBLIC); } if (level < 100) { sBuilder.setSmallIcon(R.drawable.ic_stat_00_pct_charged + level); } else { sBuilder.setSmallIcon(R.drawable.ic_stat_z100_pct_charged); } // 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(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); sBuilder.setContentIntent(resultPendingIntent); sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. sNotificationManager.notify(Config.NOTIFICATION_BATTERY_STATUS, sBuilder.build()); isStatusBarShown = true; }
From source file:com.codemobiles.util.CMNotification.java
public static Notification setNormalNotification(Context ctx, int iconResID, Bitmap remote_picture, String title, String desc, Class<?> receiver) { // Setup an explicit intent for an SuccessActivity to receive. Intent resultIntent = new Intent(ctx, receiver); // TaskStackBuilder ensures that the back button follows the recommended // convention for the back key. TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx); // Adds the back stack for the Intent (but not the Intent itself). stackBuilder.addParentStack(receiver); // 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); return new NotificationCompat.Builder(ctx).setSmallIcon(iconResID).setAutoCancel(true) .setLargeIcon(remote_picture).setContentIntent(resultPendingIntent).setContentTitle(title) .setContentText(desc).build(); }
From source file:com.hkm.taxicallandroid.schema.ConfirmCall.java
private void generate_notification(final CallPanel ctx) { final NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx) .setSmallIcon(R.drawable.ic_talkrequirements).setContentTitle("Incoming Taxi").setContentText(String .format(content_f, incoming_driver_data.getLicense(), incoming_driver_data.getEstTime())); // Creates an explicit intent for an Activity in your app final Intent resultIntent = new Intent(ctx, CallPanel.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(ctx); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(CallPanel.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) ctx .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(39939, mBuilder.build()); }
From source file:com.android.talkbacktests.testsession.NotificationTest.java
private void showSimpleNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(getContext()) .setSmallIcon(android.R.drawable.ic_notification_overlay).setAutoCancel(true) .setContentTitle(getString(R.string.normal_notification_title)) .setContentText(getString(R.string.normal_notification_text)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); TaskStackBuilder stackBuilder = TaskStackBuilder.create(getContext()); stackBuilder.addParentStack(MainActivity.class); Intent resultIntent = new Intent(getContext(), MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) getContext() .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID_MAIN_MENU, builder.build()); }
From source file:nabhack.localz.receiver.GcmBroadcastReceiver.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx) .setSmallIcon(R.drawable.ic_stat_localz).setContentTitle("New Localz deal!!!") .setContentText("You have new deal from Localz!!!").setAutoCancel(true); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(ctx, DealSummaryActivity_.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(ctx); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(DealSummaryActivity_.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); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); // And notify DealOfTheDayActivity if it is on the foreground Intent intent = new Intent(); intent.setAction("nabhack.localz"); intent.putExtra("Message", msg); ctx.sendBroadcast(intent);/*w ww . ja va 2 s.co m*/ }