List of usage examples for android.app TaskStackBuilder create
public static TaskStackBuilder create(Context context)
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//from w w w . ja va2 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); }
From source file:com.hmatalonga.greenhub.util.Notifier.java
public static void batteryFullAlert(final Context context) { if (sNotificationManager == null) { sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); }/*from w w w.ja v a 2 s . c o m*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_information_white_24dp) .setContentTitle(context.getString(R.string.notif_battery_full)) .setContentText(context.getString(R.string.notif_remove_charger)).setAutoCancel(true) .setOngoing(false).setLights(Color.GREEN, 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_FULL, mBuilder.build()); }
From source file:ca.zadrox.dota2esportticker.service.ReminderAlarmService.java
private void notifyMatch(long matchId) { if (!PrefUtils.shouldShowMatchReminders(this)) { return;//from w ww . ja v a2 s. com } final ContentResolver cr = getContentResolver(); Cursor c = cr.query(MatchContract.SeriesEntry.CONTENT_URI, MatchDetailQuery.PROJECTION, SESSION_ID_WHERE_CLAUSE, new String[] { String.valueOf(matchId) }, null); if (!c.moveToNext()) { return; } Intent baseIntent = new Intent(this, MatchActivity.class); baseIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); TaskStackBuilder taskBuilder = TaskStackBuilder.create(this).addNextIntent(baseIntent); Intent matchIntent = new Intent(this, MatchDetailActivity.class); matchIntent.putExtra(MatchDetailActivity.ARGS_GG_MATCH_ID, matchId); taskBuilder.addNextIntent(matchIntent); PendingIntent pi = taskBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); final Resources res = getResources(); String contentTitle = c.getString(MatchDetailQuery.TEAM_ONE_NAME) + " vs " + c.getString(MatchDetailQuery.TEAM_TWO_NAME); String contentText; long currentTime = TimeUtils.getUTCTime(); long matchStart = c.getLong(MatchDetailQuery.DATE_TIME); int minutesLeft = (int) (matchStart - currentTime + 59000) / 60000; if (minutesLeft < 2 && minutesLeft >= 0) { minutesLeft = 1; } if (minutesLeft < 0) { contentText = "is scheduled to start now. (" + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")"; } else { contentText = "is scheduled to start in " + minutesLeft + " min. (" + c.getString(MatchDetailQuery.TOURNAMENT_NAME) + ")"; } NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this).setContentTitle(contentTitle) .setContentText(contentText).setColor(res.getColor(R.color.theme_primary)) .setTicker(contentTitle + " is about to start.") .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setLights(NOTIFICATION_ARGB_COLOR, NOTIFICATION_LED_ON_MS, NOTIFICATION_LED_OFF_MS) .setSmallIcon(R.drawable.ic_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_DEFAULT).setAutoCancel(true); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(NOTIFICATION_ID, notifBuilder.build()); }
From source file:org.secuso.privacyfriendlynetmonitor.ConnectionAnalysis.PassiveService.java
private void showWarningNotification() { //Set corresponding icon //if(Evidence.getMaxSeverity() > 2){ // mBuilder.setSmallIcon(R.mipmap.icon_warn_red); // mBuilder.setLargeIcon(mWarnRed); //} else {//ww w. j a v a 2 s . co m // mBuilder.setSmallIcon(R.mipmap.icon_warn_orange); // mBuilder.setLargeIcon(mWarnOrange); //} //mBuilder.setContentText(mNotificationCount + " new warnings encountered."); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MainActivity.class); 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. mNotificationManager.notify(Const.LOG_TAG, 1, 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:org.fairphone.peaceofmind.PeaceOfMindBroadCastReceiver.java
/** * Sets the Peace of mind icon on the notification bar * @param putIcon if true the icon is put otherwise it is removed * @param wasInterrupted when true, an extra notification is sent to inform the user that Peace of mind was ended */// ww w . ja va2 s .c om private void setPeaceOfMindIconInNotificationBar(boolean putIcon, boolean wasInterrupted) { NotificationManager manager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE); if (putIcon) { //just in case the user didn't clear it manager.cancel(PEACE_OF_MIND_INTERRUPTED_NOTIFICATION); NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.peace_system_bar_icon) .setContentTitle(mContext.getResources().getString(R.string.app_name)) .setContentText(mContext.getResources().getString(R.string.peace_on_notification)); Intent resultIntent = new Intent(mContext, PeaceOfMindActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(PeaceOfMindActivity.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); builder.setContentIntent(resultPendingIntent); Notification notificationWhileRunnig = builder.build(); notificationWhileRunnig.flags |= Notification.FLAG_NO_CLEAR; // Add notification manager.notify(PEACE_OF_MIND_ON_NOTIFICATION, notificationWhileRunnig); } else { manager.cancel(PEACE_OF_MIND_ON_NOTIFICATION); //send a notification saying that the peace was ended if (wasInterrupted) { NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.peace_system_bar_icon).setAutoCancel(true) .setContentTitle(mContext.getResources().getString(R.string.app_name)) .setContentText(mContext.getResources().getString(R.string.peace_off_notification)) .setTicker(mContext.getResources().getString(R.string.peace_off_notification)); manager.notify(PEACE_OF_MIND_INTERRUPTED_NOTIFICATION, builder.build()); } } }
From source file:com.example.easyvoice.MessageDetail.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Respond to the action bar's Up/Home button case android.R.id.home: Log.i(getClass().getSimpleName(), "home pressed"); Intent upIntent = NavUtils.getParentActivityIntent(this); if (NavUtils.shouldUpRecreateTask(this, upIntent)) { // This activity is NOT part of this app's task, so create a new task // when navigating up, with a synthesized back stack. TaskStackBuilder.create(this) // Add all of this activity's parents to the back stack .addNextIntentWithParentStack(upIntent) // Navigate up to the closest parent .startActivities();/* w w w . j av a2 s .co m*/ } else { // This activity is part of this app's task, so simply // navigate up to the logical parent activity. NavUtils.navigateUpTo(this, upIntent); } return true; } return super.onOptionsItemSelected(item); }
From source file:com.fimo_pitch.main.MainActivity.java
private void makeNotification(Context context, String title, String content) { Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setSound(uri) .setPriority(Notification.PRIORITY_HIGH).setContentText(content); Intent resultIntent = new Intent(context, MainActivity.class); userModel = getUserModel();/* w ww . jav a2 s.c o m*/ resultIntent.putExtra(CONSTANT.KEY_USER, userModel); resultIntent.putExtra(CONSTANT.FROM_NOTIFICATION, "true"); TaskStackBuilder stackBuilder = null; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) { stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(FirstActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(10, mBuilder.build()); // Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // v.vibrate(ZAQ500); } else { NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(10, mBuilder.build()); // Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // v.vibrate(500); } }
From source file:com.example.maciej.mytask.MainActivity.java
public void createNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.add) .setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.notification_desc)); 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_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(12, mBuilder.build()); }
From source file:com.abhijitvalluri.android.fitnotifications.HomeFragment.java
private void initializeDemoButton() { mDemoTV.setOnClickListener(new View.OnClickListener() { @Override/*from w w w .j a v a2 s . co m*/ public void onClick(View v) { Bundle newExtra = new Bundle(); NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext); 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(mContext.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(mContext, 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(mContext); // 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) mContext.getSystemService(Context.NOTIFICATION_SERVICE)) .notify(Constants.NOTIFICATION_ID, builder.build()); Toast.makeText(mContext, getString(R.string.test_notification_sent), Toast.LENGTH_LONG).show(); if (mDismissPlaceholderNotif) { mHandler.postDelayed(new Runnable() { @Override public void run() { ((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE)) .cancel(Constants.NOTIFICATION_ID); } }, mPlaceholderNotifDismissDelayMillis); } } }); }