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.karbide.bluoh.notification.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. */// w w w . jav a 2s . c o m private void sendNotification(String title, String messageBody, String TrueOrFalse) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra("AnotherActivity", TrueOrFalse); 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.mipmap.ic_launcher).setContentTitle(title).setContentText(messageBody) .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody)).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:andre.com.datapushandroid.services.FCMService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from www . j a v a 2s. com*/ 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); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("FCM Message").setContentText(messageBody) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:felixwiemuth.lincal.NotificationService.java
private void sendNotification(CEntry entry, int entryPos, LinCalConfig config) { Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(entry.getLink())); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); //TODO check whether this replaces notifications NotificationCompat.Builder nb = new NotificationCompat.Builder(this) .setSmallIcon(android.R.drawable.ic_menu_today).setContentTitle(config.getCalendarTitle()) .setContentText(entry.getDescription()).setContentIntent(pendingIntent).setAutoCancel(true); NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(config.getId() * 1000 + entryPos, nb.build()); //TODO manage ID }
From source file:mesa.com.outerspacemanager.outerspacemanager.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. */// ww w . j ava 2s . c o m 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); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_rocket).setContentTitle("FCM Message").setContentText(messageBody) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:kr.ds.recipe.MyGcmListenerService.java
private void sendCommunitySubNotification(String message, String uid) { Intent intent = new Intent(this, IntroActivity.class); Uri uri = Uri.parse("recipe://details?type=community_sub&uid=" + uid); intent.setAction(Intent.ACTION_VIEW); intent.setData(uri);/*w ww . j a v a 2 s . c o m*/ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder; if (isvibrate) { notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.push_icon) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); } else { notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.push_icon) .setContentText(message).setAutoCancel(true).setVibrate(new long[] { 0 }) .setContentIntent(pendingIntent); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(1000, notificationBuilder.build()); }
From source file:com.live.tj98.chatsnap.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w ww . j av a2 s . c o m*/ protected void sendNotification(String sender, String messageBody) { Intent intent = new Intent(MyFirebaseMessagingService.this, ChatsActivity.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.background_splash).setContentTitle(sender).setContentText(messageBody) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.inc.playground.playground.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w. j a v a 2s . c o m*/ */ private void sendNotification(String message, String title, JSONObject inputJson) { globalVariables = ((GlobalVariables) this.getApplication()); Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); Intent iv = new Intent(); // if cancel event if (title.contains("requested")) { iv = new Intent(MyGcmListenerService.this, ApproveEventList.class); iv.putExtra("parent", "MyGcm"); iv.putExtra("inputJson", inputJson.toString()); } else { ArrayList<NotificationObject> notificationList = globalVariables.GetNotifications(); EventsObject curEvent = new EventsObject(); NotificationObject curNotification = new NotificationObject(); curNotification.setDescription(message); curNotification.setTitle(title); curNotification.setInputJson(inputJson); notificationList.add(curNotification); globalVariables.SetNotifications(notificationList); iv = new Intent(MyGcmListenerService.this, NotificationsList.class); } PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, iv, 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(title).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:com.app.basarnas.fcm.MyFirebaseMessagingService.java
private void sendNotification() { Intent intent = new Intent(this, MainActivity.class); intent.putExtra(Config.JSON_DATA_NOTIFICATION, jsonDataNotification); intent.setAction(Intent.ACTION_MAIN); 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) .setStyle(new NotificationCompat.BigTextStyle().bigText(dataNotification.getText())) .setSmallIcon(R.mipmap.ic_launcher, 10) .setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary)) .setContentTitle(dataNotification.getTitle()) .setContentText(CommonUtilities.toHtml(dataNotification.getText())) .setPriority(NotificationCompat.PRIORITY_HIGH).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(Config.NOTIFICATION_ID /* ID of notification */, notificationBuilder.build()); }
From source file:com.gsma.rcs.ri.sharing.image.ImageSharingIntentService.java
/** * Add image share notification/* w w w .j a va 2 s.c o m*/ * * @param invitation Intent invitation * @param ishDao the image sharing data object */ private void addImageSharingInvitationNotification(Intent invitation, ImageSharingDAO ishDao) { ContactId contact = ishDao.getContact(); if (contact == null) { if (LogUtils.isActive) { Log.e(LOGTAG, "addImageSharingInvitationNotification failed: cannot parse contact"); } return; } /* Create pending intent */ Intent intent = new Intent(invitation); intent.setClass(this, ReceiveImageSharing.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); /* * If the PendingIntent has the same operation, action, data, categories, components, and * flags it will be replaced. Invitation should be notified individually so we use a random * generator to provide a unique request code and reuse it for the notification. */ int uniqueId = Utils.getUniqueIdForPendingIntent(); PendingIntent contentIntent = PendingIntent.getActivity(this, uniqueId, intent, PendingIntent.FLAG_ONE_SHOT); String displayName = RcsContactUtil.getInstance(this).getDisplayName(contact); String title = getString(R.string.title_recv_image_sharing); /* Create notification */ NotificationCompat.Builder notif = new NotificationCompat.Builder(this); notif.setContentIntent(contentIntent); notif.setSmallIcon(R.drawable.ri_notif_csh_icon); notif.setWhen(System.currentTimeMillis()); notif.setAutoCancel(true); notif.setOnlyAlertOnce(true); notif.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notif.setDefaults(Notification.DEFAULT_VIBRATE); notif.setContentTitle(title); notif.setContentText(getString(R.string.label_from_args, displayName)); /* Send notification */ NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(uniqueId, notif.build()); }
From source file:com.rickendirk.rsgwijzigingen.ZoekService.java
private void setAlarmIn20Min() { Intent zoekIntent = new Intent(this, ZoekService.class); zoekIntent.putExtra("isAchtergrond", true); zoekIntent.addCategory("GeenWifiHerhaling"); //Categorie om andere intents cancelen te voorkomen PendingIntent pendingIntent = PendingIntent.getService(this, 3, zoekIntent, PendingIntent.FLAG_ONE_SHOT); AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Long in20Min = SystemClock.elapsedRealtime() + 1200000; //20Min in milisec. manager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, in20Min, pendingIntent); Log.i(TAG, "Nieuw alarm gezet in 20 min"); }