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:com.csform.android.uiapptemplate.gcm.GcmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Bundle extras = intent.getExtras();/*from www .j a va 2 s. c o m*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { sendNotification("Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { sendNotification("Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // String title = extras.getString("title"); // String message = extras.getString("message"); // // // This loop represents the service doing some work. // for (int i = 0; i < 2; i++) { // Log.i(TAG, "Working... " + (i + 1) // + "/5 @ " + SystemClock.elapsedRealtime()); // try { // Thread.sleep(2000); // } catch (InterruptedException e) { // } // } // Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. // sendNotification("Received: " + extras.toString()); sendNotification("Received: " + extras.getString("key1") + extras.getString("key2")); Log.i(TAG, "Received: " + extras.toString()); Log.d("123", "START"); Intent intent2 = new Intent(this.getApplicationContext(), ClientManagementActivity.class); intent2.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); intent2.putExtra("data", extras); //intent2.setData(Uri.parse(extras.toString())); startActivity(intent2); Log.d("123", "END"); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:org.androidpn.client.SerivceManager.Notifier.java
public void notify(String notificationId, String apiKey, String title, String message, String uri) { Log.d(LOGTAG, "notify()..."); Log.d(LOGTAG, "notificationId=" + notificationId); Log.d(LOGTAG, "notificationApiKey=" + apiKey); Log.d(LOGTAG, "notificationTitle=" + title); Log.d(LOGTAG, "notificationMessage=" + message); Log.d(LOGTAG, "notificationUri=" + uri); if (isNotificationEnabled()) { // Show the toast if (isNotificationToastEnabled()) { Toast.makeText(context, message, Toast.LENGTH_LONG).show(); }//w w w . ja va2 s . co m // PNNotification int ntfyDefaults = Notification.DEFAULT_LIGHTS; if (isNotificationSoundEnabled()) { ntfyDefaults |= Notification.DEFAULT_SOUND; } if (isNotificationVibrateEnabled()) { ntfyDefaults |= Notification.DEFAULT_VIBRATE; } Intent intent; //launch mainactivity if (uri == null || uri.length() <= 0) { intent = new Intent(context, MainActivity.class); } else { intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(uri)); } /* intent.putExtra(Constants.NOTIFICATION_ID, notificationId); intent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); intent.putExtra(Constants.NOTIFICATION_TITLE, title); intent.putExtra(Constants.NOTIFICATION_MESSAGE, message); intent.putExtra(Constants.NOTIFICATION_URI, uri);*/ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Notification.Builder notification = new Notification.Builder(context).setContentTitle(title) .setContentText(message).setSmallIcon(getNotificationIcon()).setDefaults(ntfyDefaults) .setContentIntent(contentIntent) //.setLargeIcon(R.drawable.notification) .setWhen(System.currentTimeMillis()).setTicker(message); notify(notification); //notification.flags |= PNNotification.FLAG_AUTO_CANCEL; // Intent intent; // if (uri != null // && uri.length() > 0 // && (uri.startsWith("http:") || uri.startsWith("https:") // || uri.startsWith("tel:") || uri.startsWith("geo:"))) { // intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); // } else { // String callbackActivityPackageName = sharedPrefs.getString( // Constants.CALLBACK_ACTIVITY_PACKAGE_NAME, ""); // String callbackActivityClassName = sharedPrefs.getString( // Constants.CALLBACK_ACTIVITY_CLASS_NAME, ""); // intent = new Intent().setClassName(callbackActivityPackageName, // callbackActivityClassName); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); // } //notification.setLatestEventInfo(context, title, message, // contentIntent); //notificationManager.notify(random.nextInt(), notification); // Intent clickIntent = new Intent( // Constants.ACTION_NOTIFICATION_CLICKED); // clickIntent.putExtra(Constants.NOTIFICATION_ID, notificationId); // clickIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); // clickIntent.putExtra(Constants.NOTIFICATION_TITLE, title); // clickIntent.putExtra(Constants.NOTIFICATION_MESSAGE, message); // clickIntent.putExtra(Constants.NOTIFICATION_URI, uri); // // positiveIntent.setData(Uri.parse((new StringBuilder( // // "notif://notification.adroidpn.org/")).append(apiKey).append( // // "/").append(System.currentTimeMillis()).toString())); // PendingIntent clickPendingIntent = PendingIntent.getBroadcast( // context, 0, clickIntent, 0); // // notification.setLatestEventInfo(context, title, message, // clickPendingIntent); // // Intent clearIntent = new Intent( // Constants.ACTION_NOTIFICATION_CLEARED); // clearIntent.putExtra(Constants.NOTIFICATION_ID, notificationId); // clearIntent.putExtra(Constants.NOTIFICATION_API_KEY, apiKey); // // negativeIntent.setData(Uri.parse((new StringBuilder( // // "notif://notification.adroidpn.org/")).append(apiKey).append( // // "/").append(System.currentTimeMillis()).toString())); // PendingIntent clearPendingIntent = PendingIntent.getBroadcast( // context, 0, clearIntent, 0); // notification.deleteIntent = clearPendingIntent; // // notificationManager.notify(random.nextInt(), notification); } else { Log.w(LOGTAG, "Notificaitons disabled."); } datasource = new PNNotificationDataSource(context); datasource.open(); datasource.createNotification(title, message, uri); datasource.close(); //Update the list view if (MainActivity.instance != null) { MainActivity.instance.resetList(); } }
From source file:com.paperpad.MoulinsDuDuc.GcmIntentService.java
private void sendNotification(String msg, String page_id) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(this, SplashActivity.class); Bundle bundle = new Bundle(); bundle.putString("page_id", page_id); intent.putExtras(bundle);/*from w ww . j a va 2s .co m*/ intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // PendingIntent.ge // PendingIntent.getActivity(this, NOTIFICATION_ID, intent, Intent.FLAG_ACTIVITY_SINGLE_TOP); // PendingIntent contentIntent2 = PendingIntent.getActivity(context, requestCode, intent, flags, options) NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setAutoCancel(false) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(getResources().getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.euphor.paperpad.GcmIntentService.java
private void sendNotification(String msg, String page_id) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent = new Intent(this, SplashActivity.class); Bundle bundle = new Bundle(); bundle.putString("page_id", page_id); intent.putExtras(bundle);/*from w w w . ja va 2s .co m*/ intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // PendingIntent.ge // PendingIntent.getActivity(this, NOTIFICATION_ID, intent, Intent.FLAG_ACTIVITY_SINGLE_TOP); // PendingIntent contentIntent2 = PendingIntent.getActivity(context, requestCode, intent, flags, options) NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setAutoCancel(false) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getResources().getString(R.string.app_name)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.cloudbees.gasp.gcm.GCMIntentService.java
/** * Send a notification message that a new update has been received * * @param msg Notification message/*w ww . j a v a 2s .c o m*/ */ private void sendNotification(String msg) { NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, ConsoleActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("Gasp! Update") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:net.czlee.debatekeeper.AlertManager.java
/** * Constructor./* w w w. ja v a 2 s . co m*/ * @param debatingTimerService The instance of {@link DebatingTimerService} to which this * AlertManager relates */ public AlertManager(Service debatingTimerService) { mService = debatingTimerService; // System services mNotificationManager = (NotificationManager) debatingTimerService .getSystemService(Context.NOTIFICATION_SERVICE); mVibrator = (Vibrator) debatingTimerService.getSystemService(Context.VIBRATOR_SERVICE); mPowerManager = (PowerManager) mService.getSystemService(Context.POWER_SERVICE); // Create a PendingIntent for the notification we raise while the timer is running. Intent intent = new Intent(debatingTimerService, DebatingActivity.class); // This flag prevents the activity from having multiple instances on the back stack, // so that when the user presses the notification while already in Debatekeeper, pressing // back won't make the user go through several instances of Debatekeeper on the back stack. intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); mIntentForOngoingNotification = PendingIntent.getActivity(debatingTimerService, 0, intent, 0); // Set up defaults Resources res = mService.getResources(); mSilentMode = res.getBoolean(R.bool.prefDefault_silentMode); mVibrateMode = res.getBoolean(R.bool.prefDefault_vibrateMode); createWakeLock(); }
From source file:com.example.samples.mp3player.Mp3PlayerService.java
/** * Show a notification while this service is running. *///from w w w .j a v a 2 s. c om private Notification buildMp3PlayerNotification() { CharSequence title = getText(R.string.mp3player_service_started); CharSequence text = getText(R.string.mp3player_service_label); Intent i = new Intent(this, Mp3Player.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0); NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle() .addLine("M.Twain (Google+) Haiku is more than a cert...").addLine("M.Twain Reminder") .addLine("M.Twain Lunch?").addLine("M.Twain Revised Specs").addLine("M.Twain ") .addLine("Google Play Celebrate 25 billion apps with Goo..") .addLine("Stack Exchange StackOverflow weekly Newsl...").setBigContentTitle("6 new message") .setSummaryText("mtwain@android.com"); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.stat_sample).setContentTitle(title).setContentText(text); //.setContentIntent(contentIntent); Notification noti = mBuilder.build(); RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.mp3player_notification); expandedView.setOnClickPendingIntent(R.id.noti_image, contentIntent); expandedView.setOnClickPendingIntent(R.id.noti_button_play, contentIntent); noti.bigContentView = expandedView; noti.flags |= Notification.FLAG_NO_CLEAR; return noti; }
From source file:eu.inmite.apps.smsjizdenka.util.NotificationUtil.java
/** * Verification if tickets is bought 1 minute after another. */// w w w . j a v a 2s . co m public static void notifyVerification(Context c, City city) { Intent i = new Intent(c, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); i.putExtra(MainActivity.EXTRA_REALLY_BUY_CITY_ID, city.id); PendingIntent contentIntent = PendingIntent.getActivity(c, NOTIFICATION_VERIFY, i, PendingIntent.FLAG_CANCEL_CURRENT); String title = c.getString(R.string.cities_ticket_bought_again_verification); String text = c.getString(R.string.cities_ticket_bought_again_action); fireNotification(c, NOTIFICATION_VERIFY, contentIntent, title, text, null, null, title, R.drawable.notification_small_warning, R.drawable.notification_big_warning, null, false); }
From source file:com.google.android.apps.iosched.gcm.GCMIntentService.java
private void displayNotification(Context context, String message) { LOGI(TAG, "displayNotification: " + message); ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_stat_notification).setTicker(message) .setContentTitle(context.getString(R.string.app_name)).setContentText(message) .setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, HomeActivity.class).setFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP), 0))/*from w ww . j a v a 2 s .c o m*/ .setAutoCancel(true).getNotification()); }
From source file:jp.maju.wifiserver.camera.QRReaderActivity.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.surface_camera: mCameraSurfaceView.oneShot(new PreviewCallback() { @Override//from www. j av a 2 s. com public void onPreviewFrame(byte[] data, Camera camera) { int previewWidth = camera.getParameters().getPreviewSize().width; int previewHeight = camera.getParameters().getPreviewSize().height; PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, previewWidth, previewHeight, 0, 0, previewWidth, previewHeight, false); BinaryBitmap biBitmap = new BinaryBitmap(new HybridBinarizer(source)); Result result = null; try { result = new MultiFormatReader().decode(biBitmap); String text = result.getText(); String[] params = text.split(":"); if (CommonUtil.getCurrentSSID(getApplication()).equals(params[0])) { SocketInfo si = new SocketInfo(params[0]); si.setHost(params[1]); si.setPort(Integer.parseInt(params[2])); si.setKind(params[3]); Intent intent = new Intent(QRReaderActivity.this, ClientActivity.class) .putExtra(ClientActivity.KEY_SOCKET_INFO, si); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PreferenceUtil.save(getApplication(), si); PreferenceUtil.setDefaultSide(getApplication(), 2); startActivity(intent); finish(); } Logger.d(TAG, "Result decoded:" + text); } catch (Exception e) { Logger.e(TAG, e); Toast.makeText(getApplicationContext(), "Failed to read", Toast.LENGTH_SHORT).show(); } } }, 3); break; } }