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.yj.wangjatv.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param data GCM message received./* w w w. j a va 2 s. co m*/ */ private void sendNotification(Bundle data) { Intent intent = new Intent(this, IntroActivity.class); intent.putExtra("data", data); 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(getString(R.string.app_name)) .setContentText(data.getString("msg")).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.hacktx.android.services.NotificationService.java
private void sendNotification(String group, Map<String, String> data) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); 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); int id = NotificationUtils.getIdBase(this, group); String title = data.get("title") != null ? data.get("title") : getString(R.string.app_name); String text = data.get("text") != null ? data.get("text") : getString(R.string.notif_new_notifications); boolean vibrate = Boolean.parseBoolean(data.get("vibrate") != null ? data.get("vibrate") : "false"); NotificationCompat.Builder notificationBuilder = getBaseNotificationBuilder(title, text, vibrate) .setContentIntent(pendingIntent); notificationManager.notify(id, notificationBuilder.build()); }
From source file:com.iovirta.iot_kamera_sovellus.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. */// w ww . ja v a 2 s.c om private void sendNotification(String messageBody) { Intent intent = new Intent(this, mediaView.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("Iot Cam Demo") .setContentText("Liikett havaittu!").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.jefftharris.passwdsafe.sync.box.BoxProvider.java
@Override public void startAccountLink(FragmentActivity activity, int requestCode) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); if (prefs.contains(PREF_AUTH_USER_ID) || prefs.contains(PREF_AUTH_REFRESH_TOKEN)) { SharedPreferences.Editor edit = prefs.edit(); edit.remove(PREF_AUTH_USER_ID);//from w ww. ja va2 s . c o m edit.remove(PREF_AUTH_ACCESS_TOKEN); edit.remove(PREF_AUTH_EXPIRES_IN); edit.remove(PREF_AUTH_REFRESH_TOKEN); edit.remove(PREF_AUTH_TOKEN_TYPE); edit.apply(); } if (isAccountAuthorized()) { unlinkAccount(); } Intent intent = new Intent(); itsAcctLinkIntent = activity.createPendingResult(requestCode, intent, PendingIntent.FLAG_ONE_SHOT); itsClient.authenticate(); }
From source file:kr.ds.humor.MyGcmListenerService.java
private void sendNotification(String message, Bitmap bitmap) { 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 = new NotificationCompat.Builder(this) .setPriority(NotificationCompat.PRIORITY_MAX) .setContentTitle(getResources().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);/* ww w . j av a 2s. com*/ style.bigPicture(bitmap); notificationBuilder.setStyle(style); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(UniqueID.getRandomNumber(1000), notificationBuilder.build()); }
From source file:com.trams.azit.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param message GCM message received.//from w w w . j ava 2s. c om */ private void sendNotification(String message, String code) { Intent intent; if (getSharedPreferences("Azit", MODE_PRIVATE).getString("login", "").equals("false") && !Constants.IS_LOGIN) { //?? ? ? ?? intent = new Intent(this, LoginActivity_.class); } else { //??? ? int intCode = Integer.parseInt(code); switch (intCode) { case 201: intent = new Intent(this, MyMessage.class); break; case 401: intent = new Intent(this, MentoMainActivity.class); intent.putExtra("position", 2); break; case 402: intent = new Intent(this, MyPointActivity.class); break; case 403: intent = new Intent(this, Mento_Act.class); break; case 404: intent = new Intent(this, MentoMainActivity.class); break; default: intent = new Intent(this, LoginActivity_.class); break; } } 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.app_icon).setContentTitle(getResources().getString(R.string.app_name)) .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.fitc.dooropener.lib.gcm.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param status GCM message received./*ww w .ja va2s.c o m*/ */ private void sendNotification(GcmDataPayload status) { /** * This code should find launcher activity of app using this librbary and set it as the what gets launched */ Intent intent = null; final PackageManager packageManager = getPackageManager(); Log.i(TAG, "PACKAGE NAME " + getPackageName()); Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> appList = packageManager.queryIntentActivities(mainIntent, 0); for (final ResolveInfo resolveInfo : appList) { if (getPackageName().equals(resolveInfo.activityInfo.packageName)) //if this activity is not in our activity (in other words, it's another default home screen) { intent = packageManager.getLaunchIntentForPackage(resolveInfo.activityInfo.packageName); break; } } PendingIntent pendingIntent = null; if (intent != null) { intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 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(getResources().getString(R.string.notif_content_title)) .setContentText(status.getStatusData()).setAutoCancel(true).setSound(defaultSoundUri); if (pendingIntent != null) { notificationBuilder.setContentIntent(pendingIntent); } NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }
From source file:com.dishcuss.foodie.hub.GCM.MyGcmListenerService.java
private void sendNotification(String message, String title, String type, int id) { Intent intent = new Intent(this, HomeActivity.class); if (type.equals("Credit")) { intent = new Intent(this, MyWalletActivity.class); }//from w ww . j a v a2 s .c om if (type.equals("User")) { if (id != 0) { intent = new Intent(this, ProfilesDetailActivity.class); intent.putExtra("UserID", id); } } if (type.equals("Post")) { intent = new Intent(this, NotificationClickPostDetail.class); intent.putExtra("TypeID", id); intent.putExtra("Type", "Post"); } if (type.equals("Review")) { intent = new Intent(this, NotificationClickPostDetail.class); intent.putExtra("TypeID", id); intent.putExtra("Type", "Review"); } 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(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.piggate.samples.PiggateLoginService.Service_Notify.java
@Override public void onTaskRemoved(Intent rootIntent) { Intent restartService = new Intent(getApplicationContext(), this.getClass()); restartService.setPackage(getPackageName()); PendingIntent restartServicePI = PendingIntent.getService(getApplicationContext(), 1, restartService, PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE); alarmService.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 1000, restartServicePI); }
From source file:com.botree.botree911_client.notification.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*www . jav a 2 s.c om*/ private void sendNotification(String title, String messageBody) { int count = PreferenceUtility.getNoticationCount(MyFirebaseMessagingService.this); PreferenceUtility.saveNotificationCount(MyFirebaseMessagingService.this, (count + 1)); Intent intent = new Intent(this, SplashActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle(title); bigTextStyle.bigText(messageBody); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { notificationBuilder.setSmallIcon(R.drawable.ic_stat_name); notificationBuilder.setColor(ResourcesCompat.getColor(getResources(), R.color.colorGreenLight, null)); } else { notificationBuilder.setSmallIcon(R.mipmap.ic_launcher); } notificationBuilder.setContentTitle(title); notificationBuilder.setContentText(messageBody); notificationBuilder.setStyle(bigTextStyle); notificationBuilder.setAutoCancel(true); notificationBuilder.setSound(defaultSoundUri); notificationBuilder.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(count /* ID of notification */, notificationBuilder.build()); }