List of usage examples for android.content Intent FLAG_ACTIVITY_NEW_DOCUMENT
int FLAG_ACTIVITY_NEW_DOCUMENT
To view the source code for android.content Intent FLAG_ACTIVITY_NEW_DOCUMENT.
Click Source Link
From source file:com.example.android.diegobaldi.sunshine.DetailActivity.java
/** * Uses the ShareCompat Intent builder to create our Forecast intent for sharing. All we need * to do is set the type, text and the NEW_DOCUMENT flag so it treats our share as a new task. * See: http://developer.android.com/guide/components/tasks-and-back-stack.html for more info. * * @return the Intent to use to share our weather forecast *///from w w w. j a v a 2s .c o m private Intent createShareForecastIntent() { Intent shareIntent = ShareCompat.IntentBuilder.from(this).setType("text/plain") .setText(mForecastSummary + FORECAST_SHARE_HASHTAG).getIntent(); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); return shareIntent; }
From source file:com.example.android.popularmovies.fragments.MovieTrailersFragment.java
private Intent getShareIntent() { String msg = getString(R.string.easter_egg); if (!mTrailerAdapter.getList().isEmpty()) { for (Trailer trailer : mTrailerAdapter.getList()) { if (trailer.getSite().toLowerCase().equals(NetworkUtils.YOUTUBE)) { msg = NetworkUtils.getYoutubeUrl(trailer.getKey()); break; }/*from w w w. j a v a2 s. c om*/ } } Intent shareIntent = ShareCompat.IntentBuilder.from(getActivity()).setType("text/plain").setText(msg) .getIntent(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); } else { shareIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); } return shareIntent; }
From source file:it.jaschke.alexandria.fragment.DetailFragment.java
private Intent createShareIntent(String bookTitle) { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_text) + bookTitle); return shareIntent; }
From source file:net.kourlas.voipms_sms.notifications.Notifications.java
/** * Shows a notification with the specified details. * * @param contact The contact that the notification is from. * @param shortText The short form of the message text. * @param longText The long form of the message text. *///ww w .j av a 2 s . c om private void showNotification(String contact, String shortText, String longText) { String title = Utils.getContactName(applicationContext, contact); if (title == null) { title = Utils.getFormattedPhoneNumber(contact); } NotificationCompat.Builder notification = new NotificationCompat.Builder(applicationContext); notification.setContentTitle(title); notification.setContentText(shortText); notification.setSmallIcon(R.drawable.ic_chat_white_24dp); notification.setPriority(Notification.PRIORITY_HIGH); String notificationSound = Preferences.getInstance(applicationContext).getNotificationSound(); if (!notificationSound.equals("")) { notification.setSound(Uri.parse(Preferences.getInstance(applicationContext).getNotificationSound())); } String num = Utils.getFormattedPhoneNumber(contact); Log.v("prior", num); SharedPreferences sharedPreferences = applicationContext.getSharedPreferences("ledData", Context.MODE_PRIVATE); String cNm = sharedPreferences.getString(title, "3000"); SharedPreferences sharedPref = applicationContext.getSharedPreferences("color", Context.MODE_PRIVATE); int clr = sharedPref.getInt(title, 0xFF02ffff); Log.v("saved rate of ", cNm + " for " + title); int ledSpeed = 3000; int color = 0xFF02ffff; if (cNm.equals("500") || cNm.equals("3000")) { ledSpeed = Integer.parseInt(cNm); color = clr; } notification.setLights(color, ledSpeed, ledSpeed); if (Preferences.getInstance(applicationContext).getNotificationVibrateEnabled()) { notification.setVibrate(new long[] { 0, 250, 250, 250 }); } else { notification.setVibrate(new long[] { 0 }); } notification.setColor(0xFF546e7a); notification.setAutoCancel(true); notification.setStyle(new NotificationCompat.BigTextStyle().bigText(longText)); Bitmap largeIconBitmap; try { largeIconBitmap = MediaStore.Images.Media.getBitmap(applicationContext.getContentResolver(), Uri.parse(Utils.getContactPhotoUri(applicationContext, contact))); largeIconBitmap = Bitmap.createScaledBitmap(largeIconBitmap, 256, 256, false); largeIconBitmap = Utils.applyCircularMask(largeIconBitmap); notification.setLargeIcon(largeIconBitmap); } catch (Exception ignored) { // Do nothing. } Intent intent = new Intent(applicationContext, ConversationActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.putExtra(applicationContext.getString(R.string.conversation_extra_contact), contact); TaskStackBuilder stackBuilder = TaskStackBuilder.create(applicationContext); stackBuilder.addParentStack(ConversationActivity.class); stackBuilder.addNextIntent(intent); notification.setContentIntent(stackBuilder.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT)); Intent replyIntent = new Intent(applicationContext, ConversationQuickReplyActivity.class); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { replyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); } else { //noinspection deprecation replyIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); } replyIntent.putExtra(applicationContext.getString(R.string.conversation_extra_contact), contact); PendingIntent replyPendingIntent = PendingIntent.getActivity(applicationContext, 0, replyIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action.Builder replyAction = new NotificationCompat.Action.Builder( R.drawable.ic_reply_white_24dp, applicationContext.getString(R.string.notifications_button_reply), replyPendingIntent); notification.addAction(replyAction.build()); Intent markAsReadIntent = new Intent(applicationContext, MarkAsReadReceiver.class); markAsReadIntent.putExtra(applicationContext.getString(R.string.conversation_extra_contact), contact); PendingIntent markAsReadPendingIntent = PendingIntent.getBroadcast(applicationContext, 0, markAsReadIntent, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Action.Builder markAsReadAction = new NotificationCompat.Action.Builder( R.drawable.ic_drafts_white_24dp, applicationContext.getString(R.string.notifications_button_mark_read), markAsReadPendingIntent); notification.addAction(markAsReadAction.build()); int id; if (notificationIds.get(contact) != null) { id = notificationIds.get(contact); } else { id = notificationIdCount++; notificationIds.put(contact, id); } NotificationManager notificationManager = (NotificationManager) applicationContext .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(id, notification.build()); }
From source file:com.google.android.apps.muzei.settings.SettingsActivity.java
private void setupAppBar() { mAppBar = (Toolbar) findViewById(R.id.app_bar); mAppBar.setNavigationOnClickListener(new View.OnClickListener() { @Override// w ww . j a v a 2 s . c o m public void onClick(View view) { onNavigateUp(); } }); final LayoutInflater inflater = LayoutInflater.from(this); Spinner sectionSpinner = (Spinner) findViewById(R.id.section_spinner); sectionSpinner.setAdapter(new BaseAdapter() { @Override public int getCount() { return SECTION_LABELS.length; } @Override public Object getItem(int position) { return SECTION_LABELS[position]; } @Override public long getItemId(int position) { return position + 1; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.settings_ab_spinner_list_item, parent, false); } ((TextView) convertView.findViewById(android.R.id.text1)) .setText(getString(SECTION_LABELS[position])); return convertView; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.settings_ab_spinner_list_item_dropdown, parent, false); } ((TextView) convertView.findViewById(android.R.id.text1)) .setText(getString(SECTION_LABELS[position])); return convertView; } }); sectionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> spinner, View view, int position, long id) { Class<? extends Fragment> fragmentClass = SECTION_FRAGMENTS[position]; Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.content_container); if (currentFragment != null && fragmentClass.equals(currentFragment.getClass())) { return; } inflateMenuFromFragment(0); try { Fragment newFragment = fragmentClass.newInstance(); getSupportFragmentManager().beginTransaction() .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) .setTransitionStyle(R.style.Muzei_SimpleFadeFragmentAnimation) .replace(R.id.content_container, newFragment).commitAllowingStateLoss(); } catch (Exception e) { throw new RuntimeException(e); } } @Override public void onNothingSelected(AdapterView<?> spinner) { } }); sectionSpinner.setSelection(mStartSection); inflateMenuFromFragment(0); mAppBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.action_get_more_sources: try { Intent playStoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/search?q=Muzei&c=apps")) .addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); preferPackageForIntent(SettingsActivity.this, playStoreIntent, PLAY_STORE_PACKAGE_NAME); startActivity(playStoreIntent); } catch (ActivityNotFoundException activityNotFoundException1) { Toast.makeText(SettingsActivity.this, R.string.play_store_not_found, Toast.LENGTH_LONG) .show(); } return true; case R.id.action_about: startActivity(new Intent(SettingsActivity.this, AboutActivity.class)); return true; } Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.content_container); if (currentFragment != null && currentFragment instanceof SettingsActivityMenuListener) { ((SettingsActivityMenuListener) currentFragment).onSettingsActivityMenuItemClick(item); } return false; } }); }
From source file:com.kaproduction.malibilgiler.MainActivity.java
@SuppressWarnings("StatementWithEmptyBody") @Override/*from w w w. j a v a2s .c om*/ public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); if (id == R.id.nav_detay) { // Handle the camera action Intent i = new Intent(this, TabbedActivity.class); i.putExtra("TAB_ID", 3); startActivity(i); } else if (id == R.id.nav_vergi) { Intent i1 = new Intent(this, TabbedActivity.class); i1.putExtra("TAB_ID", 0); startActivity(i1); } else if (id == R.id.nav_sosyal) { Intent i2 = new Intent(this, TabbedActivity.class); i2.putExtra("TAB_ID", 1); startActivity(i2); } else if (id == R.id.nav_makro) { Intent i3 = new Intent(this, TabbedActivity.class); i3.putExtra("TAB_ID", 2); startActivity(i3); } else if (id == R.id.nav_gelir) { Intent i4 = new Intent(this, CalculateActivity.class); i4.putExtra("TAB_ID", 0); startActivity(i4); } else if (id == R.id.nav_karPayi) { Intent i5 = new Intent(this, CalculateActivity.class); i5.putExtra("TAB_ID", 1); startActivity(i5); } else if (id == R.id.nav_agi) { Intent i6 = new Intent(this, CalculateActivity.class); i6.putExtra("TAB_ID", 2); startActivity(i6); } else if (id == R.id.nav_asgariUcret) { Intent i6 = new Intent(this, CalculateActivity.class); i6.putExtra("TAB_ID", 3); startActivity(i6); } else if (id == R.id.nav_kapiciUcret) { Intent i7 = new Intent(this, CalculateActivity.class); i7.putExtra("TAB_ID", 4); startActivity(i7); } else if (id == R.id.nav_gecikmeFaizi) { Intent i8 = new Intent(this, CalculateActivity.class); i8.putExtra("TAB_ID", 5); startActivity(i8); } else if (id == R.id.nav_paylas) { sendIntent(); } else if (id == R.id.nav_rating) { Uri uri = Uri.parse("market://details?id=" + MainActivity.this.getPackageName()); Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri); // To count with Play market backstack, After pressing back button, // to taken back to our application, we need to add following flags to intent. goToMarket.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); try { startActivity(goToMarket); } catch (ActivityNotFoundException e) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "http://play.google.com/store/apps/details?id=" + MainActivity.this.getPackageName()))); } } else if (id == R.id.nav_hakkinda) { showHakkindaDialog(); } DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); drawer.closeDrawer(GravityCompat.START); return true; }
From source file:com.tanmay.blip.fragments.RandomFragment.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.open_in_browser: Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://xkcd.com/" + comic.getNum())); startActivity(intent);//from www . j a va 2 s .co m break; case R.id.transcript: String content = comic.getTranscript(); if (content.equals("")) { content = getResources().getString(R.string.message_no_transcript); } final String speakingContent = content; new MaterialDialog.Builder(getActivity()).title(R.string.title_dialog_transcript).content(content) .negativeText(R.string.negative_text_dialog).neutralText(R.string.neutral_text_dialog_speak) .autoDismiss(false).callback(new MaterialDialog.ButtonCallback() { @Override public void onNegative(MaterialDialog dialog) { super.onNegative(dialog); dialog.dismiss(); } @Override public void onNeutral(MaterialDialog dialog) { super.onNeutral(dialog); SpeechSynthesizer.getInstance().convertToSpeechFlush(speakingContent); } }).dismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { SpeechSynthesizer.getInstance().stopSpeaking(); } }).show(); break; case R.id.img_container: ImageActivity.launch((AppCompatActivity) getActivity(), img, comic.getNum()); break; case R.id.favourite: boolean fav = comic.isFavourite(); comic.setFavourite(!fav); databaseManager.setFavourite(comic.getNum(), !fav); if (fav) { //remove from fav favourite.setColorFilter(getResources().getColor(R.color.icons_dark)); } else { //make fav favourite.setColorFilter(getResources().getColor(R.color.accent)); } break; case R.id.help: Intent explainIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.explainxkcd.com/wiki/index.php/" + comic.getNum())); startActivity(explainIntent); break; case R.id.share: Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND); shareIntent.setType("text/plain"); if (BlipUtils.isLollopopUp()) { shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); } else { shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); } shareIntent.putExtra(Intent.EXTRA_SUBJECT, comic.getTitle()); shareIntent.putExtra(Intent.EXTRA_TEXT, comic.getImg()); startActivity(Intent.createChooser(shareIntent, getActivity().getResources().getString(R.string.tip_share_image_url))); break; } }
From source file:com.kobi.metalsexchange.app.DetailFragment.java
private Intent createShareExchangeRatesIntent() { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, mExchangeRate); return shareIntent; }
From source file:com.ubimobitech.spotifystreamer.PlaybackFragment.java
private void setShareIntent(TrackInfo track) { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT); shareIntent.setType("text/plain"); StringBuilder builder = new StringBuilder(getString(R.string.share_music)); builder.append(track.getArtistName()).append(": " + track.getTrackName()) .append(" " + track.getPreviewUrl()); shareIntent.putExtra(Intent.EXTRA_TEXT, builder.toString()); if (mShareActionProvider != null) { mShareActionProvider.setShareIntent(shareIntent); }/*from w w w. ja v a2 s. c om*/ }