List of usage examples for android.app PendingIntent FLAG_CANCEL_CURRENT
int FLAG_CANCEL_CURRENT
To view the source code for android.app PendingIntent FLAG_CANCEL_CURRENT.
Click Source Link
From source file:Main.java
public static synchronized long setServiceAlarm(Context context, Intent intent, long timeInterval, int identifier) { final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent pi = PendingIntent.getService(context, identifier, intent, PendingIntent.FLAG_CANCEL_CURRENT); return setUpAlarm(am, pi, timeInterval); }
From source file:Main.java
public static synchronized long setBroadcastAlarm(Context context, Intent intent, long timeInterval, int identifier) { final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final PendingIntent pi = PendingIntent.getBroadcast(context, identifier, intent, PendingIntent.FLAG_CANCEL_CURRENT); return setUpAlarm(am, pi, timeInterval); }
From source file:com.secupwn.aimsicd.utils.MiscUtils.java
public static void showNotification(Context context, String tickertext, String contentText, @DrawableRes int drawable_id, boolean auto_cancel) { int NOTIFICATION_ID = 1; Intent notificationIntent = new Intent(context, MainActivity.class); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_FROM_BACKGROUND); PendingIntent contentIntent = PendingIntent.getActivity(context, NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), drawable_id); Notification notification = new NotificationCompat.Builder(context).setSmallIcon(drawable_id) .setLargeIcon(largeIcon).setTicker(tickertext) .setContentTitle(context.getResources().getString(R.string.main_app_name)) .setContentText(contentText).setOngoing(true).setAutoCancel(auto_cancel) .setContentIntent(contentIntent).build(); NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, notification); }
From source file:org.openintents.safe.service.ServiceNotification.java
@SuppressLint("NewApi") public static void setNotification(Context context) { // look up the notification manager service mNotifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(context, LogOffActivity.class); PendingIntent pi = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Set the info for the views that show in the notification // panel./* w ww. jav a2 s . co m*/ if (debug) { Log.d(TAG, "builder=" + CheckWrappers.mNotificationBuilderAvailable); } if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) || (CheckWrappers.mNotificationBuilderAvailable == false)) { notificationCompat = new NotificationCompat.Builder(context) .setContentTitle(context.getString(R.string.app_name)) .setContentText(context.getString(R.string.notification_msg)).setSmallIcon(R.drawable.passicon) .setOngoing(true).setContentIntent(pi); mNotifyManager.notify(NOTIFICATION_ID, notificationCompat.build()); } else { if (debug) { Log.d(TAG, "we have progress"); } // The NotificationCompat library doesn't really have a // setProgress(), so only do // that for Ice Cream Sandwich and above wrapBuilder = new WrapNotificationBuilder(context); wrapBuilder.setContentTitle(context.getString(R.string.app_name)); wrapBuilder.setContentText(context.getString(R.string.notification_msg)); wrapBuilder.setSmallIcon(R.drawable.passicon); wrapBuilder.setOngoing(true); wrapBuilder.setContentIntent(pi); wrapBuilder.setProgress(100, 0, false); wrapBuilder.notifyManager(mNotifyManager, NOTIFICATION_ID); } }
From source file:com.alchemiasoft.book.receiver.SuggestionReceiver.java
/** * Schedule a suggestion alarm.// w w w. j av a2 s .c om * * @param context reference. * @return true if the alarm has been successfully scheduled, false otherwise. */ public static boolean scheduleSuggestion(Context context) { final AlarmManager alarmManager = AlarmUtil.getAlarmManager(context); if (sPendingIntent != null) { alarmManager.cancel(sPendingIntent); } final UserData userData = UserData.load(context); final UserData.SuggestionInterval interval = userData.suggestionInterval(); if (interval == UserData.SuggestionInterval.NEVER) { return false; } final Intent intent = new Intent(SUGGESTION_ACTION); sPendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); final long refreshInMills = interval.seconds() * DateUtils.SECOND_IN_MILLIS; Log.d(TAG_LOG, "AlarmReceiver: scheduling suggestion in " + interval.seconds() + " sec(s)."); alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + refreshInMills, sPendingIntent); return true; }
From source file:fr.paug.droidcon.ui.debug.actions.ShowSessionNotificationDebugAction.java
@Override public void run(Context context, Callback callback) { Intent i = new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri("__keynote__")); PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); //= PendingIntent.getActivity(context, 0, mapIntent, 0); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context) .setContentTitle("test notification").setContentText("yep, this is a test") .setTicker("hey, you got a test") .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true); NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder) .setBigContentTitle(/*from w w w .ja va2 s. c om*/ context.getResources().getQuantityString(R.plurals.session_notification_title, 1, 8, 1)); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(32534, richNotification.build()); }
From source file:fr.simon.marquis.secretcodes.ui.CrawlerNotification.java
public static void notify(final Context context, final ArrayList<SecretCode> secretCodes, final int progress) { final Resources res = context.getResources(); final String title = res.getString(R.string.crawler_notification_title); final String text = res.getString(R.string.crawler_notification_placeholder_text); Intent cancelIntent = new Intent(context, CrawlerService.class); cancelIntent.putExtra(CrawlerService.CANCEL_ACTION, true); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_stat_crawler).setContentTitle(title).setContentText(text) .setPriority(NotificationCompat.PRIORITY_DEFAULT).setProgress(100, progress, progress == 0) .setTicker(title + "\n" + text).setNumber(secretCodes.size()) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)) .addAction(R.drawable.ic_action_cancel, res.getString(R.string.action_cancel), PendingIntent.getService(context, 0, cancelIntent, PendingIntent.FLAG_CANCEL_CURRENT)) .setAutoCancel(false);/*w ww. j av a 2 s . c o m*/ notify(context, builder.build()); }
From source file:com.android.example.notificationshowcase.NotificationService.java
private static PendingIntent makeEmailIntent(Context context, String who) { final Intent intent = new Intent(android.content.Intent.ACTION_SENDTO, Uri.parse("mailto:" + who)); return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.saarang.samples.apps.iosched.ui.debug.actions.ShowSessionNotificationDebugAction.java
@Override public void run(Context context, Callback callback) { Intent i = new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri("__keynote__")); PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); Intent mapIntent = new Intent(context, UIUtils.getMapActivityClass(context)); mapIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME); mapIntent.putExtra(BaseMapActivity.EXTRA_ROOM, "keynote"); PendingIntent piMap = TaskStackBuilder.create(context).addNextIntent(mapIntent).getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); //= PendingIntent.getActivity(context, 0, mapIntent, 0); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context) .setContentTitle("test notification").setContentText("yep, this is a test") .setTicker("hey, you got a test") .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setSmallIcon(com.saarang.samples.apps.iosched.R.drawable.ic_stat_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true); notifBuilder.addAction(com.saarang.samples.apps.iosched.R.drawable.ic_map_holo_dark, context.getString(com.saarang.samples.apps.iosched.R.string.title_map), piMap); NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder) .setBigContentTitle(context.getResources().getQuantityString( com.saarang.samples.apps.iosched.R.plurals.session_notification_title, 1, 8, 1)); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(32534, richNotification.build()); }
From source file:com.google.samples.apps.iosched.debug.actions.ShowSessionNotificationDebugAction.java
@Override public void run(Context context, Callback callback) { Intent i = new Intent(Intent.ACTION_VIEW, ScheduleContract.Sessions.buildSessionUri("__keynote__")); PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); Intent mapIntent = new Intent(context, MapActivity.class); mapIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME); mapIntent.putExtra(MapActivity.EXTRA_ROOM, "keynote"); PendingIntent piMap = TaskStackBuilder.create(context).addNextIntent(mapIntent).getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); //= PendingIntent.getActivity(context, 0, mapIntent, 0); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context) .setContentTitle("test notification").setContentText("yep, this is a test") .setTicker("hey, you got a test") .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE) .setSmallIcon(R.drawable.ic_stat_notification).setContentIntent(pi) .setPriority(Notification.PRIORITY_MAX).setAutoCancel(true); notifBuilder.addAction(R.drawable.ic_map_holo_dark, context.getString(R.string.title_map), piMap); NotificationCompat.InboxStyle richNotification = new NotificationCompat.InboxStyle(notifBuilder) .setBigContentTitle(/*from w w w . ja va 2s . c o m*/ context.getResources().getQuantityString(R.plurals.session_notification_title, 1, 8, 1)); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(32534, richNotification.build()); }