List of usage examples for android.app TaskStackBuilder getPendingIntent
public PendingIntent getPendingIntent(int requestCode, @PendingIntent.Flags int flags)
From source file:com.hmatalonga.greenhub.util.Notifier.java
public static void startStatusBar(final Context context) { if (isStatusBarShown) return;//from ww w. j a va 2 s . c om // 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.matze5800.paupdater.Functions.java
public static void Notify(Context context, String text) { Log.i("notify", text); Notification.Builder nBuilder; nBuilder = new Notification.Builder(context); Intent resultIntent = new Intent(context, Cancel.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(Cancel.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); nBuilder.setContentIntent(resultPendingIntent); nBuilder.setSmallIcon(R.drawable.ic_launcher); nBuilder.setContentTitle("PA Updater"); nBuilder.setContentText(text);/*from w w w . j a v a2 s . c om*/ nBuilder.setAutoCancel(false); nBuilder.setOngoing(true); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(1, nBuilder.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 ww. j a v a2 s . co m // 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:dev.ukanth.ufirewall.InterfaceTracker.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) private static void errorNotification(Context ctx) { NotificationManager mNotificationManager = (NotificationManager) ctx .getSystemService(Context.NOTIFICATION_SERVICE); // Artificial stack so that navigating backward leads back to the Home screen TaskStackBuilder stackBuilder = TaskStackBuilder.create(ctx).addParentStack(MainActivity.class) .addNextIntent(new Intent(ctx, MainActivity.class)); Notification notification = new NotificationCompat.Builder(ctx) .setContentTitle(ctx.getString(R.string.error_notification_title)) .setContentText(ctx.getString(R.string.error_notification_text)) .setTicker(ctx.getString(R.string.error_notification_ticker)) .setSmallIcon(R.drawable.notification_warn).setAutoCancel(true) .setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)).build(); mNotificationManager.notify(ERROR_NOTIFICATION_ID, notification); }
From source file:com.polkapolka.bluetooth.le.DeviceControlActivity.java
public static void showNotificationInMenu(Context context) { // variables/*from ww w .j a v a2 s .c o m*/ long currentTime = System.currentTimeMillis(); // guard: check if we should wait if (currentTime - lastNotificationTime < NOTIFICATION_DELAY) { return; } lastNotificationTime = currentTime; NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setContentTitle(context.getString(R.string.NotifationTitle)) .setContentText(context.getString(R.string.NotificationSubtitle)) .setTicker(context.getString(R.string.BadPostureTicker)).setSmallIcon(R.drawable.icon); // Define that we have the intention of opening MoreInfoNotification Intent moreInfoIntent = new Intent(context, userActivity.class); // Used to stack tasks across activites so we go to the proper place when back is clicked TaskStackBuilder tStackBuilder = TaskStackBuilder.create(context); // Add all parents of this activity to the stack tStackBuilder.addParentStack(DeviceControlActivity.class); // Add our new Intent to the stack tStackBuilder.addNextIntent(moreInfoIntent); // default_all -> vibrate light and sound DEFAULT_VIBRATE -> only vibration even with sound on. notificationBuilder.setDefaults(Notification.DEFAULT_ALL); notificationBuilder.setAutoCancel(true); // Define an Intent and an action to perform with it by another application // FLAG_UPDATE_CURRENT : If the intent exists keep it but update it if needed PendingIntent pendingIntent = tStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Defines the Intent to fire when the notification is clicked notificationBuilder.setContentIntent(pendingIntent); // Gets a NotificationManager which is used to notify the user of the background event NotificationManager notificationManager; notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // Post the notification notificationManager.notify(notifID, notificationBuilder.build()); }
From source file:com.luan.thermospy.android.core.NotificationHandler.java
private NotificationCompat.Builder createBuilder(Context c, String temperature, boolean playSound) { String text = "Current temperature is " + temperature; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c) .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true).setContentTitle("Thermospy") .setContentText(text).setOnlyAlertOnce(false) .setSmallIcon(R.drawable.ic_stat_action_assignment_late); Uri alarmSound = null;/*from w ww . ja v a 2 s .c om*/ if (playSound) { alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } mBuilder.setSound(alarmSound); Intent resultIntent = new Intent(c, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(c); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); return mBuilder; }
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 . j a v a 2 s. c om*/ 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:com.pwcgarage.ibeaconref.BeaconReferenceApplication.java
private void sendNotification(Region region) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)) .setContentText(/*from ww w. j a v a 2 s .c o m*/ getResources().getString(R.string.notification_entered_region, region.getUniqueId())) .setSmallIcon(R.drawable.ic_stat_ic_action_location_found); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addNextIntent(new Intent(this, MonitoringActivity.class)); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, builder.build()); }
From source file:com.lambdasoup.quickfit.persist.FitApiFailureResolutionService.java
private void handleErrorInBackground(ConnectionResult connectionResult, int startId) { if (!connectionResult.hasResolution()) { // Show the localized error notification GoogleApiAvailability.getInstance().showErrorNotification(this, connectionResult.getErrorCode()); return;// w ww . j a v a 2s . co m } // The failure has a resolution. Resolve it. // Called typically when the app is not yet authorized, and an // authorization dialog is displayed to the user. Intent resultIntent = new Intent(this, WorkoutListActivity.class); resultIntent.putExtra(WorkoutListActivity.EXTRA_PLAY_API_CONNECT_RESULT, connectionResult); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(WorkoutListActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.permission_needed_play_service_title)) .setContentText(getResources().getString(R.string.permission_needed_play_service)) .setSmallIcon(R.drawable.common_ic_googleplayservices).setContentIntent(resultPendingIntent) .setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notificationBuilder.setCategory(Notification.CATEGORY_ERROR); } ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)) .notify(Constants.NOTIFICATION_PLAY_INTERACTION, notificationBuilder.build()); stopSelfResult(startId); }
From source file:com.conceptberria.wattion.background.MakeNotification.java
/** * Para versiones mas alta que JellyBean genera un intent aadiendo en la pila de tareas la actividad {@link ViewPrice} * @return el intent/*w ww . j a va 2 s . c o m*/ */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) private PendingIntent getPendingIntentWithStackBuilder() { Intent resultIntent = new Intent(this, ViewPrice.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(ViewPrice.class); stackBuilder.addNextIntent(resultIntent); return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); }