List of usage examples for android.app TaskStackBuilder addNextIntent
public TaskStackBuilder addNextIntent(Intent nextIntent)
From source file:com.abhijitvalluri.android.fitnotifications.HomeFragment.java
private void initializeDemoButton() { mDemoTV.setOnClickListener(new View.OnClickListener() { @Override/*from ww w .j av a 2 s.c o 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); } } }); }
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 ww. jav a2 s . 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.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java
/** * Notifies the user that fresh news updates are now available. *//* w ww.j ava 2 s . c om*/ private void sendNewsNotification(Context context) { // Create the intent to open the app when the user taps on the notification. Intent mainIntent = new Intent(context, MainActivity.class); // Create the stack builder object. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Add the intent to the top of the stack. stackBuilder.addNextIntent(mainIntent); // Get a pending intent containing the entire back stack. PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Create the notification builder object. NotificationCompat.Builder builder = new NotificationCompat.Builder(context); // Set the pending intent onto the notification. builder.setContentIntent(pendingIntent); // Set the notification to automatically dismiss after the user taps it. builder.setAutoCancel(true); // Set the notification title and text. builder.setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.msg_notification_text)); // Set the notification ticker. builder.setTicker(context.getString(R.string.msg_notification_text)); // Set the notification large and small icons. builder.setSmallIcon(R.drawable.ic_notify_small) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_notify_large)); // Send the notification. NotificationManager notificationManager = (NotificationManager) context .getSystemService(context.NOTIFICATION_SERVICE); notificationManager.notify(NEWS_NOTIFICATION_ID, builder.build()); }
From source file:com.hollandhaptics.babyapp.BabyService.java
/** * @param _message The message to show./*from w w w . ja v a2 s . c om*/ * @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.polkapolka.bluetooth.le.DeviceControlActivity.java
public void showNotification(View view) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.NotifationTitle)) .setContentText(getString(R.string.NotificationSubtitle)) .setTicker(getString(R.string.NotificationTicker)).setSmallIcon(R.drawable.icon); // Define that we have the intention of opening MoreInfoNotification Intent moreInfoIntent = new Intent(this, userActivity.class); // Used to stack tasks across activites so we go to the proper place when back is clicked TaskStackBuilder tStackBuilder = TaskStackBuilder.create(this); // Add all parents of this activity to the stack tStackBuilder.addParentStack(DeviceControlActivity.class); // Add our new Intent to the stack tStackBuilder.addNextIntent(moreInfoIntent); 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) getSystemService(Context.NOTIFICATION_SERVICE); // Post the notification notificationManager.notify(notifID, notificationBuilder.build()); }
From source file:com.y59song.PrivacyGuard.MyVpnService.java
@Override public void notify(String appName, String msg) { isLocation(appName, msg);/* w w w . j a v a 2 s . 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.y59song.PrivacyGuard.MyVpnService.java
@Override public void updateNotification(String appName, String msg) { DatabaseHandler db = new DatabaseHandler(this); boolean ignored = false; if (isIgnored(appName, msg)) { ignored = true;//from ww w . jav a2 s .c om } NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); int notifyId = findNotificationId(appName, msg); int generalNotifyId = findGeneralNotificationId(appName); NotificationCompat.Builder mNotifyBuilder = new NotificationCompat.Builder(this) .setContentText("Number of leaks: " + findNotificationCounter(appName, msg)) .setContentTitle(appName + " " + msg).setTicker(appName + " " + msg) .setSmallIcon(R.drawable.notify); // ------------------------------------------------------------------------------------ // Currently initiates a new activity instance each time, should recycle if already open // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, DetailsActivity.class); // should actually be 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 } // 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(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); mNotifyBuilder.setContentIntent(resultPendingIntent); // ------------------------------------------------------------------------------------ // Creates an explicit intent for an Activity in your app 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); mNotifyBuilder.addAction(R.drawable.ignore, "Ignore", pendingIntent); // ------------------------------------------------------------------------------------ // Set Notification Style to Expanded NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String[] events = new String[findNotificationCounter(appName, msg)]; if (generalNotifyId >= 0 && !ignored) { // Because the ID remains unchanged, the existing notification is updated. Log.i(TAG, "NOTIFYID IS SUCCESSFULL" + notifyId); mNotificationManager.notify(generalNotifyId, mNotifyBuilder.build()); } else { Log.i(TAG, "NOTIFYID IS FAILING" + notifyId); } // ----------------------------------------------------------------------- // Database Entry db.addLeak(new DataLeak(notifyId, appName, msg, events.length, dateFormat.format(new Date()))); // ----------------------------------------------------------------------- }
From source file:com.kyleszombathy.sms_scheduler.Home.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "Activity View Created"); // Setting up transitions getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS); getWindow().setExitTransition(new Fade()); setContentView(R.layout.activity_home); Toolbar toolbar = (Toolbar) findViewById(R.id.SMSScheduler_Toolbar); setActionBar(toolbar);//from w w w. j a v a2s . com populateDatasets(); setUpRecyclerView(); LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("custom-event-name")); parentView = findViewById(R.id.Home_coordLayout); prefs = getSharedPreferences("com.kyleszombathy.sms_scheduler", MODE_PRIVATE); // Floating action button start activity findViewById(R.id.Home_fab).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Random alarm number int alarmNumber = getRandomInt(MIN_INT, MAX_INT); Intent intent = new Intent(new Intent(Home.this, AddMessage.class)); Bundle extras = new Bundle(); extras.putInt(ALARM_EXTRA, alarmNumber); extras.putBoolean(EDIT_MESSAGE_EXTRA, false); intent.putExtras(extras); TaskStackBuilder stackBuilder = TaskStackBuilder.create(Home.this); stackBuilder.addParentStack(AddMessage.class); stackBuilder.addNextIntent(intent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); Log.d(TAG, "Starting Activity AddMessage"); startActivityForResult(intent, NEW_MESSAGE, ActivityOptions.makeSceneTransitionAnimation(Home.this).toBundle()); } }); }
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 ww w .j a va2 s . co 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:re.serialout.MainScreen.java
public void buildNotification(Context context) { //Feature in progress, not in current version. NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle("There is a new survey for you to complete!"); builder.setContentText("Please take a second to fill it out."); builder.setSmallIcon(R.drawable.logo2); builder.setAutoCancel(true);/*from www. j av a2 s . c o m*/ System.out.println("BUILT"); Intent resultIntent = new Intent(this, MainScreen.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainScreen.class); stackBuilder.addNextIntent(resultIntent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(100, builder.build()); }