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:com.android.settings.slim.service.AlarmService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { try {/* w w w . ja v a2 s. c o m*/ startAlarmSound(); } catch (Exception e) { // Do nothing } Bundle extras = intent.getExtras(); String names = extras.getString("number"); String title = getResources().getString(R.string.quiet_hours_alarm_dialog_title); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_quiethours); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setTicker(title) .setContentTitle(title).setContentText(names).setAutoCancel(false).setOngoing(true) .setSmallIcon(R.drawable.ic_quiethours).setLargeIcon(bm) .setStyle(new NotificationCompat.BigTextStyle() .bigText(names + getResources().getString(R.string.quiet_hours_alarm_message))); Intent alarmDialog = new Intent(); alarmDialog.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); alarmDialog.setClass(this, com.android.settings.slim.service.BypassAlarm.class); alarmDialog.putExtra("number", names); alarmDialog.putExtra("norun", true); PendingIntent result = PendingIntent.getActivity(this, 0, alarmDialog, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(result); mManager.notify(NOTI_ID, builder.build()); return START_STICKY; }
From source file:com.company.millenium.iwannask.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param data GCM message received./*from ww w. ja va 2 s. co m*/ */ private void sendNotification(Bundle data) { String question_body = data.getString("question_body"); String answer_body = data.getString("answer_body"); String question_id = data.getString("question_id"); //String answer_id = data.getString("answer_id"); String user_name = data.getString("user_name"); if (user_name != null && user_name.contains(" ")) { user_name = user_name.split(" ")[0]; } String type = data.getString("type"); Intent intent = new Intent(this, MainActivity.class); intent.putExtra("url", "/questions/" + question_id); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_CANCEL_CURRENT); String info = " answered:"; if (type != null && type.contentEquals("answer_feedback")) { String isLiked = data.getString("feedback_value"); info = " disliked your answer"; if (isLiked != null && isLiked.equals("true")) { info = " liked your answer"; } } else if (type != null && type.contentEquals("question_answer_op")) { info = " commented on"; } Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_comment_question_outline_grey600_36dp).setContentTitle(user_name + info) .setContentText(question_body) .setStyle(new NotificationCompat.BigTextStyle().bigText(question_body + "\n" + answer_body)) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(id, notificationBuilder.build()); id = id + 1; }
From source file:com.android.settings.beanstalk.service.AlarmService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { try {/* w w w . j a v a2 s.c o m*/ startAlarmSound(); } catch (Exception e) { // Do nothing } Bundle extras = intent.getExtras(); String names = extras.getString("number"); String title = getResources().getString(R.string.quiet_hours_alarm_dialog_title); Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_quiethours); NotificationCompat.Builder builder = new NotificationCompat.Builder(this).setTicker(title) .setContentTitle(title).setContentText(names).setAutoCancel(false).setOngoing(true) .setSmallIcon(R.drawable.ic_quiethours).setLargeIcon(bm) .setStyle(new NotificationCompat.BigTextStyle() .bigText(names + getResources().getString(R.string.quiet_hours_alarm_message))); Intent alarmDialog = new Intent(); alarmDialog.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); alarmDialog.setClass(this, com.android.settings.beanstalk.service.BypassAlarm.class); alarmDialog.putExtra("number", names); alarmDialog.putExtra("norun", true); PendingIntent result = PendingIntent.getActivity(this, 0, alarmDialog, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(result); mManager.notify(NOTI_ID, builder.build()); return START_STICKY; }
From source file:com.appsaur.tarucassist.AutomuteAlarmReceiver.java
public void setAlarm(Context context, Calendar calendar, int ID) { mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); // Put Reminder ID in Intent Extra Intent intent = new Intent(context, AutomuteAlarmReceiver.class); intent.putExtra(BaseActivity.EXTRA_REMINDER_ID, Integer.toString(ID)); mPendingIntent = PendingIntent.getBroadcast(context, ID, intent, PendingIntent.FLAG_CANCEL_CURRENT); // Calculate notification time Calendar c = Calendar.getInstance(); long currentTime = c.getTimeInMillis(); long diffTime = calendar.getTimeInMillis() - currentTime; // Start alarm using notification time mAlarmManager.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + diffTime, mPendingIntent); // Restart alarm if device is rebooted ComponentName receiver = new ComponentName(context, BootReceiver.class); PackageManager pm = context.getPackageManager(); pm.setComponentEnabledSetting(receiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP); }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.LinkObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject obj) { String mimeType = obj.optString(MIME_TYPE); Uri uri = Uri.parse(obj.optString(URI)); if (fileAvailable(mimeType, uri)) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.addCategory(Intent.CATEGORY_DEFAULT); i.setType(mimeType);//ww w .j a v a 2 s .c om i.setData(uri); i.putExtra(Intent.EXTRA_TEXT, uri); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT); (new PresenceAwareNotify(context)).notify("New content from Musubi", "New Content from Musubi", mimeType + " " + uri, contentIntent); } else { Log.w(TAG, "Received file, failed to handle: " + uri); } }
From source file:com.farmerbb.taskbar.service.NotificationService.java
@TargetApi(Build.VERSION_CODES.M) @Override// w ww. j a v a2 s.c o m public void onCreate() { super.onCreate(); SharedPreferences pref = U.getSharedPreferences(this); if (pref.getBoolean("taskbar_active", false)) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || Settings.canDrawOverlays(this)) { isHidden = U.getSharedPreferences(this).getBoolean("is_hidden", false); String label = getString(isHidden ? R.string.action_show : R.string.action_hide); Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); PendingIntent receiverIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.farmerbb.taskbar.SHOW_HIDE_TASKBAR"), PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent receiverIntent2 = PendingIntent.getBroadcast(this, 0, new Intent("com.farmerbb.taskbar.QUIT"), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(pref.getBoolean("app_drawer_icon", false) ? R.drawable.ic_system : R.drawable.ic_allapps) .setContentIntent(contentIntent).setContentTitle(getString(R.string.taskbar_is_active)) .setContentText(getString(R.string.click_to_open_settings)) .setColor(ContextCompat.getColor(this, R.color.colorPrimary)) .addAction(0, label, receiverIntent) .addAction(0, getString(R.string.action_quit), receiverIntent2) .setPriority(Notification.PRIORITY_MIN).setShowWhen(false).setOngoing(true); startForeground(8675309, mBuilder.build()); LocalBroadcastManager.getInstance(this) .sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_SWITCH")); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) TileService.requestListeningState(this, new ComponentName(BuildConfig.APPLICATION_ID, QuickSettingsTileService.class.getName())); if (!isHidden) { registerReceiver(userForegroundReceiver, new IntentFilter(Intent.ACTION_USER_FOREGROUND)); registerReceiver(userBackgroundReceiver, new IntentFilter(Intent.ACTION_USER_BACKGROUND)); } } else { pref.edit().putBoolean("taskbar_active", false).apply(); stopSelf(); } } else stopSelf(); }
From source file:com.otaupdater.utils.RomInfo.java
public void showUpdateNotif(Context ctx) { Intent mainInent = new Intent(ctx, TabDisplay.class); mainInent.setAction(TabDisplay.ROM_NOTIF_ACTION); this.addToIntent(mainInent); PendingIntent mainPIntent = PendingIntent.getActivity(ctx, 0, mainInent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlInent = new Intent(ctx, DownloadReceiver.class); dlInent.setAction(DownloadReceiver.DL_ROM_ACTION); this.addToIntent(dlInent); PendingIntent dlPIntent = PendingIntent.getBroadcast(ctx, 0, dlInent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx); builder.setContentIntent(mainPIntent); builder.setContentTitle(ctx.getString(R.string.notif_source)); builder.setContentText(ctx.getString(R.string.notif_text_rom)); builder.setTicker(ctx.getString(R.string.notif_text_rom)); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(R.drawable.updates); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(changelog)); builder.setPriority(NotificationCompat.PRIORITY_LOW); builder.addAction(R.drawable.ic_download_default, ctx.getString(R.string.notif_download), dlPIntent); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(Config.ROM_NOTIF_ID, builder.build()); }
From source file:com.otaupdater.DownloadReceiver.java
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == null) return;//from www . j a v a2 s. c om if (action.equals(DL_ROM_ACTION)) { RomInfo.FACTORY.clearUpdateNotif(context); RomInfo.FACTORY.fromIntent(intent).startDownload(context); } else if (action.equals(DL_KERNEL_ACTION)) { KernelInfo.FACTORY.clearUpdateNotif(context); KernelInfo.FACTORY.fromIntent(intent).startDownload(context); } else if (action.equals(CLEAR_DL_ACTION)) { if (intent.hasExtra(DownloadManager.EXTRA_DOWNLOAD_ID)) { DownloadManager dm = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE); dm.remove(intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)); DownloadBarFragment.notifyActiveFragment(); } } else if (action.equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)) { DownloadStatus status = DownloadStatus.forDownloadID(context, intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)); if (status == null) return; BaseInfo info = status.getInfo(); if (info == null) return; int error = status.getStatus() == DownloadManager.STATUS_SUCCESSFUL ? info.checkDownloadedFile() : status.getReason(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (error == 0) { Intent mainIntent = new Intent(context, OTAUpdaterActivity.class); mainIntent.setAction(info.getNotifAction()); mainIntent.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true); PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent flashIntent = new Intent(context, DownloadsActivity.class); flashIntent.setAction(info.getFlashAction()); info.addToIntent(flashIntent); PendingIntent flashPIntent = PendingIntent.getActivity(context, 0, flashIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notif = new NotificationCompat.Builder(context) .setTicker(context.getString(info.getDownloadDoneTitle())) .setContentTitle(context.getString(info.getDownloadDoneTitle())) .setSmallIcon(R.drawable.ic_stat_av_download) .setContentText(context.getString(R.string.notif_completed)).setContentIntent(mainPIntent) .addAction(R.drawable.ic_action_system_update, context.getString(R.string.install), flashPIntent) .build(); nm.notify(info.getFlashNotifID(), notif); } else { Intent mainIntent = new Intent(context, OTAUpdaterActivity.class); mainIntent.setAction(info.getNotifAction()); info.addToIntent(mainIntent); PendingIntent mainPIntent = PendingIntent.getActivity(context, 0, mainIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlIntent = new Intent(context, DownloadReceiver.class); dlIntent.setAction(info.getDownloadAction()); info.addToIntent(dlIntent); PendingIntent dlPIntent = PendingIntent.getBroadcast(context, 1, dlIntent, PendingIntent.FLAG_CANCEL_CURRENT); Intent clearIntent = new Intent(context, DownloadReceiver.class); clearIntent.setAction(CLEAR_DL_ACTION); clearIntent.putExtra(DownloadManager.EXTRA_DOWNLOAD_ID, status.getId()); PendingIntent clearPIntent = PendingIntent.getBroadcast(context, 2, clearIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification notif = new NotificationCompat.Builder(context) .setTicker(context.getString(info.getDownloadFailedTitle())) .setContentTitle(context.getString(info.getDownloadFailedTitle())) .setContentText(status.getErrorString(context)).setSmallIcon(R.drawable.ic_stat_warning) .setContentIntent(mainPIntent).setDeleteIntent(clearPIntent) .addAction(R.drawable.ic_action_refresh, context.getString(R.string.retry), dlPIntent) .build(); nm.notify(info.getFailedNotifID(), notif); } } else if (action.equals(DownloadManager.ACTION_NOTIFICATION_CLICKED)) { long[] ids = intent.getLongArrayExtra(DownloadManager.EXTRA_NOTIFICATION_CLICK_DOWNLOAD_IDS); if (ids.length == 0) return; DownloadStatus status = DownloadStatus.forDownloadID(context, ids[0]); if (status == null) return; BaseInfo info = status.getInfo(); if (info == null) return; Intent i = new Intent(context, OTAUpdaterActivity.class); i.setAction(info.getNotifAction()); i.putExtra(OTAUpdaterActivity.EXTRA_FLAG_DOWNLOAD_DIALOG, true); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } }
From source file:org.qeo.deviceregistration.ui.NotificationHelper.java
private void localDeviceRegistered(Context context, Intent intent) { LOG.fine("publishing notification for local device"); String username = intent.getStringExtra(RegisterService.INTENT_EXTRA_USERNAME); String realmName = intent.getStringExtra(RegisterService.INTENT_EXTRA_REALMNAME); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(R.drawable.ic_stat_qeo); builder.setContentTitle(context.getString(R.string.notification_device_registered)); builder.setContentText(username + " in realm " + realmName); builder.setAutoCancel(true);//ww w . jav a 2 s . co m // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainActivity.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(MainActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent( ServiceApplication.REQUEST_CODE_DEVICE_REGISTERED, PendingIntent.FLAG_CANCEL_CURRENT); builder.setContentIntent(resultPendingIntent); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // mId allows you to update the notification later on. notificationManager.notify(ServiceApplication.NOTIFICATION_DEVICE_REGISTERED, builder.build()); }
From source file:com.otaupdater.utils.KernelInfo.java
public void showUpdateNotif(Context ctx) { Intent mainInent = new Intent(ctx, TabDisplay.class); mainInent.setAction(TabDisplay.KERNEL_NOTIF_ACTION); this.addToIntent(mainInent); PendingIntent mainPIntent = PendingIntent.getActivity(ctx, 0, mainInent, PendingIntent.FLAG_CANCEL_CURRENT); Intent dlInent = new Intent(ctx, DownloadReceiver.class); dlInent.setAction(DownloadReceiver.DL_KERNEL_ACTION); this.addToIntent(dlInent); PendingIntent dlPIntent = PendingIntent.getBroadcast(ctx, 0, dlInent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx); builder.setContentIntent(mainPIntent); builder.setContentTitle(ctx.getString(R.string.notif_source)); builder.setContentText(ctx.getString(R.string.notif_text_kernel)); builder.setTicker(ctx.getString(R.string.notif_text_kernel)); builder.setWhen(System.currentTimeMillis()); builder.setSmallIcon(R.drawable.updates); builder.setStyle(new NotificationCompat.BigTextStyle().bigText(changelog)); builder.setPriority(NotificationCompat.PRIORITY_LOW); builder.addAction(R.drawable.ic_download_default, ctx.getString(R.string.notif_download), dlPIntent); NotificationManager nm = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(Config.KERNEL_NOTIF_ID, builder.build()); }