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:com.audiokernel.euphonyrmt.service.NotificationHandler.java
/** * This builds a new collapsed notification. * * @return Returns a notification builder object. *//* ww w . j ava2 s .c om*/ private static NotificationCompat.Builder buildCollapsedNotification(final MPDroidService context) { final Intent musicPlayerActivity = new Intent(context, MainMenuActivity.class); final PendingIntent notificationClick = PendingIntent.getActivity(context, 0, musicPlayerActivity, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.icon_notification); builder.setContentIntent(notificationClick); builder.setStyle(new NotificationCompat.BigTextStyle()); return builder; }
From source file:com.baasbox.android.samples.aloa.receive.NewMessageNotification.java
/** * Shows the notification, or updates a previously shown notification of * this type, with the given parameters. * <p>//from www . j a v a 2s . com * TODO: Customize this method's arguments to present relevant content in * the notification. * <p> * TODO: Customize the contents of this method to tweak the behavior and * presentation of new message notifications. Make * sure to follow the * <a href="https://developer.android.com/design/patterns/notifications.html"> * Notification design guidelines</a> when doing so. * * @see #cancel(Context) */ public static void notify(final Context context, final String exampleString, final int number) { final Resources res = context.getResources(); final String ticker = exampleString; final String title = res.getString(R.string.new_message_notification_title_template, exampleString); final String text = res.getString(R.string.new_message_notification_placeholder_text_template, exampleString); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) // Set appropriate defaults for the notification light, sound, // and vibration. .setDefaults(Notification.DEFAULT_ALL) // Set required fields, including the small icon, the // notification title, and text. .setSmallIcon(R.drawable.ic_stat_new_message).setContentTitle(title).setContentText(text) // All fields below this line are optional. // Use a default priority (recognized on devices running Android // 4.1 or later) .setPriority(NotificationCompat.PRIORITY_DEFAULT) // Set ticker text (preview) information for this notification. .setTicker(ticker) // Show a number. This is useful when stacking notifications of // a single type. .setNumber(number) // Set the pending intent to be initiated when the user touches // the notification. .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)) // Automatically dismiss the notification when it is touched. .setAutoCancel(true); notify(context, builder.build()); }
From source file:com.android.mms.widget.MmsWidgetProvider.java
/** * Update the widget appWidgetId//from www . j a v a2 s .c o m */ private static void updateWidget(Context context, int appWidgetId) { if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) { Log.v(TAG, "updateWidget appWidgetId: " + appWidgetId); } RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); PendingIntent clickIntent; // Launch an intent to avoid ANRs final Intent intent = new Intent(context, MmsWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(appWidgetId, R.id.conversation_list, intent); remoteViews.setTextViewText(R.id.widget_label, context.getString(R.string.sms_app_label)); // Open Mms's app conversation list when click on header final Intent convIntent = new Intent(context, ConversationList.class); clickIntent = PendingIntent.getActivity(context, 0, convIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_header, clickIntent); // On click intent for Compose final Intent composeIntent = new Intent(context, ComposeMessageActivity.class); composeIntent.setAction(Intent.ACTION_SENDTO); clickIntent = PendingIntent.getActivity(context, 0, composeIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setOnClickPendingIntent(R.id.widget_compose, clickIntent); // On click intent for Conversation TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(context); taskStackBuilder.addParentStack(ComposeMessageActivity.class); Intent msgIntent = new Intent(Intent.ACTION_VIEW); msgIntent.setType("vnd.android-dir/mms-sms"); taskStackBuilder.addNextIntent(msgIntent); remoteViews.setPendingIntentTemplate(R.id.conversation_list, taskStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT)); AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, remoteViews); }
From source file:com.capstone.transit.trans_it.RouteMap.java
@Override protected void onResume() { super.onResume(); setUpMapIfNeeded();//from w w w .j ava 2 s.c o m positionsServiceIntent = new Intent(getApplicationContext(), RefreshPositionsService.class); positionsServiceIntent.putExtra("EXTRA_ROUTE_ID", routeID); positionsServiceIntent.putExtra("EXTRA_RECEIVER", new PositionsReceiver(new Handler())); final PendingIntent pendingIntent = PendingIntent.getService(this, 0, positionsServiceIntent, PendingIntent.FLAG_UPDATE_CURRENT); long trigger = System.currentTimeMillis(); int intervalMillis = 1000 * 60; AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); alarm.setRepeating(AlarmManager.RTC, trigger, intervalMillis, pendingIntent); }
From source file:barqsoft.footballscores.widget.WidgetListProvider.java
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // Perform this loop procedure for each App Widget that belongs to this provider for (int appWidgetId : appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_list); // Create an Intent to launch MainActivity Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.widget_item, pendingIntent); // Set up the collection if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { setRemoteAdapter(context, views); } else {//from w w w . j a va2s . co m setRemoteAdapterV11(context, views); } Intent clickIntentTemplate = new Intent(context, MainActivity.class); PendingIntent clickPendingIntentTemplate = TaskStackBuilder.create(context) .addNextIntentWithParentStack(clickIntentTemplate) .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.widget_list, clickPendingIntentTemplate); views.setEmptyView(R.id.widget_list, R.id.widget_empty); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } }
From source file:com.android.sandwichmaker.ui.NotifyService.java
private void issueNotification(Intent intent, String msg) { mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Bitmap bmp = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher); // Constructs the Builder object. builder = new NotificationCompat.Builder(this).setLargeIcon(bmp).setSmallIcon(R.drawable.ic_launcher) .setTicker(getString(R.string.hint)).setContentTitle(getString(R.string.app_name)) .setContentText(getString(R.string.notify_message)).setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)); Intent resultIntent = new Intent(this, MainActivity.class); resultIntent.putExtra(CommonConstants.EXTRA_MESSAGE, msg); resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); // Because clicking the notification opens a new ("special") activity, there's // no need to create an artificial back stack. PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(resultPendingIntent); startTimer(mMillis);/*from w w w.j a v a 2 s.c o m*/ }
From source file:com.adstrosoftware.gpsplayground.activityrecognizer.ActivityRecognizerFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); client = new ActivityRecognitionClient(getActivity(), this, this); updateIntent = PendingIntent.getBroadcast(getActivity(), 0, new Intent(ACTION_ACTIVITY_UPDATE), PendingIntent.FLAG_UPDATE_CURRENT); activityUpdateBroadcastReceiver = new ActivityUpdateBroadcastReceiver(); }
From source file:com.alchemiasoft.book.service.SuggestionService.java
@Override protected void onHandleIntent(Intent intent) { Log.d(TAG_LOG, "Starting a new book suggestion..."); final ContentResolver cr = getContentResolver(); final Cursor c = cr.query(BookDB.Book.CONTENT_URI, null, SELECTION, SELECT_NOT_OWNED, null); Book book = null;/*from w w w. j a v a 2 s. co m*/ try { if (c.moveToNext()) { book = Book.oneFrom(c); } } finally { c.close(); } // Showing a notification if a not owned book is found if (book != null) { Log.d(TAG_LOG, "Found book that can be suggested: " + book); final String content = getString(R.string.content_book_suggestion, book.getTitle(), book.getAuthor()); final NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true) .setContentTitle(getString(R.string.title_book_suggestion)).setContentText(content); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(content)); builder.setContentIntent(PendingIntent.getActivity(this, 0, HomeActivity.createFor(this, book), PendingIntent.FLAG_UPDATE_CURRENT)); // ONLY 4 WEARABLE(s) final NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); // SECOND PAGE WITH BOOK DESCRIPTION wearableExtender .addPage(new NotificationCompat.Builder(this).setContentTitle(getString(R.string.description)) .setStyle(new NotificationCompat.BigTextStyle().bigText(book.getDescrition())).build()); wearableExtender.setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.background)); // ACTION TO PURCHASE A BOOK FROM A WEARABLE final PendingIntent purchaseIntent = PendingIntent.getService(this, 0, BookActionService.IntentBuilder .buy(this, book).notificationId(ID_SUGGESTION).wearableInput().build(), PendingIntent.FLAG_UPDATE_CURRENT); wearableExtender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_action_buy, getString(R.string.action_buy), purchaseIntent).build()); // ACTION TO ADD NOTES VIA VOICE REPLY final RemoteInput input = BookActionService.RemoteInputBuilder.create(this) .options(R.array.note_options).build(); final PendingIntent notesIntent = PendingIntent .getService( this, 0, BookActionService.IntentBuilder.addNote(this, book) .notificationId(ID_SUGGESTION).wearableInput().build(), PendingIntent.FLAG_UPDATE_CURRENT); wearableExtender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_action_notes, getString(R.string.action_notes), notesIntent).addRemoteInput(input).build()); // Finally extending the notification builder.extend(wearableExtender); // Sending the notification NotificationManagerCompat.from(this).notify(ID_SUGGESTION, builder.build()); } // Completing the Wakeful Intent SuggestionReceiver.completeWakefulIntent(intent); }
From source file:com.appsaur.tarucassist.AlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { int mReceivedID = Integer.parseInt(intent.getStringExtra(BaseActivity.EXTRA_REMINDER_ID)); // Get notification title from Reminder Database ScheduleReminderDataSource scheduleReminderDataSource = new ScheduleReminderDataSource(context); StudentScheduleDataSource studentScheduleDataSource = new StudentScheduleDataSource(context); studentScheduleDataSource.open();/*from ww w .j a v a 2s . com*/ ScheduleReminder scheduleReminder = scheduleReminderDataSource.getScheduleReminder(mReceivedID); String mTitle = scheduleReminder.getTitle(); int scheduleId = scheduleReminder.getScheduleId(); mCalendar = Calendar.getInstance(); String scheduleDate = studentScheduleDataSource.getCancelledScheduleById(scheduleId, BaseActivity.dateFormat.format(mCalendar.getTime())); if (!scheduleDate.equals("")) mTitle = mTitle + " - Cancelled"; // Create intent to open ReminderEditActivity on notification click Intent editIntent = new Intent(context, ViewScheduleActivity.class); editIntent.putExtra(BaseActivity.KEY_SCHEDULE_ID, Integer.toString(scheduleId)); PendingIntent mClick = PendingIntent.getActivity(context, mReceivedID, editIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Create Notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) .setSmallIcon(R.drawable.ic_timetable_white) .setContentTitle(context.getResources().getString(R.string.app_name)).setTicker(mTitle) .setContentText(mTitle).setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setContentIntent(mClick).setAutoCancel(true).setOnlyAlertOnce(true); NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nManager.notify(mReceivedID, mBuilder.build()); }
From source file:cn.apputest.ctria.service.UploadFailRecordService.java
public static void setServiceAlarm(Context context) { Log.i("ServiceUtil-AlarmManager", "invokeTimerPOIService wac called.."); PendingIntent alarmSender = null;/* w w w . j a va2 s.co m*/ Intent startIntent = new Intent(context, UploadFailRecordService.class); startIntent.setAction(Constants.POI_SERVICE_ACTION); try { alarmSender = PendingIntent.getService(context, 0, startIntent, PendingIntent.FLAG_UPDATE_CURRENT); } catch (Exception e) { Log.i("ServiceUtil-AlarmManager", "failed to start " + e.toString()); } AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), Constants.ELAPSED_TIME_F, alarmSender); }