List of usage examples for android.app PendingIntent FLAG_ONE_SHOT
int FLAG_ONE_SHOT
To view the source code for android.app PendingIntent FLAG_ONE_SHOT.
Click Source Link
From source file:com.Wisam.passenger.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w w w .j a v a2 s .c om*/ private void sendNotification(String messageBody) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notification_logo).setContentTitle(getString(R.string.app_name)) .setContentText(messageBody).setAutoCancel(true).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.unfc.choicecustomercare.gcmservices.MyGcmListenerService.java
private void sendNotificationForTakeBreakAccept(String message, String fromId, String toId) { boolean loggedOut = CustomPreferences.getPreferences(Constants.PREF_LOGGED_OUT, false); Intent intent;//ww w.j a v a2 s . co m if (loggedOut) { intent = new Intent(this, LoginActivity.class); } else { intent = new Intent(this, MainActivity.class); } intent.setAction("takeBreakAccept"); intent.putExtra("fromId", fromId); intent.putExtra("toId", toId); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Intent intentAccept = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingAccept = PendingIntent.getActivity(this, 1, intentAccept, PendingIntent.FLAG_ONE_SHOT); // Intent intentDecline = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingDecline = PendingIntent.getActivity(this, 2, intentDecline, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(getString(R.string.app_name)) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent).setAutoCancel(true); notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL; notificationBuilder.setAutoCancel(true); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(Constants.TAKE_A_BREAK_NOTIFICATION_ID, notificationBuilder.build()); }
From source file:com.parrot.cyclops.CameraView.java
private void startCyclopsServiceForeground() { logdebug("startCyclopsServiceForeground"); SystemProperties.setTvBusyByCyclops(true); NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(mContext.getString(R.string.notif_title)) .setContentText(mContext.getString(R.string.notif_text)); PendingIntent pendingIntent;/*ww w.j a va 2 s. c o m*/ Intent intent = new Intent(mContext, CyclopsActivity.class); pendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); builder.setContentIntent(pendingIntent); builder.setPriority(NotificationCompat.PRIORITY_MAX); Notification notif = builder.build(); notif.flags = Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_NO_CLEAR; mCyclopsService.startForeground(Cyclops.CYCLOPS_FOREGROUND_NOTIFICATION, notif); }
From source file:com.zaparound.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w w w . j av a2 s .co m*/ private void sendNotificationZapRequest(String messagetitle, String messageBody) { Intent intent = new Intent(this, LandingActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("CHECKIN_TAB_POS", 1); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); Notification notification = mBuilder.setSmallIcon(R.drawable.applogo).setTicker(messagetitle).setWhen(0) .setAutoCancel(true).setContentTitle(messagetitle) //.setNumber(++count) .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody)) //.setSubText("\n "+count+" new messages\n") .setContentIntent(pendingIntent) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.applogo)) .setContentText(messageBody).build(); NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notification); }
From source file:com.piggeh.palmettoscholars.services.MyFirebaseMessagingService.java
public void notifyNewsletter(String title) { Intent contentIntent = new Intent(this, MainActivity.class); contentIntent.putExtra("navigation_page", MainActivity.PAGE_NEWSLETTER); contentIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 2 /* Request code */, contentIntent, PendingIntent.FLAG_ONE_SHOT); Intent settingsIntent = new Intent(this, SettingsActivity.class); settingsIntent.putExtra("navigation_page", MainActivity.PAGE_SETTINGS); settingsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent settingsPendingIntent = PendingIntent.getActivity(this, 3 /* Request code */, settingsIntent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.BigTextStyle notifStyle = new NotificationCompat.BigTextStyle(); notifStyle.bigText(title);/*from w w w . j a v a 2s . co m*/ notifStyle.setBigContentTitle(getString(R.string.notif_newsletter_title)); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.notification_icon_nodpi) .setContentTitle(getString(R.string.notif_newsletter_title)).setContentText(title) .setAutoCancel(true).setSound(defaultSoundUri) .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setContentIntent(contentPendingIntent) .setStyle(notifStyle).addAction(R.drawable.ic_notifications_off, getString(R.string.notif_action_options), settingsPendingIntent); // Get an instance of the NotificationManager service NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); // Build the notification and issues it with notification manager. notificationManager.notify(NOTIFICATION_ID_NEWSLETTER, notificationBuilder.build()); }
From source file:com.medicohealthcare.service.AlarmServer.java
public void setAlarm(Calendar calendar) { AlarmManager am = (AlarmManager) HomeActivity.getParentAtivity() .getSystemService(HomeActivity.getParentAtivity().getApplicationContext().ALARM_SERVICE); Intent intent = new Intent(HomeActivity.getParentAtivity(), AlarmService.class); long trigerTime = calendar.getTimeInMillis(); System.out.println("trigerTime = " + trigerTime); System.out.println("trigerTime current = " + Calendar.getInstance().getTimeInMillis()); PendingIntent pendingIntent = PendingIntent.getBroadcast(HomeActivity.getParentAtivity(), (int) trigerTime, intent, PendingIntent.FLAG_ONE_SHOT); am.set(AlarmManager.RTC_WAKEUP, trigerTime, pendingIntent); }
From source file:com.windroilla.invoker.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w ww . j a va 2 s.co m */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_ic_notification).setContentTitle("New Block Time") .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:io.github.hidroh.materialistic.data.ItemSyncAdapter.java
private PendingIntent getItemActivity(String itemId) { return PendingIntent.getActivity(getContext(), 0, new Intent(Intent.ACTION_VIEW).setData(AppUtils.createItemUri(itemId)) .putExtra(ItemActivity.EXTRA_CACHE_MODE, ItemManager.MODE_CACHE) .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), PendingIntent.FLAG_ONE_SHOT); }
From source file:com.android.settings.cyanogenmod.LtoService.java
private PendingIntent scheduleNextDownload(long lastDownload) { AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(this, LtoService.class); PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); long nextLtoDownload = lastDownload + LongTermOrbits.getDownloadInterval(); am.set(AlarmManager.RTC, nextLtoDownload, pi); return pi;//from w w w .ja va 2 s. c o m }
From source file:me.trashout.service.TrashHunterService.java
private void createNotification(int trashCount, int trashHunterArea) { Log.d("TrashHunter", ".....createNotification..... trashHunterArea - " + trashHunterArea); Intent viewIntent = BaseActivity.generateIntent(this, TrashListFragment.class.getName(), TrashListFragment.generateBundle(true, trashHunterArea), MainActivity.class); viewIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent viewPendingIntent = PendingIntent.getActivity(this, 0, viewIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); Context context = getBaseContext(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(getNotificationIcon()) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)) .setContentTitle(context.getString(R.string.app_name)) .setContentText(String.format(getString(R.string.notification_new_trash_formatter), trashCount)) .setAutoCancel(true).setContentIntent(viewPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notif = mBuilder.build(); notif.defaults |= Notification.DEFAULT_SOUND; notif.defaults |= Notification.DEFAULT_VIBRATE; mNotificationManager.notify(NOTIFICATION_ID, notif); }