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:br.com.awa.mylottery.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./* w ww .j a va 2 s.c o m*/ */ private void sendNotification(String message) { Intent intent = new Intent(this, HomeActivity.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.common_ic_googleplayservices).setContentTitle("MyLottery") .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.alobha.challenger.business.gmc.NotificationGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param challenge GCM challenge received. *///w ww . j a va2s.c o m private void sendNotification(Challenge challenge) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("challenge_id", challenge.id); intent.setAction("ShowNotification"); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.inner_logo); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.inner_logo).setLargeIcon(largeIcon) .setContentTitle(getString(R.string.app_name)) .setContentText("You were challenged by " + challenge.owner.first_name).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:edu.gatech.wguo64.lostandfoundandroidapp.notification.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w . jav a2 s .c om*/ */ private void sendNotification(String message) { Intent intent = null; long reportId = -1; if (message.startsWith("Lost")) { intent = new Intent(this, DetailReportActivity.class); reportId = Long.parseLong(message.substring(5)); intent.putExtra("reportId", reportId); message = "Your found report may get a match!"; } else if (message.startsWith("Found")) { intent = new Intent(this, DetailReportActivity.class); reportId = Long.parseLong(message.substring(6)); intent.putExtra("reportId", reportId); message = "Your lost report may get a match!"; } 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("Lost And Found Georgia Tech") .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:in.myfootprint.myfootprint.push.MyGCMListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from www .j ava 2 s . co m*/ */ private void sendNotification(String message) { MyFootprintApplication.getInstance().trackEvent("Open directly", "Push Message", "Notification"); numMessages = 0; Intent intent = new Intent(this, ProfileActivity.class); intent.putExtra("FragmentNumber", "3"); 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.favicon_marker).setContentTitle("myFootprint") .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).setContentText(message) .setAutoCancel(true).setSound(defaultSoundUri).setContentIntent(pendingIntent); notificationBuilder.setNumber(++numMessages); //Log.e("NotifWaala", String.valueOf(numMessages)); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.neklo.demo.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//w ww . j av a 2s . com */ private void sendNotification(String title, 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(getApplication().getApplicationInfo().icon).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:kr.ds.myfoodpdx.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received./*from w w w . ja va2s .c o m*/ */ private void sendNotification(String message) { boolean isvibrate = SharedPreference.getBooleanSharedPreference(getApplicationContext(), "isvibrate"); Intent intent = new Intent(this, IntroActivity.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; if (isvibrate) { notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.icon) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setPriority(Notification.PRIORITY_MAX).setContentIntent(pendingIntent); } else { notificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)).setSmallIcon(R.mipmap.icon) .setContentText(message).setAutoCancel(true).setVibrate(new long[] { 0 }) .setPriority(Notification.PRIORITY_MAX).setContentIntent(pendingIntent); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(UniqueID.getRandomNumber(1000), notificationBuilder.build()); }
From source file:cn.kangeqiu.kq.activity.BaseActivity.java
/** * ??????????? ????/*from w ww. jav a 2s . c o m*/ * * @param message */ protected void notifyNewMessage(EMMessage message) { // ????(app??demo??) // ?setShowNotificationInbackgroup:false(false???sdk??) if (!EasyUtils.isAppRunningForeground(this)) { return; } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(getApplicationInfo().icon).setWhen(System.currentTimeMillis()).setAutoCancel(true); String ticker = CommonUtils.getMessageDigest(message, this); String st = getResources().getString(R.string.expression); if (message.getType() == Type.TXT) ticker = ticker.replaceAll("\\[.{2,3}\\]", st); // ???? mBuilder.setTicker(message.getFrom() + ": " + ticker); // pendingintent?2.3bug Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, notifiId, intent, PendingIntent.FLAG_ONE_SHOT); mBuilder.setContentIntent(pendingIntent); Notification notification = mBuilder.build(); notificationManager.notify(notifiId, notification); notificationManager.cancel(notifiId); }
From source file:com.eusecom.attendance.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. */// w w w . j a va2 s. 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_stat_ic_notification).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:com.lvbo.template.module.fcm.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.// w w w . jav a 2 s . c o m */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); // intent.setData((Uri.parse("custom://"+ System.currentTimeMillis()))); // For multiple notification intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); int bgColor = getResources().getColor(R.color.colorPrimary); Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setLargeIcon(largeIcon) .setContentTitle(getString(R.string.app_name)).setContentText(message) // .setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent).setColor(bgColor) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId /* ID of notification */, notificationBuilder.build()); notificationId++; }
From source file:com.kectech.android.wyslink.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 v a2s . co m*/ */ private void sendNotification(String message) { // Intent intent = new Intent(this, MainActivity.class); // intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); // http://stackoverflow.com/questions/5502427/resume-application-and-stack-from-notification // use the same intent filters as android uses when launches the app final Intent intent = new Intent(this, MainActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); // http://stackoverflow.com/questions/25030710/gcm-push-notification-large-icon-size Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_notification_large); float multiplier = getImageFactor(getResources()); largeIcon = Bitmap.createScaledBitmap(largeIcon, (int) (largeIcon.getWidth() * multiplier), (int) (largeIcon.getHeight() * multiplier), false); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setLargeIcon(largeIcon).setSmallIcon(R.drawable.ic_stat_communication_message) .setContentTitle("wysLink Message").setContentText(message).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent) .setVisibility(NotificationCompat.VISIBILITY_PRIVATE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { // support from API 17 and above (Android 4.2) notificationBuilder.setSubText("click to open"); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); // Another issue i had in android lollipop is that the small icon was displayed next to the large icon. // http://stackoverflow.com/questions/16170648/android-notification-builder-show-a-notification-without-icon/33943309#33943309 Notification notification = notificationBuilder.build(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { int smallIconViewId = this.getResources().getIdentifier("right_icon", "id", android.R.class.getPackage().getName()); if (smallIconViewId != 0) { if (notification.contentIntent != null) notification.contentView.setViewVisibility(smallIconViewId, View.INVISIBLE); if (notification.headsUpContentView != null) notification.headsUpContentView.setViewVisibility(smallIconViewId, View.INVISIBLE); if (notification.bigContentView != null) notification.bigContentView.setViewVisibility(smallIconViewId, View.INVISIBLE); } } notificationManager.notify(0 /* ID of notification */, notification); }