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.endiansoftware.echo.remotewatch.GcmIntentService.java
private void sendNotification(Bundle msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle(msg.get("key1").toString()) .setContentText(msg.get("key2").toString()).setTicker(msg.get("key1").toString()); mBuilder.setContentIntent(contentIntent); Notification notification = mBuilder.build(); if (msg.get("collapse_key").toString().equals("Emergency")) { notification.flags |= notification.FLAG_INSISTENT | notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND | Notification.DEFAULT_LIGHTS; notification.vibrate = new long[] { 100L, 100L, 200L, 500L }; } else {//from ww w. j a va 2 s .c o m notification.flags |= notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.vibrate = new long[] { 100L }; } mNotificationManager.notify(NOTIFICATION_ID, notification); PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG"); wl.acquire(); }
From source file:mai.whack.StickyNotesActivity.java
/** Called when the activity is first created. */ @Override/*from w ww . j a v a2 s. c o m*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mNfcAdapter = NfcAdapter.getDefaultAdapter(this); setContentView(R.layout.main); findViewById(R.id.write_tag).setOnClickListener(mTagWriter); // Handle all of our received NFC intents in this activity. mNfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); // Intent filters for reading a note from a tag or exchanging over p2p. IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); try { ndefDetected.addDataType("text/plain"); } catch (MalformedMimeTypeException e) { } mNdefExchangeFilters = new IntentFilter[] { ndefDetected }; // Intent filters for writing to a tag IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); mWriteTagFilters = new IntentFilter[] { tagDetected }; }
From source file:me.willowcheng.makerthings.core.GcmIntentService.java
private void sendNotification(String msg, int notificationId) { // registerReceiver(mNotificationDeletedBroadcastReceiver, // new IntentFilter("org.openhab.notification.deleted")); if (mNotificationManager == null) mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(this, OpenHABMainActivity.class); notificationIntent.setAction("org.openhab.notification.selected"); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.putExtra("notificationId", notificationId); PendingIntent pendingNotificationIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent deleteIntent = new Intent(getApplicationContext(), NotificationDeletedBroadcastReceiver.class); deleteIntent.setAction("org.openhab.notification.deleted"); deleteIntent.putExtra("notificationId", notificationId); PendingIntent pendingDeleteIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT); Uri alarmSound = Uri.parse(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getString(Constants.PREFERENCE_TONE, "")); if (alarmSound.toString().equals("")) { alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); }/* w w w . j a v a 2 s . co m*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.openhabicon).setContentTitle("openHAB") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setAutoCancel(true) .setSound(alarmSound).setContentText(msg); mBuilder.setContentIntent(pendingNotificationIntent); mBuilder.setDeleteIntent(pendingDeleteIntent); mNotificationManager.notify(notificationId, mBuilder.build()); }
From source file:com.ibm.cloud.appid.android.internal.authorizationmanager.ChromeTabActivity.java
@Override public void onCreate(Bundle savedInstanceBundle) { logger.debug("onCreate"); super.onCreate(savedInstanceBundle); postAuthorizationIntent = getApplicationContext().getPackageName() + postAuthorizationIntent; Intent intent = getIntent();//ww w . j ava2 s.c om if (!postAuthorizationIntent.equals(intent.getAction())) { String serverUrl = getIntent().getStringExtra(AuthorizationUIManager.EXTRA_URL); this.redirectUrl = getIntent().getStringExtra(AuthorizationUIManager.EXTRA_REDIRECT_URL); String authFlowContextGuid = getIntent() .getStringExtra(AuthorizationUIManager.EXTRA_AUTH_FLOW_CONTEXT_GUID); AuthorizationFlowContext ctx = AuthorizationFlowContextStore.remove(authFlowContextGuid); this.oAuthManager = ctx.getOAuthManager(); this.authorizationListener = ctx.getAuthorizationListener(); logger.debug("serverUrl: " + serverUrl); logger.debug("redirectUrl: " + redirectUrl); CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); builder.enableUrlBarHiding(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.intent .setPackage(AuthorizationUIManager.getPackageNameToUse(this.getApplicationContext())); customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { onBroadcastReceived(intent); } }; IntentFilter intentFilter = new IntentFilter(INTENT_GOT_HTTP_REDIRECT); LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, intentFilter); //This will launch the chrome tab Uri uri = Uri.parse(serverUrl); logger.debug("launching custom tab with url: " + uri.toString()); customTabsIntent.launchUrl(this, uri); } else { //if we launch after authorization completed finish(); } }
From source file:com.zion.htf.receiver.AlarmReceiver.java
@Override public void onReceive(Context context, Intent intent) { // Get preferences Resources res = context.getResources(); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); int setId, alarmId; try {/*from w w w .j a v a 2 s. com*/ if (0 == (setId = intent.getIntExtra("set_id", 0))) throw new MissingArgumentException("set_id", "int"); if (0 == (alarmId = intent.getIntExtra("alarm_id", 0))) throw new MissingArgumentException("alarm_id", "int"); } catch (MissingArgumentException e) { throw new RuntimeException(e.getMessage()); } // Fetch info about the set try { // VIBRATE will be added if user did NOT disable notification vibration // SOUND won't as it is set even if it is to the default value int flags = Notification.DEFAULT_LIGHTS; MusicSet set = MusicSet.getById(setId); Artist artist = set.getArtist(); SimpleDateFormat dateFormat; if ("fr".equals(Locale.getDefault().getLanguage())) { dateFormat = new SimpleDateFormat("HH:mm", Locale.FRANCE); } else { dateFormat = new SimpleDateFormat("h:mm aa", Locale.ENGLISH); } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, ArtistDetailsActivity.class); resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);// Do not start a new activity but reuse the existing one (if any) resultIntent.putExtra(ArtistDetailsActivity.EXTRA_SET_ID, setId); // Manipulate the TaskStack in order to get a good back button behaviour. See http://developer.android.com/guide/topics/ui/notifiers/notifications.html TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(ArtistDetailsActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // Extract a bitmap from a file to use a large icon Bitmap largeIconBitmap = BitmapFactory.decodeResource(context.getResources(), artist.getPictureResourceId()); // Builds the notification NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setPriority(NotificationCompat.PRIORITY_MAX).setSmallIcon(R.drawable.ic_stat_notify_app_icon) .setLargeIcon(largeIconBitmap).setAutoCancel(true).setContentIntent(resultPendingIntent) .setContentTitle(artist.getName()) .setContentText(String.format(context.getString(R.string.alarm_notification), artist.getName(), set.getStage(), dateFormat.format(set.getBeginDate()))); // Vibrate settings Boolean defaultVibrate = true; if (!pref.contains(res.getString(R.string.pref_key_notifications_alarms_vibrate))) { // Get the system default for the vibrate setting AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (null != audioManager) { switch (audioManager.getRingerMode()) { case AudioManager.RINGER_MODE_SILENT: defaultVibrate = false; break; case AudioManager.RINGER_MODE_NORMAL: case AudioManager.RINGER_MODE_VIBRATE: default: defaultVibrate = true; } } } Boolean vibrate = pref.getBoolean(res.getString(R.string.pref_key_notifications_alarms_vibrate), defaultVibrate); // Ringtone settings String ringtone = pref.getString(res.getString(R.string.pref_key_notifications_alarms_ringtone), Settings.System.DEFAULT_NOTIFICATION_URI.toString()); // Apply notification settings if (!vibrate) { notificationBuilder.setVibrate(new long[] { 0l }); } else { flags |= Notification.DEFAULT_VIBRATE; } notificationBuilder.setSound(Uri.parse(ringtone)); // Get the stage GPS coordinates try { Stage stage = Stage.getByName(set.getStage()); // Add the expandable notification buttons PendingIntent directionsButtonPendingIntent = PendingIntent .getActivity(context, 1, new Intent(Intent.ACTION_VIEW, Uri.parse(String.format(Locale.ENGLISH, "http://maps.google.com/maps?f=d&daddr=%f,%f", stage.getLatitude(), stage.getLongitude()))), Intent.FLAG_ACTIVITY_NEW_TASK); notificationBuilder.addAction(R.drawable.ic_menu_directions, context.getString(R.string.action_directions), directionsButtonPendingIntent); } catch (InconsistentDatabaseException e) { // Although this is a serious error, its impact on functionality is minimal. // Report this through piwik if (BuildConfig.DEBUG) e.printStackTrace(); } // Finalize the notification notificationBuilder.setDefaults(flags); Notification notification = notificationBuilder.build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(set.getStage(), 0, notification); SavedAlarm.delete(alarmId); } catch (SetNotFoundException e) { throw new RuntimeException(e.getMessage()); // TODO: Notify that an alarm was planned but some error prevented to display it properly. Open AlarmManagerActivity on click // Report this through piwik } }
From source file:com.facebook.CustomTabMainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Custom Tab Redirects should not be creating a new instance of this activity if (CustomTabActivity.CUSTOM_TAB_REDIRECT_ACTION.equals(getIntent().getAction())) { setResult(RESULT_CANCELED);/*from ww w . j a v a 2 s . c o m*/ finish(); return; } if (savedInstanceState == null) { Bundle parameters = getIntent().getBundleExtra(EXTRA_PARAMS); String chromePackage = getIntent().getStringExtra(EXTRA_CHROME_PACKAGE); CustomTab customTab = new CustomTab(OAUTH_DIALOG, parameters); customTab.openCustomTab(this, chromePackage); shouldCloseCustomTab = false; // This activity will receive a broadcast if it can't be opened from the back stack redirectReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // Remove the custom tab on top of this activity. Intent newIntent = new Intent(CustomTabMainActivity.this, CustomTabMainActivity.class); newIntent.setAction(REFRESH_ACTION); newIntent.putExtra(EXTRA_URL, intent.getStringExtra(EXTRA_URL)); newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivity(newIntent); } }; LocalBroadcastManager.getInstance(this).registerReceiver(redirectReceiver, new IntentFilter(CustomTabActivity.CUSTOM_TAB_REDIRECT_ACTION)); } }
From source file:com.appzoneltd.lastmile.customer.deprecated.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*w w w . j a v a 2 s . c om*/ private static void generateNotification(Context context, String message) { NotificationCompat.Builder notification; String title = context.getString(R.string.app_name); long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notification = new NotificationCompat.Builder(context); notification.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)); notification.setSmallIcon(R.mipmap.ic_launcher); notification.setContentTitle(title); notification.setContentText(message); Intent notificationIntent = new Intent(context, PushNotificationActivity.class); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setContentIntent(intent); notification.setAutoCancel(true); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationManager.notify(1, notification.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()); }
From source file:com.willowtreeapps.spurceexampleapp.SpruceActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.sort_option: break;//from w w w . jav a 2 s .c om case R.id.recycler_option: startActivity(new Intent(this, RecyclerActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)); break; } return super.onOptionsItemSelected(item); }
From source file:com.maryplasez.spicemeapp.MyFirebaseMessagingService.java
/** * Create and show a simple notification containing the received FCM message. * * @param messageBody FCM message body received. *//*from ww w.jav a 2 s .co m*/ private void sendNotification(String messageBody) { String title = "I want to lick you till you swear allegiance to the empire"; Intent intent = new Intent(this, ChatActivity.class); intent.putExtra("PUSH", title); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 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.mipmap.icon).setContentTitle(title).setContentText(messageBody).setAutoCancel(true) .setSound(defaultSoundUri).setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); }