List of usage examples for android.app TaskStackBuilder create
public static TaskStackBuilder create(Context context)
From source file:com.jay.pea.mhealthapp2.utilityClasses.AlarmReceiver.java
/** * OnRecieve method that recieves calls form the AlertManager class and then applies some logic to fire notifications to the user. * * @param context//from w w w .j av a2 s . c o m * @param intent */ @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "onRecieve"); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MedMinder"); //Acquire the lock wl.acquire(); dose = null; dose = (Dose) intent.getSerializableExtra(AlertManager.ALARMSTRING); Log.d(TAG, " This dose is " + dose.getMedication().getMedName() + " " + dose.getDoseTime().toString(dtfTime)); if (dose == null) { Log.d(TAG, "Alert object Extra is null"); } //get the parent med Medication med = dose.getMedication(); int alertCount = 0; for (DateTime doseDueDT : med.getDoseMap1().keySet()) { DateTime doseTakenDT = med.getDoseMap1().get(doseDueDT); if (doseDueDT.isBefore(new DateTime().now()) && doseDueDT.isAfter(new DateTime().withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0)) && doseTakenDT.equals(new DateTime(0))) { alertCount++; } } if (alertCount == 0) { return; } SharedPreferences sharedPref = context.getSharedPreferences("AlertCounter", 0); int alertCountPref = sharedPref.getInt(med.getMedName(), 0); SharedPreferences.Editor editor = sharedPref.edit(); DateTime now = new DateTime().now(); int notifID = dose.getMedication().getDbID(); Random rand = new Random(); //int notifID = rand.nextInt(); Log.d(TAG, dose.getMedication().getDbID() + " " + dose.getDoseTime().getMillisOfDay()); if (dose.getTakenTime().toString(dtfDate).equals(new DateTime(0).toString(dtfDate))) { // if ((dose.getDoseTime().getMillis() + alertMissedWindowArray[dose.getMedication().getFreq() - 1] * 2) > new DateTime().getMillis()); String alertString = "You have " + alertCount + " missed doses for " + med.getMedName(); if (alertCount == 1) { alertString = "You have a missed dose for " + med.getMedName(); } //check if the dose is due +/- 15mins and advise that a dose is due. long diffMillis = dose.getDoseTime().getMillis() - new DateTime().now().getMillis(); Log.d(TAG, diffMillis + " dose time = " + dose.getDoseTime().getMillis() + " now= " + new DateTime().now().getMillis()); boolean doseDue = Math.abs(diffMillis) < 1800000; if (doseDue) { alertString = dose.getMedication().getDose() + " of " + dose.getMedication().getMedName() + " is due now."; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.medminder_icon).setContentTitle("MedMinder").setContentText(alertString); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mBuilder.setSound(alarmSound); // 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); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(notifID, mBuilder.build()); Log.d(TAG, " Notification sent " + notifID); // // // editor.putInt(med.getMedName(), alertCount); // editor.commit(); //Release the lock wl.release(); } }
From source file:com.ph1ash.dexter.beeplepaper.BeeplePaperService.java
protected void displayLoginNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.common_full_open_on_phone).setContentTitle("BeeplePaper - Verify Login") .setContentText("Verify your Facebook login for to allow BeeplePaper to update."); 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_ONE_SHOT); mBuilder.setContentIntent(resultPendingIntent); Notification notif = mBuilder.build(); notif.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, notif); }
From source file:com.hmatalonga.greenhub.util.Notifier.java
public static void newMessageAlert(final Context context) { if (sNotificationManager == null) { sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); }/* www .j av a 2s . com*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_email_white_24dp) .setContentTitle(context.getString(R.string.notif_new_message)) .setContentText(context.getString(R.string.notif_open_inbox)).setAutoCancel(true).setOngoing(false) .setLights(Color.GREEN, 500, 2000).setVibrate(new long[] { 0, 800, 1500 }) .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, InboxActivity.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. Notification notification = mBuilder.build(); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; sNotificationManager.notify(Config.NOTIFICATION_MESSAGE_NEW, notification); }
From source file:org.protocoderrunner.apprunner.api.PApp.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @ProtocoderScript/*w w w.jav a2s .c o m*/ @APIMethod(description = "", example = "") @APIParam(params = { "id", "title", "description" }) public void setNotification(int id, String title, String description) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(a.get()) .setSmallIcon(R.drawable.app_icon).setContentTitle(title).setContentText(description); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(a.get(), AppRunnerActivity.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(a.get()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(AppRunnerActivity.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) a.get() .getSystemService(a.get().NOTIFICATION_SERVICE); // mId allows you to update the notification later on. mNotificationManager.notify(id, mBuilder.build()); }
From source file:in.rab.ordboken.Ordboken.java
public boolean onOptionsItemSelected(Activity activity, MenuItem item) { if (item.getItemId() == R.id.menu_logout) { updateCreds("", ""); mNeClient.logout();/*from w ww .java 2s. c o m*/ SharedPreferences.Editor ed = mPrefs.edit(); ed.putBoolean("loggedIn", false); ed.putString("username", ""); ed.putString("password", ""); ed.commit(); Intent intent = new Intent(mContext, LoginActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(intent); activity.finish(); return true; } else if (item.getItemId() == android.R.id.home) { Intent upIntent = NavUtils.getParentActivityIntent(activity); if (NavUtils.shouldUpRecreateTask(activity, upIntent)) { TaskStackBuilder.create(activity).addNextIntentWithParentStack(upIntent).startActivities(); } else { NavUtils.navigateUpFromSameTask(activity); } return true; } return false; }
From source file:org.catnut.service.ComposeTweetService.java
private void fallback(Draft draft, String error) { draft.createAt = System.currentTimeMillis(); getContentResolver().insert(CatnutProvider.parse(Draft.MULTIPLE), Draft.METADATA.convert(draft)); mBuilder.setContentTitle(getString(R.string.post_fail)).setContentText(error) .setTicker(getText(R.string.post_fail)).setProgress(0, 0, false); // fallback/* w w w . j a va2 s. co m*/ Intent resultIntent = SingleFragmentActivity.getIntent(this, SingleFragmentActivity.DRAFT); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this); taskStackBuilder.addParentStack(SingleFragmentActivity.class); taskStackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = taskStackBuilder.getPendingIntent(ID, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent).setAutoCancel(true); mNotifyManager.notify(ID, mBuilder.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 .ja v a2 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:org.secuso.privacyfriendlynetmonitor.ConnectionAnalysis.PassiveService.java
private void showAppNotification() { mBuilder.setSmallIcon(R.drawable.ic_notification); mBuilder.setLargeIcon(mIcon);/*from www .j a v a 2s.co m*/ 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. mNotificationManager.notify(Const.LOG_TAG, 1, mBuilder.build()); }
From source file:de.aw.awlib.AWNotification.java
/** * Erstellt einen NotificationBuilder mit Ticker {@link AWNotification#ticker}, hasProgressBar * und setzt (wenn gesetzt) startActivity als StartActivity. * * @return NotificationBuilder//from w w w. jav a 2 s . com */ protected NotificationCompat.Builder getNotification() { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, mChannelID); mBuilder.setSmallIcon(getIconResID()).setAutoCancel(true); if (ticker != null) { mBuilder.setTicker(ticker); } if (number != NOID) { mBuilder.setNumber(number); } mBuilder.setProgress(0, 0, hasProgressBar); Intent intent; if (startActivity != null) { TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); intent = new Intent(context, startActivity); intent.putExtras(extras); stackBuilder.addNextIntent(intent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); } return mBuilder; }
From source file:com.mienaikoe.deltamonitor.CameraWatcherService.java
private void notifyMessage(String title, String message) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.icon) .setContentTitle(title).setContentText(message); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(this, MotionDetectionActivity.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); stackBuilder.addParentStack(MotionDetectionActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); if (notifier == null) { notifier = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); }/*from ww w . j a va 2 s .co m*/ notifier.notify(NOTIFICATION_ID, mBuilder.build()); }