List of usage examples for android.app PendingIntent FLAG_UPDATE_CURRENT
int FLAG_UPDATE_CURRENT
To view the source code for android.app PendingIntent FLAG_UPDATE_CURRENT.
Click Source Link
From source file:biz.bokhorst.bpt.BPTService.java
@Override public IBinder onBind(Intent intent) { // Start foreground service startForeground(1, getNotification(getString(R.string.Running))); // Instantiate helpers locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); databaseHelper = new DatabaseHelper(this); preferences = PreferenceManager.getDefaultSharedPreferences(this); PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); taskHandler = new Handler(); wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BPT"); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Intent alarmIntent = new Intent("BPT_ALARM"); pendingAlarmIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE); alarmReceiver = new BPTAlarmReceiver(); registerReceiver(alarmReceiver, new IntentFilter("BPT_ALARM")); bound = true;/*ww w. ja va 2 s. co m*/ return serverMessenger.getBinder(); }
From source file:com.android.deskclock.alarms.AlarmNotifications.java
public static void showMissedNotification(Context context, AlarmInstance instance) { LogUtils.v("Displaying missed notification for alarm instance: " + instance.mId); String label = instance.mLabel; String alarmTime = AlarmUtils.getFormattedTime(context, instance.getAlarmTime()); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setContentTitle(context.getString(R.string.alarm_missed_title)) .setContentText(instance.mLabel.isEmpty() ? alarmTime : context.getString(R.string.alarm_missed_text, alarmTime, label)) .setSmallIcon(R.drawable.stat_notify_alarm).setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setLocalOnly(true);//ww w.ja va2 s .c o m final int hashCode = instance.hashCode(); // Setup dismiss intent Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE); notification.setDeleteIntent( PendingIntent.getService(context, hashCode, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content intent Intent showAndDismiss = AlarmInstance.createIntent(context, AlarmStateManager.class, instance.mId); showAndDismiss.putExtra(EXTRA_NOTIFICATION_ID, hashCode); showAndDismiss.setAction(AlarmStateManager.SHOW_AND_DISMISS_ALARM_ACTION); notification.setContentIntent( PendingIntent.getBroadcast(context, hashCode, showAndDismiss, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); nm.notify(hashCode, notification.build()); }
From source file:com.google.android.gms.location.sample.geofencing.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. *//*from w w w . j a v a2 s. c o m*/ private void sendNotification(String notificationDetails) { // 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.ic_launcher) // In a real app, you may want to use a library like Volley // to decode the Bitmap. .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setColor(Color.RED).setContentTitle(notificationDetails) .setContentText(getString(R.string.geofence_transition_notification_text)) .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.sublimis.urgentcallfilter.Magic.java
@SuppressWarnings("deprecation") private void notification() { if (MyPreference.isNotifications()) { if (mContext != null) { NotificationManager notificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); if (notificationManager != null) { Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis()); Intent notificationIntent = new Intent(mContext, ActivityMain.class); if (notification != null && notificationIntent != null) { notificationIntent.setFlags(notificationIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(mContext, mContext.getResources().getString(R.string.notification_title), mContext.getResources().getString(R.string.notification_text), pendingIntent); notificationManager.notify(0, notification); }/*from w w w.ja v a2s . c om*/ } } } }
From source file:com.androidinspain.deskclock.data.TimerNotificationBuilder.java
public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) { final Timer timer = unexpired.get(0); final int count = unexpired.size(); // Compute some values required below. final boolean running = timer.isRunning(); final Resources res = context.getResources(); final long base = getChronometerBase(timer); final String pname = context.getPackageName(); final List<Action> actions = new ArrayList<>(2); final CharSequence stateText; if (count == 1) { if (running) { // Single timer is running. if (TextUtils.isEmpty(timer.getLabel())) { stateText = res.getString(com.androidinspain.deskclock.R.string.timer_notification_label); } else { stateText = timer.getLabel(); }/*www . j a v a 2 s. c o m*/ // Left button: Pause final Intent pause = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_PAUSE_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_pause_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.timer_pause); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Action.Builder(icon1, title1, intent1).build()); // Right Button: +1 Minute final Intent addMinute = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_ADD_MINUTE_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon2 = com.androidinspain.deskclock.R.drawable.ic_add_24dp; final CharSequence title2 = res.getText(com.androidinspain.deskclock.R.string.timer_plus_1_min); final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute); actions.add(new Action.Builder(icon2, title2, intent2).build()); } else { // Single timer is paused. stateText = res.getString(com.androidinspain.deskclock.R.string.timer_paused); // Left button: Start final Intent start = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_START_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_start_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.sw_resume_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Action.Builder(icon1, title1, intent1).build()); // Right Button: Reset final Intent reset = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_RESET_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon2 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp; final CharSequence title2 = res.getText(com.androidinspain.deskclock.R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Action.Builder(icon2, title2, intent2).build()); } } else { if (running) { // At least one timer is running. stateText = res.getString(com.androidinspain.deskclock.R.string.timers_in_use, count); } else { // All timers are paused. stateText = res.getString(com.androidinspain.deskclock.R.string.timers_stopped, count); } final Intent reset = TimerService.createResetUnexpiredTimersIntent(context); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.timer_reset_all); final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset); actions.add(new Action.Builder(icon1, title1, intent1).build()); } // Intent to load the app and show the timer when the notification is tapped. final Intent showApp = new Intent(context, TimerService.class).setAction(TimerService.ACTION_SHOW_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()) .putExtra(Events.EXTRA_EVENT_LABEL, com.androidinspain.deskclock.R.string.label_notification); final PendingIntent pendingShowApp = PendingIntent.getService(context, REQUEST_CODE_UPCOMING, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); final Builder notification = new NotificationCompat.Builder(context).setOngoing(true).setLocalOnly(true) .setShowWhen(false).setAutoCancel(false).setContentIntent(pendingShowApp) .setPriority(Notification.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM) .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_timer) .setSortKey(nm.getTimerNotificationSortKey()).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setStyle(new NotificationCompat.DecoratedCustomViewStyle()) .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background)); for (Action action : actions) { notification.addAction(action); } if (Utils.isNOrLater()) { notification.setCustomContentView(buildChronometer(pname, base, running, stateText)) .setGroup(nm.getTimerNotificationGroupKey()); } else { final CharSequence contentTextPreN; if (count == 1) { contentTextPreN = TimerStringFormatter.formatTimeRemaining(context, timer.getRemainingTime(), false); } else if (running) { final String timeRemaining = TimerStringFormatter.formatTimeRemaining(context, timer.getRemainingTime(), false); contentTextPreN = context.getString(com.androidinspain.deskclock.R.string.next_timer_notif, timeRemaining); } else { contentTextPreN = context.getString(com.androidinspain.deskclock.R.string.all_timers_stopped_notif); } notification.setContentTitle(stateText).setContentText(contentTextPreN); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final Intent updateNotification = TimerService.createUpdateNotificationIntent(context); final long remainingTime = timer.getRemainingTime(); if (timer.isRunning() && remainingTime > MINUTE_IN_MILLIS) { // Schedule a callback to update the time-sensitive information of the running timer final PendingIntent pi = PendingIntent.getService(context, REQUEST_CODE_UPCOMING, updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); final long nextMinuteChange = remainingTime % MINUTE_IN_MILLIS; final long triggerTime = SystemClock.elapsedRealtime() + nextMinuteChange; TimerModel.schedulePendingIntent(am, triggerTime, pi); } else { // Cancel the update notification callback. final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE); if (pi != null) { am.cancel(pi); pi.cancel(); } } } return notification.build(); }
From source file:org.ambientdynamix.core.HomeActivity.java
@Override public void onCreate(Bundle savedInstanceState) { Log.v(TAG, "Activity State: onCreate()"); super.onCreate(savedInstanceState); // Set our static reference activity = this; setContentView(R.layout.home_tab);//from www . j a va 2 s . co m updateCheck(); points = new HashSet<>(); mMixpanel = MixpanelAPI.getInstance(this, Constants.MIXPANEL_TOKEN); mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map_main)); // Check if we were successful in obtaining the map. if (mMap == null) { // check if google play service in the device is not available or out-dated. GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); // nothing anymore, cuz android will take care of the rest (to remind user to update google play service). } // Construct the data source sensorMeasurements = new ArrayList<>(); // Create the adapter to convert the array to views sensorMeasurementAdapter = new SensorMeasurementAdapter(this, sensorMeasurements); // Attach the adapter to a ListView final TwoWayView listView = (TwoWayView) findViewById(R.id.lvItems); listView.setOrientation(TwoWayView.Orientation.VERTICAL); listView.setPadding(0, 0, 0, 0); listView.setItemMargin(0); listView.setAdapter(sensorMeasurementAdapter); //Disable for now final Intent activityRecognitionIntent = new Intent(this, ActivityRecognitionService.class); activityRecognitionPendingIntent = PendingIntent.getService(getApplicationContext(), 0, activityRecognitionIntent, PendingIntent.FLAG_UPDATE_CURRENT); mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(ActivityRecognition.API) .addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API) .build(); mGoogleApiClient.connect(); pendingSendButton = (Button) findViewById(R.id.send_pending_now); pendingSendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AsyncReportOnServerTask().execute(); try { final JSONObject props = new JSONObject(); props.put("count", DynamixService.getDataStorageSize()); //mMixpanel.track("send-stored-readings", props); } catch (JSONException ignore) { } } }); // Setup an state refresh timer, which periodically updates application // state in the appList final Timer refresher = new Timer(true); final TimerTask t = new TimerTask() { @Override public void run() { refreshData(); } }; refresher.scheduleAtFixedRate(t, 0, 5000); phoneIdTv = (TextView) this.findViewById(R.id.deviceId_label); expDescriptionTv = (TextView) this.findViewById(R.id.experiment_description); if (mMap.getMap() != null) { mMap.getMap().setMyLocationEnabled(true); mMap.getMap().getUiSettings().setAllGesturesEnabled(false); mMap.getMap().getUiSettings().setMyLocationButtonEnabled(false); } }
From source file:com.jaguarlandrover.auto.remote.vehicleentry.RviService.java
static void sendNotification(Context ctx, String action, String... extras) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ctx); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); boolean fire = prefs.getBoolean("pref_fire_notifications", true); if (!fire)//from w w w .j a v a 2 s .com return; NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx).setSmallIcon(R.drawable.rvi_not) .setAutoCancel(true).setContentTitle(ctx.getResources().getString(R.string.app_name)) .setContentText(action); Intent targetIntent = new Intent(ctx, LockActivity.class); int j = 0; for (String ex : extras) { targetIntent.putExtra("_extra" + (++j), ex); targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); } PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(contentIntent); nm.notify(0, builder.build()); }
From source file:com.teinproductions.tein.papyrosprogress.UpdateCheckReceiver.java
private static void issueNotification(Context context, Set<String> addedMilestones, Set<String> removedMilestones, Map<String, int[]> changedProgresses) { String title = context.getString(R.string.notification_title); StringBuilder message = new StringBuilder(); // Changed progresses for (String milestoneTitle : changedProgresses.keySet()) { int oldProgress = changedProgresses.get(milestoneTitle)[0]; int newProgress = changedProgresses.get(milestoneTitle)[1]; message.append("\n").append(String.format(context.getString(R.string.notific_msg_text_format), milestoneTitle, oldProgress, newProgress)); }// w ww .j a v a2s. c om // Added milestones for (String milestoneTitle : addedMilestones) { message.append("\n").append(context.getString(R.string.milestone_added_notification, milestoneTitle)); } // Removed milestones for (String milestoneTitle : removedMilestones) { message.append("\n").append(context.getString(R.string.milestone_removed_notification, milestoneTitle)); } // Remove first newline message.delete(0, 1); // Create PendingIntent PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); boolean sound = pref.getBoolean(Constants.NOTIFICATION_SOUND_PREF, true); boolean vibrate = pref.getBoolean(Constants.NOTIFICATION_VIBRATE_PREF, true); boolean light = pref.getBoolean(Constants.NOTIFICATION_LIGHT_PREF, true); int defaults = 0; if (sound) defaults = defaults | Notification.DEFAULT_SOUND; if (vibrate) defaults = defaults | Notification.DEFAULT_VIBRATE; if (light) defaults = defaults | Notification.DEFAULT_LIGHTS; // Build the notification NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setContentIntent(pendingIntent) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)) .setSmallIcon(R.mipmap.notification_small_icon) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setDefaults(defaults).setAutoCancel(true); // Issue the notification NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(PROGRESS_NOTIFICATION_ID, builder.build()); }
From source file:com.android.deskclock.data.StopwatchModel.java
/** * Updates the notification to reflect the latest state of the stopwatch and recorded laps. *//*from www . ja va 2s. com*/ void updateNotification() { final Stopwatch stopwatch = getStopwatch(); // Notification should be hidden if the stopwatch has no time or the app is open. if (stopwatch.isReset() || mNotificationModel.isApplicationInForeground()) { mNotificationManager.cancel(mNotificationModel.getStopwatchNotificationId()); return; } @StringRes final int eventLabel = R.string.label_notification; // Intent to load the app when the notification is tapped. final Intent showApp = new Intent(mContext, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final PendingIntent pendingShowApp = PendingIntent.getActivity(mContext, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); // Compute some values required below. final boolean running = stopwatch.isRunning(); final String pname = mContext.getPackageName(); final Resources res = mContext.getResources(); final long base = SystemClock.elapsedRealtime() - stopwatch.getTotalTime(); final RemoteViews collapsed = new RemoteViews(pname, R.layout.stopwatch_notif_collapsed); collapsed.setChronometer(R.id.swn_collapsed_chronometer, base, null, running); collapsed.setOnClickPendingIntent(R.id.swn_collapsed_hitspace, pendingShowApp); collapsed.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch); final RemoteViews expanded = new RemoteViews(pname, R.layout.stopwatch_notif_expanded); expanded.setChronometer(R.id.swn_expanded_chronometer, base, null, running); expanded.setOnClickPendingIntent(R.id.swn_expanded_hitspace, pendingShowApp); expanded.setImageViewResource(R.id.notification_icon, R.drawable.stat_notify_stopwatch); @IdRes final int leftButtonId = R.id.swn_left_button; @IdRes final int rightButtonId = R.id.swn_right_button; if (running) { // Left button: Pause expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_pause_button)); setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_pause_24dp); final Intent pause = new Intent(mContext, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); expanded.setOnClickPendingIntent(leftButtonId, pendingServiceIntent(pause)); // Right button: Add Lap if (canAddMoreLaps()) { expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_lap_button)); setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_sw_lap_24dp); final Intent lap = new Intent(mContext, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_LAP_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); expanded.setOnClickPendingIntent(rightButtonId, pendingServiceIntent(lap)); expanded.setViewVisibility(rightButtonId, VISIBLE); } else { expanded.setViewVisibility(rightButtonId, INVISIBLE); } // Show the current lap number if any laps have been recorded. final int lapCount = getLaps().size(); if (lapCount > 0) { final int lapNumber = lapCount + 1; final String lap = res.getString(R.string.sw_notification_lap_number, lapNumber); collapsed.setTextViewText(R.id.swn_collapsed_laps, lap); collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE); expanded.setTextViewText(R.id.swn_expanded_laps, lap); expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE); } else { collapsed.setViewVisibility(R.id.swn_collapsed_laps, GONE); expanded.setViewVisibility(R.id.swn_expanded_laps, GONE); } } else { // Left button: Start expanded.setTextViewText(leftButtonId, res.getText(R.string.sw_start_button)); setTextViewDrawable(expanded, leftButtonId, R.drawable.ic_start_24dp); final Intent start = new Intent(mContext, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); expanded.setOnClickPendingIntent(leftButtonId, pendingServiceIntent(start)); // Right button: Reset (HandleDeskClockApiCalls will also bring forward the app) expanded.setViewVisibility(rightButtonId, VISIBLE); expanded.setTextViewText(rightButtonId, res.getText(R.string.sw_reset_button)); setTextViewDrawable(expanded, rightButtonId, R.drawable.ic_reset_24dp); final Intent reset = new Intent(mContext, HandleDeskClockApiCalls.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); expanded.setOnClickPendingIntent(rightButtonId, pendingActivityIntent(reset)); // Indicate the stopwatch is paused. collapsed.setTextViewText(R.id.swn_collapsed_laps, res.getString(R.string.swn_paused)); collapsed.setViewVisibility(R.id.swn_collapsed_laps, VISIBLE); expanded.setTextViewText(R.id.swn_expanded_laps, res.getString(R.string.swn_paused)); expanded.setViewVisibility(R.id.swn_expanded_laps, VISIBLE); } // Swipe away will reset the stopwatch without bringing forward the app. final Intent reset = new Intent(mContext, StopwatchService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_STOPWATCH) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, eventLabel); final Notification notification = new NotificationCompat.Builder(mContext).setLocalOnly(true) .setOngoing(running).setContent(collapsed).setAutoCancel(stopwatch.isPaused()) .setPriority(Notification.PRIORITY_MAX).setDeleteIntent(pendingServiceIntent(reset)) .setSmallIcon(R.drawable.ic_tab_stopwatch_activated).build(); notification.bigContentView = expanded; mNotificationManager.notify(mNotificationModel.getStopwatchNotificationId(), notification); }
From source file:com.actinarium.rhythm.control.RhythmNotificationService.java
private NotificationCompat.Builder makeCommonNotification(String text) { final NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.arl_rhythm).setCategory(NotificationCompat.CATEGORY_SERVICE) .setPriority(NotificationCompat.PRIORITY_DEFAULT).setAutoCancel(false).setShowWhen(false) .setContentText(text).setStyle(new NotificationCompat.BigTextStyle().bigText(text)); // Old androids throw an exception when the notification doesn't have content intent if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { Intent contentAction = new Intent(this, RhythmNotificationService.class); contentAction.setAction(ACTION_NEXT_OVERLAY); PendingIntent piContentAction = PendingIntent.getService(this, 0, contentAction, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(piContentAction); }/*from ww w . j a v a 2 s .c o m*/ return builder; }