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:org.dmfs.tasks.notification.NotificationUpdaterService.java
public static PendingIntent getUnpinActionIntent(Context context, int notificationId, Uri taskUri) { final Intent intent = new Intent(context, NotificationUpdaterService.class); intent.setAction(NotificationUpdaterService.ACTION_UNPIN); intent.setPackage(context.getPackageName()); intent.setData(taskUri);// w w w . j ava 2s. c o m intent.putExtra(EXTRA_NOTIFICATION_ID, notificationId); final PendingIntent pendingIntent = PendingIntent.getService(context, REQUEST_CODE_UNPIN, intent, PendingIntent.FLAG_CANCEL_CURRENT); return pendingIntent; }
From source file:com.irccloud.android.Notifications.java
@SuppressLint("NewApi") private android.app.Notification buildNotification(String ticker, int bid, long[] eids, String title, String text, Spanned big_text, int count, Intent replyIntent, Spanned wear_text, String network, String auto_messages[]) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()); NotificationCompat.Builder builder = new NotificationCompat.Builder( IRCCloudApplication.getInstance().getApplicationContext()) .setContentTitle(title + ((network != null) ? (" (" + network + ")") : "")) .setContentText(Html.fromHtml(text)).setAutoCancel(true).setTicker(ticker) .setWhen(eids[0] / 1000).setSmallIcon(R.drawable.ic_stat_notify) .setColor(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getColor(R.color.dark_blue)) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setPriority(NotificationCompat.PRIORITY_HIGH).setOnlyAlertOnce(false); if (ticker != null && (System.currentTimeMillis() - prefs.getLong("lastNotificationTime", 0)) > 10000) { if (prefs.getBoolean("notify_vibrate", true)) builder.setDefaults(android.app.Notification.DEFAULT_VIBRATE); String ringtone = prefs.getString("notify_ringtone", "content://settings/system/notification_sound"); if (ringtone != null && ringtone.length() > 0) builder.setSound(Uri.parse(ringtone)); }//from w w w. ja va 2 s .c om int led_color = Integer.parseInt(prefs.getString("notify_led_color", "1")); if (led_color == 1) { if (prefs.getBoolean("notify_vibrate", true)) builder.setDefaults( android.app.Notification.DEFAULT_LIGHTS | android.app.Notification.DEFAULT_VIBRATE); else builder.setDefaults(android.app.Notification.DEFAULT_LIGHTS); } else if (led_color == 2) { builder.setLights(0xFF0000FF, 500, 500); } SharedPreferences.Editor editor = prefs.edit(); editor.putLong("lastNotificationTime", System.currentTimeMillis()); editor.commit(); Intent i = new Intent(); i.setComponent(new ComponentName(IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), "com.irccloud.android.MainActivity")); i.putExtra("bid", bid); i.setData(Uri.parse("bid://" + bid)); Intent dismiss = new Intent(IRCCloudApplication.getInstance().getApplicationContext().getResources() .getString(R.string.DISMISS_NOTIFICATION)); dismiss.setData(Uri.parse("irccloud-dismiss://" + bid)); dismiss.putExtra("bid", bid); dismiss.putExtra("eids", eids); PendingIntent dismissPendingIntent = PendingIntent.getBroadcast( IRCCloudApplication.getInstance().getApplicationContext(), 0, dismiss, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent( PendingIntent.getActivity(IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); builder.setDeleteIntent(dismissPendingIntent); if (replyIntent != null) { WearableExtender extender = new WearableExtender(); PendingIntent replyPendingIntent = PendingIntent.getService( IRCCloudApplication.getInstance().getApplicationContext(), bid + 1, replyIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_CANCEL_CURRENT); extender.addAction( new NotificationCompat.Action.Builder(R.drawable.ic_reply, "Reply", replyPendingIntent) .addRemoteInput( new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()) .build()); if (count > 1 && wear_text != null) extender.addPage( new NotificationCompat.Builder(IRCCloudApplication.getInstance().getApplicationContext()) .setContentText(wear_text).extend(new WearableExtender().setStartScrollBottom(true)) .build()); NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( title + ((network != null) ? (" (" + network + ")") : "")) .setReadPendingIntent(dismissPendingIntent).setReplyAction(replyPendingIntent, new RemoteInput.Builder("extra_reply").setLabel("Reply to " + title).build()); if (auto_messages != null) { for (String m : auto_messages) { if (m != null && m.length() > 0) { unreadConvBuilder.addMessage(m); } } } else { unreadConvBuilder.addMessage(text); } unreadConvBuilder.setLatestTimestamp(eids[count - 1] / 1000); builder.extend(extender) .extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build())); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) { i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); builder.addAction(R.drawable.ic_action_reply, "Quick Reply", quickReplyIntent); } android.app.Notification notification = builder.build(); RemoteViews contentView = new RemoteViews( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification); contentView.setTextViewText(R.id.title, title + " (" + network + ")"); contentView.setTextViewText(R.id.text, (count == 1) ? Html.fromHtml(text) : (count + " unread highlights.")); contentView.setLong(R.id.time, "setTime", eids[0] / 1000); notification.contentView = contentView; if (Build.VERSION.SDK_INT >= 16 && big_text != null) { RemoteViews bigContentView = new RemoteViews( IRCCloudApplication.getInstance().getApplicationContext().getPackageName(), R.layout.notification_expanded); bigContentView.setTextViewText(R.id.title, title + (!title.equals(network) ? (" (" + network + ")") : "")); bigContentView.setTextViewText(R.id.text, big_text); bigContentView.setLong(R.id.time, "setTime", eids[0] / 1000); if (count > 3) { bigContentView.setViewVisibility(R.id.more, View.VISIBLE); bigContentView.setTextViewText(R.id.more, "+" + (count - 3) + " more"); } else { bigContentView.setViewVisibility(R.id.more, View.GONE); } if (replyIntent != null && prefs.getBoolean("notify_quickreply", true)) { bigContentView.setViewVisibility(R.id.actions, View.VISIBLE); bigContentView.setViewVisibility(R.id.action_divider, View.VISIBLE); i = new Intent(IRCCloudApplication.getInstance().getApplicationContext(), QuickReplyActivity.class); i.setData(Uri.parse("irccloud-bid://" + bid)); i.putExtras(replyIntent); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent quickReplyIntent = PendingIntent.getActivity( IRCCloudApplication.getInstance().getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT); bigContentView.setOnClickPendingIntent(R.id.action_reply, quickReplyIntent); } notification.bigContentView = bigContentView; } return notification; }
From source file:com.wheelphone.remotemini.WheelphoneRemoteMini.java
public void onStart() { if (debugUsbComm) { logString = TAG + ": onStart"; Log.d(TAG, logString);//from www.j av a 2s .co m appendLog("debugUsbComm.txt", logString, false); } super.onStart(); // Lock screen wl.acquire(); Intent notificationIntent = new Intent(this, WheelphoneRemoteMini.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification.Builder builder = new Notification.Builder(this); builder.setContentIntent(pendingIntent).setWhen(System.currentTimeMillis()) .setTicker(getText(R.string.notification_title)) .setSmallIcon(R.drawable.wheelphone_logo_remote_mini_small) .setContentTitle(getText(R.string.notification_title)) .setContentText(getText(R.string.notification_content)); Notification notification = builder.getNotification(); notification.flags |= Notification.FLAG_ONGOING_EVENT; ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification); }
From source file:com.google.samples.apps.iosched.service.SessionAlarmService.java
private PendingIntent createRoomMapIntent(final String roomId) { Intent mapIntent = new Intent(getApplicationContext(), MapActivity.class); mapIntent.putExtra(MapActivity.EXTRA_ROOM, roomId); mapIntent.putExtra(MapActivity.EXTRA_DETACHED_MODE, true); return TaskStackBuilder.create(getApplicationContext()) .addNextIntent(new Intent(this, ExploreIOActivity.class)).addNextIntent(mapIntent) .getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.mobilyzer.MeasurementScheduler.java
public synchronized String submitTask(MeasurementTask newTask) { // TODO check if scheduler is running... // and there is a current running/scheduled task String newTaskId = newTask.getTaskId(); tasksStatus.put(newTaskId, TaskStatus.SCHEDULED); idToClientKey.put(newTaskId, newTask.getKey()); Logger.d("MeasurementScheduler --> submitTask: " + newTask.getDescription().key + " " + newTaskId); MeasurementTask current;// ww w. ja va 2 s. com if (getCurrentTask() != null) { current = getCurrentTask(); Logger.d("submitTask: current is NOT null"); } else { current = null; Logger.d("submitTask: current is null"); } // preemption condition if (current != null && newTask.getDescription().priority < current.getDescription().priority && new Date(current.getDuration() + getCurrentTaskStartTime().getTime()) .after(newTask.getDescription().endTime)) { Logger.d("submitTask: trying to cancel/preempt the task"); // finding the current instance in pending tasks. we can call // pause on that instance only if (pendingTasks.containsKey(current)) { for (MeasurementTask mt : pendingTasks.keySet()) { if (current.equals(mt)) { current = mt; break; } } Logger.e("Cancelling Current Task"); if (current instanceof PreemptibleMeasurementTask && ((PreemptibleMeasurementTask) current).pause()) { pendingTasks.remove(current); ((PreemptibleMeasurementTask) current).updateTotalRunningTime( System.currentTimeMillis() - getCurrentTaskStartTime().getTime()); if (newTask.timeFromExecution() <= 0) { mainQueue.add(newTask); mainQueue.add(current); handleMeasurement(); } else { mainQueue.add(newTask); mainQueue.add(current); long timeFromExecution = newTask.timeFromExecution(); measurementIntentSender = PendingIntent.getBroadcast(this, 0, new UpdateIntent(UpdateIntent.MEASUREMENT_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeFromExecution, measurementIntentSender); setCurrentTask(newTask); setCurrentTaskStartTime(new Date(System.currentTimeMillis() + timeFromExecution)); } } else if (current.stop()) { pendingTasks.remove(current); if (newTask.timeFromExecution() <= 0) { mainQueue.add(newTask); mainQueue.add(current); handleMeasurement(); } else { mainQueue.add(newTask); mainQueue.add(current); long timeFromExecution = newTask.timeFromExecution(); measurementIntentSender = PendingIntent.getBroadcast(this, 0, new UpdateIntent(UpdateIntent.MEASUREMENT_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeFromExecution, measurementIntentSender); // setCurrentTask(null); setCurrentTask(newTask); setCurrentTaskStartTime(new Date(System.currentTimeMillis() + timeFromExecution)); } } else { mainQueue.add(newTask); } } else { alarmManager.cancel(measurementIntentSender); if (newTask.timeFromExecution() <= 0) { mainQueue.add(newTask); handleMeasurement(); } else { mainQueue.add(newTask); long timeFromExecution = newTask.timeFromExecution(); measurementIntentSender = PendingIntent.getBroadcast(this, 0, new UpdateIntent(UpdateIntent.MEASUREMENT_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + timeFromExecution, measurementIntentSender); // setCurrentTask(null); setCurrentTask(newTask); setCurrentTaskStartTime(new Date(System.currentTimeMillis() + timeFromExecution)); } } } else { Logger.d("submitTask: adding to mainqueue"); mainQueue.add(newTask); if (current == null) { Logger.d("submitTask: adding to mainqueue, current is null"); Logger.d("submitTask: calling handleMeasurement"); alarmManager.cancel(measurementIntentSender); handleMeasurement(); } else { Logger.d("submitTask: adding to mainqueue, current is not null: " + current.getMeasurementType() + " " + getCurrentTaskStartTime()); if (pendingTasks.containsKey(current)) { Logger.d("submitTask: isDone?" + pendingTasks.get(current).isDone()); if (pendingTasks.get(current).isDone()) { alarmManager.cancel(measurementIntentSender); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 3 * 1000, measurementIntentSender); } else if (getCurrentTaskStartTime() != null) { if (!current.getMeasurementType().equals(RRCTask.TYPE) && new Date(System.currentTimeMillis() - Config.MAX_TASK_DURATION) .after(getCurrentTaskStartTime())) { Logger.d("submitTask: 1"); pendingTasks.get(current).cancel(true); handleMeasurement(); } else if (current.getMeasurementType().equals(RRCTask.TYPE) && new Date( System.currentTimeMillis() - (Config.DEFAULT_RRC_TASK_DURATION + 15 * 60 * 1000)) .after(getCurrentTaskStartTime())) { Logger.d("submitTask: 2"); pendingTasks.get(current).cancel(true); handleMeasurement(); } else { Logger.d("submitTask: 3"); alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + Config.MAX_TASK_DURATION / 2, measurementIntentSender); } } } else { Logger.d("submitTask: not found in pending task"); handleMeasurement(); } } } return newTaskId; }
From source file:co.taqat.call.assistant.AssistantActivity.java
public void restartApplication() { mPrefs.firstLaunchSuccessful();/*from w ww. j a v a 2 s . co m*/ Intent mStartActivity = new Intent(this, LinphoneLauncherActivity.class); PendingIntent mPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 500, mPendingIntent); stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class)); android.os.Process.killProcess(android.os.Process.myPid()); }
From source file:org.dmfs.tasks.notification.NotificationUpdaterService.java
private static PendingIntent getDelayActionIntent(Context context, int notificationId, Uri taskUri, long due, boolean delay1h, String timezone, boolean allday) { String action = null;/*from w ww .j a v a 2s . c o m*/ if (delay1h) { action = ACTION_DELAY_1H; } else { action = ACTION_DELAY_1D; } final Intent intent = new Intent(context, NotificationUpdaterService.class); intent.setAction(action); intent.setPackage(context.getPackageName()); intent.setData(taskUri); intent.putExtra(EXTRA_TASK_DUE, due); intent.putExtra(EXTRA_TIMEZONE, timezone); intent.putExtra(EXTRA_ALLDAY, allday); intent.putExtra(EXTRA_NOTIFICATION_ID, notificationId); final PendingIntent pendingIntent = PendingIntent.getService(context, REQUEST_CODE_DELAY, intent, PendingIntent.FLAG_CANCEL_CURRENT); return pendingIntent; }
From source file:com.SecUpwN.AIMSICD.service.AimsicdService.java
/** * Set or update the Notification//from w w w .jav a 2 s . c o m */ public void setNotification() { String tickerText; String contentText = "Phone Type " + mDevice.getPhoneType(); String iconType = prefs.getString(this.getString(R.string.pref_ui_icons_key), "sense"); int status; if (mFemtoDetected || mTypeZeroSmsDetected) { status = 4; //ALARM } else if (mChangedLAC) { status = 3; //MEDIUM contentText = "Hostile Service Area: Changing LAC Detected"; } else if (mTrackingFemtocell || mTrackingCell || mLoaded) { status = 2; //NORMAL if (mTrackingFemtocell) { contentText = "FemtoCell Detection Active"; } else if (mTrackingCell) { contentText = "Cell Tracking Active"; } } else { status = 1; //IDLE } int icon = R.drawable.sense_idle; switch (status) { case 1: //IDLE switch (iconType) { case "flat": icon = R.drawable.flat_idle; break; case "sense": icon = R.drawable.sense_idle; break; case "white": icon = R.drawable.white_idle; break; } tickerText = getResources().getString(R.string.app_name_short) + " - Status: Idle"; break; case 2: //NORMAL switch (iconType) { case "flat": icon = R.drawable.flat_ok; break; case "sense": icon = R.drawable.sense_ok; break; case "white": icon = R.drawable.white_ok; break; } tickerText = getResources().getString(R.string.app_name_short) + " - Status: Good No Threats Detected"; break; case 3: //MEDIUM switch (iconType) { case "flat": icon = R.drawable.flat_medium; break; case "sense": icon = R.drawable.sense_medium; break; case "white": icon = R.drawable.white_medium; break; } tickerText = getResources().getString(R.string.app_name_short) + " - Hostile Service Area: Changing LAC Detected"; break; case 4: //DANGER switch (iconType) { case "flat": icon = R.drawable.flat_danger; break; case "sense": icon = R.drawable.sense_danger; break; case "white": icon = R.drawable.white_danger; break; } tickerText = getResources().getString(R.string.app_name_short) + " - ALERT!! Threat Detected"; if (mFemtoDetected) { contentText = "ALERT!! FemtoCell Connection Threat Detected"; } else if (mTypeZeroSmsDetected) { contentText = "ALERT!! Type Zero Silent SMS Intercepted"; } break; default: icon = R.drawable.sense_idle; tickerText = getResources().getString(R.string.app_name); break; } Intent notificationIntent = new Intent(mContext, AIMSICD.class); notificationIntent.putExtra("silent_sms", mTypeZeroSmsDetected); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_FROM_BACKGROUND); PendingIntent contentIntent = PendingIntent.getActivity(mContext, NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification mBuilder = new NotificationCompat.Builder(this).setSmallIcon(icon).setTicker(tickerText) .setContentTitle(this.getResources().getString(R.string.app_name)).setContentText(contentText) .setOngoing(true).setAutoCancel(false).setContentIntent(contentIntent).build(); NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(NOTIFICATION_ID, mBuilder); }
From source file:net.lp.hivawareness.v4.HIVAwarenessActivity.java
private void finishGame(boolean infected, int whenInfected) { String msg;/*www .j a va 2 s . co m*/ if (infected && whenInfected == 0) { msg = getString(R.string.infected_at_beginning); } else if (infected) { msg = getString(R.string.infected_when, whenInfected); } else { msg = getString(R.string.not_infected); } Intent intent = new Intent(this, AlertReceiver.class); intent.putExtra("message", msg); PendingIntent operation = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC, System.currentTimeMillis(), operation); // clear history SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE); Editor editor = prefs.edit(); editor.remove(PREFS_HISTORY); editor.remove(PREFS_HISTORY_INFECTED); editor.apply(); HIVAwarenessActivity.dataChanged(); }
From source file:com.mine.psf.PsfPlaybackService.java
private void notifyPlaying() { Intent notificationIntent = new Intent(this, PsfPlaybackActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); NotificationCompat.Builder builder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_psfplaying).setContentTitle(getAlbumName()) .setContentText(getTrackName()); builder.setContentIntent(contentIntent); // Next button, only work after v11 Intent nextTrackIntent = new Intent(this, PsfPlaybackService.class); nextTrackIntent.setAction(ACTION_CMD); nextTrackIntent.putExtra(CMDNAME, CMDNEXT); PendingIntent nextTrackPendingIntent = PendingIntent.getService(this, 0, nextTrackIntent, PendingIntent.FLAG_CANCEL_CURRENT); // Prev button // Intent pauseTrackIntent = new Intent(this, PsfPlaybackService.class); // pauseTrackIntent.setAction(ACTION_CMD); // pauseTrackIntent.putExtra(CMDNAME, CMDPAUSE); // PendingIntent pauseTrackPendingIntent = // PendingIntent.getService(this, 1, pauseTrackIntent, PendingIntent.FLAG_CANCEL_CURRENT); // Prev button Intent prevTrackIntent = new Intent(this, PsfPlaybackService.class); prevTrackIntent.setAction(ACTION_CMD); prevTrackIntent.putExtra(CMDNAME, CMDPREV); PendingIntent prevTrackPendingIntent = PendingIntent.getService(this, 2, prevTrackIntent, PendingIntent.FLAG_CANCEL_CURRENT); builder.addAction(android.R.drawable.ic_media_previous, "Prev", prevTrackPendingIntent); // builder.addAction(android.R.drawable.ic_media_pause, "", pauseTrackPendingIntent); builder.addAction(android.R.drawable.ic_media_next, "Next", nextTrackPendingIntent); startForeground(PLAYBACKSERVICE_STATUS, builder.build()); }