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.sumang.chatdemo.MyFirebaseMessagingService.java
/** * Handle time allotted to BroadcastReceivers. *///from w ww . j av a 2 s. c om private void handleNow(String title, String messageBody) { Log.d(TAG, "Short lived task is done."); 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).setGroup("ABC") .setGroupSummary(true).setSmallIcon(R.drawable.messenger_bubble_small_white) .setColor(getResources().getColor(R.color.colorAccent)).setContentTitle(title) .setContentText(messageBody).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getApplicationContext()); notificationManager.notify(Util.createID() /* ID of notification */, notificationBuilder.build()); }
From source file:com.rossier.shclechelles.service.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w w w.j a va2 s . co m */ private void sendNotification(String from, String message) { Gson gson = new GsonBuilder().create(); String messageUTF8 = ""; try { messageUTF8 = new String(message.getBytes(), "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } Log.i("MyGCMListenerService", message); Log.i("MyGCMListenerService", messageUTF8); if (messageUTF8 == "") return; MatchNotification match = gson.fromJson(messageUTF8, MatchNotification.class); 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); int icon = R.drawable.ic_launcher_shc; long when = System.currentTimeMillis(); // Notification notification = new Notification(icon, "Nouveaux rsultats", when); Notification notification = new Notification.Builder(this.getBaseContext()) .setContentText("Nouveaux rsultats").setSmallIcon(icon).setWhen(when).build(); NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.match_notif_layout); contentView.setTextViewText(R.id.notif_team_home, match.getTeam_home()); contentView.setTextViewText(R.id.notif_team_away, match.getTeam_away()); contentView.setTextViewText(R.id.notif_result_home, match.getResult_home() + ""); contentView.setTextViewText(R.id.notif_result_away, match.getResult_away() + ""); contentView.setTextViewText(R.id.notif_ligue, match.getLigue()); contentView.setImageViewResource(R.id.notif_team_loc_logo, Utils.getLogo(match.getTeam_home())); contentView.setImageViewResource(R.id.notif_team_away_logo, Utils.getLogo(match.getTeam_away())); notification.contentView = contentView; Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.contentIntent = contentIntent; //notification.flags |= Notification.FLAG_ONGOING_EVENT; //Do not clear the notification notification.defaults |= Notification.DEFAULT_LIGHTS; // LED notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration notification.defaults |= Notification.DEFAULT_SOUND; // Sound //get topics name String[] topic = from.split("/"); mNotificationManager.notify(topic[2].hashCode(), notification); }
From source file:com.ct.fitorto.gcm.GcmService.java
private void sendNotification(String msg, String title) { Intent intent = new Intent(this, NotificationActivity.class); 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 = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_fitorto) .setLargeIcon((BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))) .setContentTitle(title).setContentText(msg).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); //manager.putPreferenceIntValues(ApplicationData.NOTIFICATION_ID, (notificationId + 1)); }
From source file:kr.com.biligo.MyGcmListenerService.java
private void sendNotification(String message, Bitmap bitmap) { Intent intent = new Intent(this, MainActivity.class); 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 = new NotificationCompat.Builder(this) .setPriority(NotificationCompat.PRIORITY_MAX).setContentTitle(getString(R.string.app_name)) .setSmallIcon(R.mipmap.icon).setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent); if (bitmap != null) { NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle(); style.setBigContentTitle(getString(R.string.app_name)); style.setSummaryText(message);// w w w . j ava2s.c o m style.bigPicture(bitmap); notificationBuilder.setStyle(style); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0, notificationBuilder.build()); }
From source file:com.foi.air1603.sport_manager.sevices.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from w w w . ja v a 2 s. c o m*/ private void sendNotification(Map<String, String> messageBody) { Intent intent = new Intent(this, MainActivity.class); Bundle bundle = new Bundle(); bundle.putString("user", messageBody.get("user")); bundle.putString("reservation_id", messageBody.get("reservation_id")); intent.putExtras(bundle); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); // messageBody se sastoji od: user, reservation_id Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_event_white_48dp).setColor(getResources().getColor(R.color.green)) .setContentTitle("Novi invite!") .setContentText(messageBody.get("user") + " te pozvao u novi termin!").setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); if (MainActivity.user == null || MainActivity.user.hide_notifications == 0) { return; } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); // PAZI! nisam siguran je li se i MainActivity:handleSystemTrayNotification() koristi }
From source file:kr.ds.mymunsang.MyFirebaseMessagingService.java
private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity2.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); String channelId = getString(R.string.channel_message_id); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, channelId) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.icon) .setContentTitle(getString(R.string.app_name)).setContentText(message).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Since android Oreo notification channel is needed. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel(channelId, getString(R.string.channel_message_id), NotificationManager.IMPORTANCE_DEFAULT); channel.setDescription(getString(R.string.channel_message)); notificationManager.createNotificationChannel(channel); }/*from www .ja v a 2 s. c o m*/ notificationManager.notify(0, notificationBuilder.build()); }
From source file:com.anandroid.firebase.utils.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*w w w . ja v a 2 s .c o m*/ private void sendNotification(String messageBody) { Intent intent; if (messageBody.indexOf("F") == 0) { intent = new Intent(this, Analytics.class); } else { 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:org.roman.findme.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*w w w.j av a 2s .co m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, MessageActivity.class); intent.putExtra("message", message); 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("Message").setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); if (sharedPreferences.getBoolean("display_message", true)) { displayMessage(message); } }
From source file:com.entropy.promoenginedemoapp.gcm.MyGcmListenerService.java
private void sendNotification(String message) { Intent intent = new Intent(this, SecondActivity.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.logo).setContentTitle("Hype Demo").setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify((int) System.currentTimeMillis() /* ID of notification */, notificationBuilder.build()); }
From source file:com.preguardia.app.notification.MyGcmListenerService.java
private void showConsultationApprovedNotification(String title, String message, String consultationId) { // Prepare intent which is triggered if the notification is selected Intent intent = new Intent(this, ConsultationDetailsActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra(Constants.EXTRA_CONSULTATION_ID, consultationId); PendingIntent pendingIntent = PendingIntent.getActivity(this, Constants.PATIENT_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_logo).setContentTitle(title).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(4, notificationBuilder.build()); }