List of usage examples for android.app TaskStackBuilder addParentStack
public TaskStackBuilder addParentStack(ComponentName sourceActivityName)
From source file:de.localtoast.launchit.BackgroundService.java
private void addNotificationIcon() { Context context = getBaseContext(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.abc_ab_bottom_solid_dark_holo).setContentTitle("Launch it!") .setContentText("Touch for preferences").setOngoing(true); Intent resultIntent = new Intent(context, SettingsActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // 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(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(1, mBuilder.build()); }
From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java
/** * sends the service notification// w ww . jav a2 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); }
From source file:com.abhijitvalluri.android.fitnotifications.HomeFragment.java
private void initializeDemoButton() { mDemoTV.setOnClickListener(new View.OnClickListener() { @Override/*from ww w . j a v a 2 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); } } }); }
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. j a v a 2s . com 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.hollandhaptics.babyapp.BabyService.java
/** * @param _message The message to show./*www . ja v a 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.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);/*from w w w.ja v a 2 s. c om*/ 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. j a v a 2s . 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.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. jav a2 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.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 a 2 s. co m 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()); } }); }