List of usage examples for android.app TaskStackBuilder create
public static TaskStackBuilder create(Context context)
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;/* www. 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:rtdc.android.presenter.InCallActivity.java
@Override protected void onCreate(android.os.Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_in_call); // Force screen to stay on during the call getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); if (getResources().getBoolean(R.bool.isTablet)) AndroidVoipController.get().setSpeaker(true); if (AndroidVoipController.get().isReceivingRemoteVideo() || AndroidVoipController.get().isVideoEnabled()) { displayVideo();// w w w . j a v a 2 s. co m } else { displayAudio(); } // Build the intent that will be used by the notification Intent resultIntent = new Intent(this, InCallActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Build stack trace for the notification TaskStackBuilder stackBuilder = TaskStackBuilder.create(AndroidBootstrapper.getAppContext()); stackBuilder.addParentStack(InCallActivity.class); stackBuilder.addNextIntent(resultIntent); // Build notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_phone_white_24dp).setContentTitle(ResBundle.get().rtdcTitle()) .setContentText(ResBundle.get() .inCallWith(AndroidVoIPThread.getInstance().getCall().getFrom().getDisplayName())); PendingIntent inCallPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(inCallPendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(IN_CALL_NOTIFICATION_ID, mBuilder.build()); AndroidVoIPThread.getInstance().addVoIPListener(this); }
From source file:com.raspi.chatapp.util.Notification.java
public void createNotification(String buddyId, String name, String message, String type) { SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); if (defaultSharedPreferences .getBoolean(context.getResources().getString(R.string.pref_key_new_message_notifications), true)) { int index = buddyId.indexOf("@"); if (index != -1) buddyId = buddyId.substring(0, index); if (name == null) name = buddyId;/*from w w w .jav a 2 s. c om*/ Log.d("DEBUG", "creating notification: " + buddyId + "|" + name + "|" + message); Intent resultIntent = new Intent(context, ChatActivity.class); resultIntent.setAction(NOTIFICATION_CLICK); String oldBuddyId = getOldBuddyId(); Log.d("DEBUG", (oldBuddyId == null) ? ("oldBuddy is null (later " + buddyId) : ("oldBuddy: " + oldBuddyId)); if (oldBuddyId == null || oldBuddyId.equals("")) { oldBuddyId = buddyId; setOldBuddyId(buddyId); } if (oldBuddyId.equals(buddyId)) { resultIntent.putExtra(Constants.BUDDY_ID, buddyId); resultIntent.putExtra(Constants.CHAT_NAME, name); } TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(ChatActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationManager nm = ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)); NotificationCompat.Style style; String[] previousNotifications = readJSONArray(CURRENT_NOTIFICATIONS); String title; String[] currentNotifications = Arrays.copyOf(previousNotifications, previousNotifications.length + 1); currentNotifications[currentNotifications.length - 1] = name + ": " + message; if (previousNotifications.length == 0) { style = new NotificationCompat.BigTextStyle(); NotificationCompat.BigTextStyle bigTextStyle = ((NotificationCompat.BigTextStyle) style); title = context.getResources().getString(R.string.new_message) + " " + context.getResources().getString(R.string.from) + " " + name; bigTextStyle.bigText(currentNotifications[0]); bigTextStyle.setBigContentTitle(title); } else { style = new NotificationCompat.InboxStyle(); NotificationCompat.InboxStyle inboxStyle = (NotificationCompat.InboxStyle) style; title = (previousNotifications.length + 1) + " " + context.getResources().getString(R.string.new_messages); for (String s : currentNotifications) if (s != null && !"".equals(s)) inboxStyle.addLine(s); inboxStyle.setSummaryText( (currentNotifications.length > 2) ? ("+" + (currentNotifications.length - 2) + " more") : null); inboxStyle.setBigContentTitle(title); } writeJSONArray(currentNotifications, CURRENT_NOTIFICATIONS); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(currentNotifications[currentNotifications.length - 1]) .setSmallIcon(MessageHistory.TYPE_TEXT.equals(type) ? R.drawable.ic_forum_white_48dp : R.drawable.ic_photo_camera_white_48dp) .setLargeIcon(getLargeIcon(Character.toUpperCase(name.toCharArray()[0]))).setStyle(style) .setAutoCancel(true).setPriority(5).setContentIntent(resultPendingIntent); String str = context.getResources().getString(R.string.pref_key_privacy); mBuilder.setVisibility(context.getResources().getString(R.string.pref_value1_privacy).equals(str) ? NotificationCompat.VISIBILITY_SECRET : context.getResources().getString(R.string.pref_value2_privacy).equals(str) ? NotificationCompat.VISIBILITY_PRIVATE : NotificationCompat.VISIBILITY_PUBLIC); str = context.getResources().getString(R.string.pref_key_vibrate); if (defaultSharedPreferences.getBoolean(str, true)) mBuilder.setVibrate(new long[] { 800, 500, 800, 500 }); str = context.getResources().getString(R.string.pref_key_led); if (defaultSharedPreferences.getBoolean(str, true)) mBuilder.setLights(Color.BLUE, 500, 500); str = defaultSharedPreferences.getString(context.getResources().getString(R.string.pref_key_ringtone), ""); mBuilder.setSound("".equals(str) ? RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION) : Uri.parse(str)); nm.notify(NOTIFICATION_ID, mBuilder.build()); str = context.getResources().getString(R.string.pref_key_banner); if (!defaultSharedPreferences.getBoolean(str, true)) { try { Thread.sleep(1500); } catch (InterruptedException e) { } reset(); } } }
From source file:alaindc.crowdroid.GeofenceTransitionsIntentService.java
/** * Posts a notification in the notification bar when a transition is detected. * If the user clicks the notification, control goes to the MainActivity. */// ww w . ja v a 2s .com private void sendNotification(String nameofsensor) { // Create an explicit content Intent that starts the main Activity. Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); // Construct a task stack. TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Add the main Activity to the task stack as the parent. stackBuilder.addParentStack(MainActivity.class); // Push the content Intent onto the stack. stackBuilder.addNextIntent(notificationIntent); // Get a PendingIntent containing the entire back stack. PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Get a notification builder that's compatible with platform versions >= 4 NotificationCompat.Builder builder = new NotificationCompat.Builder(this); // Define the notification settings. builder.setSmallIcon(R.drawable.icon) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.icon)).setColor(Color.RED) .setContentTitle("Geofence Crowdroid").setContentText("Geofence Trigger: " + nameofsensor) .setContentIntent(notificationPendingIntent); // Dismiss notification once the user touches it. builder.setAutoCancel(true); // Get an instance of the Notification manager NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Issue the notification mNotificationManager.notify(0, builder.build()); }
From source file:com.partner.common.updater.ApkDownloadUtil.java
/** * ?//from www . j a va 2 s . com * @param context * @param targetClass */ private void showAppDownloadNotify(Context context, Class<?> parentClass, Class<?> targetClass) { mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // show notify Intent notifyIntent = new Intent(context, targetClass); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack if (parentClass != null) { stackBuilder.addNextIntent(new Intent(context, parentClass)); } // Adds the Intent to the top of the stack stackBuilder.addNextIntent(notifyIntent); // Gets a PendingIntent containing the entire back stack PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder = new NotificationCompat.Builder(context); mBuilder.setContentTitle(appName).setSmallIcon(R.drawable.ic_launcher) .setContentIntent(resultPendingIntent); mBuilder.setProgress(100, 0, false); mNotifyManager.notify(appName.hashCode(), mBuilder.build()); }
From source file:capstone.se491_phm.gcm.PhmGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./* w ww. j a va2s . c o m*/ */ private void sendNotification(String message) { Context context = getBaseContext(); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(Constants.SERVER_IP, message); editor.commit(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.notification).setContentTitle("External Sensor Request") .setContentText("A connection request has been made from this ip: " + message + ". Click to allow connection") .setSound(defaultSoundUri); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, ExternalSensorActivity.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(ExternalSensorActivity.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); // mId allows you to update the notification later on. MainActivity.mNotificationManager.notify(notificationId, mBuilder.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;/*from w w w . j a v a2 s. c om*/ } // 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: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:io.github.protino.codewatch.sync.WakatimeDataSyncJob.java
public void updateNotifications() { //Notify goals final CountDownLatch firebaseLatch = new CountDownLatch(1); final List<GoalItem> goalItemList = new ArrayList<>(); Context context = getApplicationContext(); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean notifyGoals = sharedPreferences.getBoolean(context.getString(R.string.pref_goal_reminders_key), true);/*from w w w. j a v a2 s . c o m*/ boolean notifyRank = sharedPreferences.getBoolean(context.getString(R.string.pref_leaderboard_changes_key), true); String firebaseUid = sharedPreferences.getString(Constants.PREF_FIREBASE_USER_ID, null); String title = context.getString(R.string.app_name); Intent resultIntent = new Intent(context, NavigationDrawerActivity.class); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); taskStackBuilder.addNextIntent(resultIntent); PendingIntent pendingIntent = taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); if (notifyGoals && firebaseUid != null) { FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance(); DatabaseReference databaseReference = firebaseDatabase.getReference().child("goals").child(firebaseUid); databaseReference.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for (DataSnapshot snapshot : dataSnapshot.getChildren()) { goalItemList.add(snapshot.getValue(GoalItem.class)); } firebaseLatch.countDown(); } @Override public void onCancelled(DatabaseError databaseError) { firebaseLatch.countDown(); } }); try { //Build the notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setColor(context.getResources().getColor(R.color.colorPrimaryDark)) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title) .setContentText(context.getString(R.string.goals_reminder)); firebaseLatch.await(); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); for (GoalItem goalItem : goalItemList) { String goalText = null; switch (goalItem.getType()) { case LANGUAGE_GOAL: goalText = context.getString(R.string.language_goal, goalItem.getName(), goalItem.getData()); break; case PROJECT_DAILY_GOAL: goalText = context.getString(R.string.project_daily_goal, goalItem.getData(), goalItem.getName()); break; case PROJECT_DEADLINE_GOAL: long deadline = goalItem.getData(); long currentDate = System.currentTimeMillis(); int remainingDays = Days.daysBetween(new DateTime(currentDate), new DateTime(deadline)) .getDays(); if (remainingDays > 0) { if (currentDate < deadline) { goalText = context.getString(R.string.finish_project_today, goalItem.getName()); } } else { goalText = context.getString(R.string.finish_project_within, goalItem.getName(), remainingDays); } break; default: break; } if (goalText != null) { inboxStyle.addLine(goalText); } } builder.setStyle(inboxStyle); builder.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(GOAL_NOTIFICATION_ID, builder.build()); } catch (InterruptedException e) { Timber.e(e); } } if (notifyRank) { String wakatimeUid = sharedPreferences.getString(PREF_WAKATIME_USER_ID, null); Cursor cursor = getContentResolver().query(LeaderContract.LeaderEntry.buildProfileUri(wakatimeUid), null, null, null, null); if (cursor == null || !cursor.moveToFirst()) { return; } int rank = cursor.getInt(cursor.getColumnIndex(LeaderContract.LeaderEntry.COLUMN_RANK)); int dailyAverage = cursor .getInt(cursor.getColumnIndex(LeaderContract.LeaderEntry.COLUMN_DAILY_AVERAGE)); String text = context.getString(R.string.leaderboard_notification_text, rank, FormatUtils.getFormattedTime(context, dailyAverage)); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_launcher) .setColor(context.getResources().getColor(R.color.colorPrimaryDark)).setContentTitle(title) .setContentText(text).setStyle(new NotificationCompat.BigTextStyle().bigText(text)) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(LEADERBOARD_NOTIFICATION_ID, builder.build()); cursor.close(); } }
From source file:com.ibm.mf.geofence.demo.MyGeofenceReceiver.java
private void sendNotification(Context context, List<MFGeofence> fences, String type) { String title = "Geofence: " + type; StringBuilder sb = new StringBuilder(); int count = 0; for (MFGeofence g : fences) { if (count > 0) sb.append('\n'); sb.append(String.format("%s : lat=%.6f; lng=%.6f; radius=%.0f m", g.getName(), g.getLatitude(), g.getLongitude(), g.getRadius())); count++;// ww w .ja va 2s .co m } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setAutoCancel(true) .setSmallIcon(android.R.drawable.ic_notification_overlay).setContentTitle(title) .setContentText(sb.toString()); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MapsActivity.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(MapsActivity.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.incrementAndGet(), mBuilder.build()); }