List of usage examples for android.content Intent FLAG_ACTIVITY_SINGLE_TOP
int FLAG_ACTIVITY_SINGLE_TOP
To view the source code for android.content Intent FLAG_ACTIVITY_SINGLE_TOP.
Click Source Link
From source file:net.frygo.findmybuddy.GCMIntentService.java
private static void generateAcceptfriendNotification(Context context, String message, String status) { Random rand = new Random(); int x = rand.nextInt(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, customlistview.class); if (status.equalsIgnoreCase("accept")) message = message + " added you as buddy"; else//from w w w. j a va2 s . co m message = message + " rejected you as buddy"; PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_CANCEL_CURRENT); Notification notification = new Notification(R.drawable.logo, message, System.currentTimeMillis()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(x, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); final PowerManager.WakeLock mWakelock = pm .newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, title); mWakelock.acquire(); // Timer before putting Android Device to sleep mode. Timer timer = new Timer(); TimerTask task = new TimerTask() { public void run() { mWakelock.release(); } }; timer.schedule(task, 5000); }
From source file:com.vis.GcmIntentService.java
private void sendNotification(String notificationMessage) { try {/* w w w . j a va 2 s . c o m*/ mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Gson gson = new Gson(); NotificationMessage notification = gson.fromJson(notificationMessage, NotificationMessage.class); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Intent intent = new Intent(this, MainActivity.class); intent.putExtra("NOTIFICATION", notificationMessage); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("Video in Short").setSound(alarmSound) .setAutoCancel(true) .setStyle(new NotificationCompat.BigTextStyle().bigText(notification.getMessage())) .setContentText(notification.getMessage()); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); Tracker t = ((Analytics) getApplication()).getDefaultTracker(); // Build and send an Event. t.send(new HitBuilders.EventBuilder().setCategory("GCM").setAction("Message") .setLabel("Message recieved").build()); } catch (JsonSyntaxException e) { e.printStackTrace(); } }
From source file:com.nobledesignlabs.lookupaddress.GcmIntentService.java
private void displayNotification(Context context, Bundle extras) { // ---PendingIntent to launch activity if the user selects // this notification--- // NotificationView context = new NotificationView(); try {//from www .ja v a2 s .c om Intent i = null; Random rand = new Random(); int timenow = rand.nextInt(); String title = extras.getString("title"); String message = extras.getString("message"); String picture = extras.getString("imgurl"); String sinfotype = extras.getString("infotype"); boolean cancelonclick = true; int infotype = Integer.parseInt(sinfotype); if (infotype == CommonStuff.ADDRESS_NOTIFICATION) { i = new Intent(context, NotificationView.class); i.putExtra("notificationID", timenow); i.putExtra("message", message); i.putExtra("title", title); i.putExtra("picture", picture); cancelonclick = true; // i.putExtra("infotype", picture); } else if (infotype == CommonStuff.ADDRESS_AUTHORIZATION_REQUEST) { i = new Intent(context, AuthorizationRequestActivity.class); String token = extras.getString("token"); i.putExtra("notificationID", timenow); i.putExtra("message", message); i.putExtra("title", title); i.putExtra("picture", picture); i.putExtra("token", token); String address = extras.getString("address"); i.putExtra("address", address); cancelonclick = true; // i.putExtra("infotype", picture); } else if (infotype == CommonStuff.ADDRESS_SHARING_REQUEST) { i = new Intent(context, AuthorizedActivity.class); i.putExtra("notificationID", timenow); i.putExtra("message", message); i.putExtra("title", title); String token = extras.getString("token"); String address = extras.getString("address"); i.putExtra("address", address); i.putExtra("token", token); cancelonclick = false; // i.putExtra("infotype", picture); } if (i != null) { i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(context, timenow, i, 0); /* * NotificationManager nm = (NotificationManager) context * .getSystemService(Context.NOTIFICATION_SERVICE); Notification * notif = new Notification( R.drawable.direction_uturn, * message, timenow); // String title = * context.getString(R.string.app_name); * * i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | * Intent.FLAG_ACTIVITY_SINGLE_TOP); * * notif.setLatestEventInfo(context, title, message, * pendingIntent); // notif.flags |= * Notification.FLAG_AUTO_CANCEL; notif.flags = * Notification.FLAG_AUTO_CANCEL; notif.defaults |= * Notification.DEFAULT_SOUND; notif.defaults |= * Notification.DEFAULT_VIBRATE; notif.vibrate = new long[] { * 100, 250, 100, 500 }; nm.notify(timenow, notif); */ NotificationCompat.Builder b = new NotificationCompat.Builder(context); if (cancelonclick) { b.setAutoCancel(true).setOngoing(false).setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.direction_uturn).setTicker(title).setContentTitle(title) .setContentText(message).setVibrate(new long[] { 100, 250, 100, 500 }) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setContentIntent(pendingIntent).setLights(0xFFF7BF05, 250, 500) .setContentInfo("me@address"); } else { b.setAutoCancel(false).setOngoing(true).setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.direction_uturn).setTicker(title).setContentTitle(title) .setContentText(message).setLights(0xFF308036, 250, 500) .setVibrate(new long[] { 100, 250, 100, 500 }) .setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND) .setContentIntent(pendingIntent).setContentInfo("me@address"); } NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(timenow, b.build()); } } catch (Exception d) { } }
From source file:com.preguardia.app.notification.MyGcmListenerService.java
private void showMessageNewNotification(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.GENERAL_NEW_MESSAGE_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(Constants.NOTIFICATION_NEW_MESSAGE_ID, notificationBuilder.build()); }
From source file:com.bufarini.reminders.AlarmReceiver.java
private void showNotification(Context context, Intent intent) { Intent snoozeIntent = new Intent(context, NotificationActivity.class); snoozeIntent.putExtras(intent.getExtras()); snoozeIntent.putExtra("notificaton action", "snooze"); PendingIntent snoozePendingIntent = PendingIntent.getActivity(context, 0, snoozeIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent doneIntent = new Intent(context, NotificationActivity.class); doneIntent.putExtras(intent.getExtras()); doneIntent.putExtra("notificaton action", "done"); doneIntent.putExtra("task", intent.getSerializableExtra("task")); PendingIntent donePendingIntent = PendingIntent.getActivity(context, 1, doneIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent resultIntent = new Intent(context, Reminders.class); resultIntent.putExtra("action", "view task"); resultIntent.putExtra("task", intent.getSerializableExtra("task")); resultIntent.setFlags(//from w w w.ja v a 2s .c o m Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true) .setSmallIcon(R.drawable.ic_action_alarms) .setContentTitle(context.getResources().getString(R.string.alarmPopupTitle1)) .setContentIntent(resultPendingIntent) .addAction(R.drawable.ic_action_alarms, "Snooze", snoozePendingIntent) .addAction(R.drawable.ic_action_done, "Done", donePendingIntent) .setContentText(intent.getExtras().getString(NotificationUtils.TITLE)); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); int notificationId = NotificationUtils.getNotificationId(intent.getExtras().getLong(NotificationUtils.ID)); notificationManager.notify(notificationId, builder.build()); }
From source file:com.example.evan.comp296.profile.MyDownloadService.java
/** * Show a notification for a finished download. *//*from w w w .j a v a 2 s. co m*/ private void showDownloadFinishedNotification(String downloadPath, int bytesDownloaded) { // Hide the progress notification dismissProgressNotification(); // Make Intent to MainActivity_Profile Intent intent = new Intent(this, MainActivity_Profile.class).putExtra(EXTRA_DOWNLOAD_PATH, downloadPath) .putExtra(EXTRA_BYTES_DOWNLOADED, bytesDownloaded) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); boolean success = bytesDownloaded != -1; String caption = success ? getString(R.string.download_success) : getString(R.string.download_failure); showFinishedNotification(caption, intent, true); }
From source file:com.piggate.sdk.Piggate.java
public void postNotification(String title, String msg, Class myClass, int resource, Bundle extras, Boolean force) {//from ww w . j av a 2 s . c o m if (!getApplicationContext().getPackageName() .equalsIgnoreCase(((ActivityManager) getApplicationContext() .getSystemService(getApplicationContext().ACTIVITY_SERVICE)).getRunningAppProcesses() .get(0).processName) || force) { Intent notifyIntent = new Intent(_context, myClass); if (extras != null) notifyIntent.putExtras(extras); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivities(_context, 0, new Intent[] { notifyIntent }, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new Notification.Builder(_context).setSmallIcon(resource) .setContentTitle(title).setContentText(msg).setAutoCancel(true).setContentIntent(pendingIntent) .build(); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; notificationManager.notify(123, notification); } }
From source file:com.example.mgalante.mysummerapp.views.main.services.MyDownloadService.java
/** * Show a notification for a finished download. *//*from w ww. j av a 2 s .c o m*/ private void showDownloadFinishedNotification(String downloadPath, int bytesDownloaded) { // Hide the progress notification dismissProgressNotification(); // Make Intent to MainActivity Intent intent = new Intent(this, MainActivity.class).putExtra(EXTRA_DOWNLOAD_PATH, downloadPath) .putExtra(EXTRA_BYTES_DOWNLOADED, bytesDownloaded) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); boolean success = bytesDownloaded != -1; String caption = success ? getString(R.string.download_success) : getString(R.string.download_failure); showFinishedNotification(caption, intent, true); }
From source file:edu.mines.letschat.GcmIntentService.java
protected PendingIntent getDeleteIntent() { Intent resultBroadCastIntent = new Intent(); resultBroadCastIntent.setAction("deletion"); resultBroadCastIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); resultBroadCastIntent.addCategory(Intent.CATEGORY_DEFAULT); sendBroadcast(resultBroadCastIntent); return PendingIntent.getBroadcast(getBaseContext(), 0, resultBroadCastIntent, PendingIntent.FLAG_CANCEL_CURRENT); }
From source file:com.ta.truckmap.gpstracking.GcmIntentService.java
private Intent startUserCreatePushIntent(String id, String type) { Utility.setSharedPrefBooleanData(getApplicationContext(), "isNotification", true); Utility.setSharedPrefStringData(getApplicationContext(), "notification", myMsg); Intent pushIntent = new Intent(getApplicationContext(), SplashActivity.class); pushIntent.putExtra("id", id); pushIntent.putExtra("type", type); pushIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); return pushIntent; }