List of usage examples for android.content Intent createChooser
public static Intent createChooser(Intent target, CharSequence title)
From source file:com.codebutler.farebot.activities.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { try {/* w w w .j a v a 2 s .c o m*/ if (item.getItemId() == R.id.supported_cards) { startActivity(new Intent(this, SupportedCardsActivity.class)); return true; } else if (item.getItemId() == R.id.about) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://codebutler.github.com/farebot"))); return true; } else if (item.getItemId() == R.id.import_clipboard) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); onCardsImported(ExportHelper.importCardsXml(this, clipboard.getText().toString())); return true; } else if (item.getItemId() == R.id.import_file) { Uri uri = Uri.fromFile(Environment.getExternalStorageDirectory()); Intent i = new Intent(Intent.ACTION_GET_CONTENT); i.putExtra(Intent.EXTRA_STREAM, uri); i.setType("application/xml"); startActivityForResult(Intent.createChooser(i, "Select File"), SELECT_FILE); return true; } else if (item.getItemId() == R.id.import_sd) { String xml = FileUtils.readFileToString(new File(SD_EXPORT_PATH)); onCardsImported(ExportHelper.importCardsXml(this, xml)); return true; } else if (item.getItemId() == R.id.copy_xml) { ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); clipboard.setText(ExportHelper.exportCardsXml(this)); Toast.makeText(this, "Copied to clipboard.", 5).show(); return true; } else if (item.getItemId() == R.id.share_xml) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, ExportHelper.exportCardsXml(this)); startActivity(intent); return true; } else if (item.getItemId() == R.id.save_xml) { String xml = ExportHelper.exportCardsXml(this); File file = new File(SD_EXPORT_PATH); FileUtils.writeStringToFile(file, xml, "UTF-8"); Toast.makeText(this, "Wrote FareBot-Export.xml to USB Storage.", 5).show(); return true; } else if (item.getItemId() == R.id.prefs) { startActivity(new Intent(this, FareBotPreferenceActivity.class)); } } catch (Exception ex) { Utils.showError(this, ex); } return false; }
From source file:com.crowflying.buildwatch.ConfigurationActivity.java
@Override public boolean onPreferenceClick(Preference preference) { Log.d(LOG_TAG, String.format("Preference %s was clicked...", preference.getKey())); // Call the code for autosetup... if (PREFS_AUTOSETUP.equals(preference.getKey())) { Log.i(LOG_TAG, "Calling XZING."); tracker.trackEvent("configuration", "subscreen", "autosetup", 0L); IntentIntegrator integrator = new IntentIntegrator(this); integrator.setMessageByID(R.string.barcode_scanner_not_installed_message); integrator.initiateScan();/*from www . ja v a 2 s .com*/ return true; } if (PREFS_FORGET_SETTINGS.equals(preference.getKey())) { Log.i(LOG_TAG, "Forgetting all settings"); tracker.trackEvent("configuration", "action", "settings_cleared", 0L); PreferenceManager.getDefaultSharedPreferences(this).edit().clear().commit(); return true; } if (PREFS_KEY_LAUNCH_WEBSITE.equals(preference.getKey())) { Log.i(LOG_TAG, "Launching website"); Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(getString(R.string.config_launch_website_url))); startActivity(i); return true; } if (PREFS_KEY_GCM_TOKEN.equals(preference.getKey())) { String token = getPreferenceManager().getSharedPreferences().getString(PREFS_KEY_GCM_TOKEN, ""); if (!TextUtils.isEmpty(token)) { Log.i(LOG_TAG, "Token clicked. Echoing it to the logfile for convencience: " + token); Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getString(R.string.share_gcm_token_subject)); sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, token); startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_gcm_token_using))); } return true; } return false; }
From source file:arun.com.chromer.webheads.ui.context.WebHeadContextActivity.java
@OnClick(R.id.share_all) public void onShareAllClick() { final CharSequence[] items = new String[] { getString(R.string.comma_seperated), getString(R.string.share_all_list) }; new MaterialDialog.Builder(this).title(R.string.choose_share_method).items(items) .itemsCallbackSingleChoice(0, (dialog, itemView, which, text) -> { if (which == 0) { startActivity(Intent.createChooser( TEXT_SHARE_INTENT.putExtra(EXTRA_TEXT, getCSVUrls().toString()), getString(R.string.share_all))); } else { final ArrayList<Uri> webSites = new ArrayList<>(); for (Website website : websitesAdapter.getWebsites()) { try { webSites.add(Uri.parse(website.preferredUrl())); } catch (Exception ignored) { }/* w ww. j av a 2s. c o m*/ } final Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE); shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, webSites); shareIntent.setType("text/plain"); startActivity(Intent.createChooser(shareIntent, getString(R.string.share_all))); } return false; }).show(); }
From source file:com.activiti.android.app.fragments.content.ContentsFragment.java
@Subscribe public void onDownloadTransferEvent(DownloadTransferEvent event) { if (event.hasException) { Snackbar.make(getActivity().findViewById(R.id.left_panel), event.exception.getMessage(), Snackbar.LENGTH_SHORT).show(); return;//w w w . j a v a2 s . c om } if (waitingDialog != null) { waitingDialog.dismiss(); } try { switch (event.mode) { case ContentTransferSyncAdapter.MODE_SHARE: Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_SUBJECT, event.data.getName()); sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(event.data)); sendIntent.setType(event.mimetype); getActivity().startActivity( Intent.createChooser(sendIntent, getResources().getText(R.string.action_send_file))); break; case ContentTransferSyncAdapter.MODE_OPEN_IN: Intent viewIntent = new Intent(Intent.ACTION_VIEW); viewIntent.putExtra(Intent.EXTRA_SUBJECT, event.data.getName()); viewIntent.setDataAndType(Uri.fromFile(event.data), event.mimetype); startActivity(viewIntent); break; } } catch (ActivityNotFoundException e) { Snackbar.make(getActivity().findViewById(R.id.left_panel), R.string.file_editor_error_open, Snackbar.LENGTH_SHORT).show(); } }
From source file:bizapps.com.healthforusPatient.activity.RegisterActivity.java
private void galleryIntent() { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT);// startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE); }
From source file:com.adkdevelopment.earthquakesurvival.ui.InfoFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.info_fragment, container, false); ImageView backdrop = ButterKnife.findById(getActivity(), R.id.backdrop); FloatingActionButton floatingActionButton = ButterKnife.findById(getActivity(), R.id.fab); mUnbinder = ButterKnife.bind(this, rootView); if (getActivity().getIntent() != null) { int section = getActivity().getIntent().getIntExtra(SurvivalFragment.SECTION, -1); List<String> titles = new ArrayList<>(); List<String> text = new ArrayList<>(); String title = ""; int drawable = -1; switch (section) { case 1://from www. ja v a 2s . c o m titles.addAll(Arrays.asList(getResources().getStringArray(R.array.survival_before_title))); text.addAll(Arrays.asList(getResources().getStringArray(R.array.survival_before_text))); drawable = R.drawable.earth1; title = getString(R.string.survival_before); break; case 2: titles.addAll(Arrays.asList(getResources().getStringArray(R.array.survival_during_title))); text.addAll(Arrays.asList(getResources().getStringArray(R.array.survival_during_text))); drawable = R.drawable.earth2; title = getString(R.string.survival_during); break; case 3: titles.addAll(Arrays.asList(getResources().getStringArray(R.array.survival_after_title))); text.addAll(Arrays.asList(getResources().getStringArray(R.array.survival_after_text))); drawable = R.drawable.earth3; title = getString(R.string.survival_after); break; case 4: title = getString(R.string.survival_resources); titles.addAll(Arrays.asList(getResources().getStringArray(R.array.survival_resources_title))); text.addAll(Arrays.asList(getResources().getStringArray(R.array.survival_resources_text))); drawable = R.drawable.earth3; break; case 5: title = getString(R.string.survival_kit); titles.addAll(Arrays.asList(getResources().getStringArray(R.array.survival_kit_title))); text.addAll(Arrays.asList(getResources().getStringArray(R.array.survival_kit_text))); drawable = R.drawable.earth3; break; default: break; } RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, false); InfoAdapter mRecentAdapter = new InfoAdapter(titles, text); mRecyclerView.setHasFixedSize(true); mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setAdapter(mRecentAdapter); floatingActionButton.setOnClickListener(click -> { if (_rxBus.hasObservers()) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/html"); if (titles.size() > 0 && text.size() > 0) { intent.putExtra(Intent.EXTRA_SUBJECT, titles.get(0)); intent.putExtra(Intent.EXTRA_TEXT, text.get(0)); } _rxBus.send(Intent.createChooser(intent, getString(R.string.send_email))); } }); ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar(); if (actionBar != null) { actionBar.setTitle(title); } Picasso.with(getContext()).load(drawable).error(R.drawable.dropcoverholdon).into(backdrop); } return rootView; }
From source file:com.xengar.android.booksearch.ui.BookDetailActivity.java
private void setShareIntent() { ImageView ivImage = (ImageView) findViewById(R.id.ivBookCover); final TextView tvTitle = (TextView) findViewById(R.id.tvTitle); // Get access to the URI for the bitmap Uri bmpUri = getLocalBitmapUri(ivImage); // Construct a ShareIntent with link to image Intent shareIntent = new Intent(); // Construct a ShareIntent with link to image shareIntent.setAction(Intent.ACTION_SEND); shareIntent.setType("*/*"); shareIntent.putExtra(Intent.EXTRA_TEXT, (String) tvTitle.getText()); shareIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); // Launch share menu startActivity(Intent.createChooser(shareIntent, "Share Image")); }
From source file:com.ckchan.assignment1.ckchan_todolist.MainActivity.java
@Override //Selecting action bar items public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { Settings();/*from w w w . j ava 2 s.c o m*/ return true; } //Handle presses on the action bar items switch (item.getItemId()) { case R.id.summary_info: SummaryInfo(); return true; case R.id.email_all: try { Context context = getApplicationContext(); TaskDatabase taskDatabase = new TaskDatabase(); ; Email email = taskDatabase.loadEmailAddress(context); ArrayList<TodoTask> taskArray = (ArrayList<TodoTask>) taskDatabase.loadTaskData(context); ArrayList<TodoTask> archiveArray = (ArrayList<TodoTask>) taskDatabase.loadArchiveData(context); //StringBuilder code from: //http://stackoverflow.com/questions/12899953/in-java-how-to-append-a-string-more-efficiently StringBuilder stringBuilder = new StringBuilder(); if (email != null) { Intent i = new Intent(Intent.ACTION_SEND); i.setType("message/rfc822"); i.putExtra(Intent.EXTRA_EMAIL, new String[] { email.getAddress() }); i.putExtra(Intent.EXTRA_SUBJECT, "Todo and Archive Tasks"); stringBuilder.append("Todo Tasks\n"); for (TodoTask task : taskArray) { stringBuilder.append(task.getTaskDescription() + "\n"); } stringBuilder.append("Archive Tasks\n"); for (TodoTask task : archiveArray) { stringBuilder.append(task.getTaskDescription() + "\n"); } String emailContent = stringBuilder.toString(); i.putExtra(Intent.EXTRA_TEXT, emailContent); try { startActivity(Intent.createChooser(i, "Send mail...")); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(context, "There are no email clients installed.", Toast.LENGTH_SHORT).show(); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } default: return super.onOptionsItemSelected(item); } }
From source file:com.dm.material.dashboard.candybar.adapters.IntentAdapter.java
private void sendRequest(ComponentName name) { try {//from ww w . ja va 2 s.co m Intent intent = new Intent(Intent.ACTION_SEND); intent = addIntentExtra(intent); intent.setComponent(name); intent.addCategory(Intent.CATEGORY_LAUNCHER); mContext.startActivity(intent); } catch (IllegalArgumentException e) { try { Intent intent = new Intent(Intent.ACTION_SEND); intent = addIntentExtra(intent); mContext.startActivity( Intent.createChooser(intent, mContext.getResources().getString(R.string.email_client))); } catch (ActivityNotFoundException e1) { LogUtil.e(Log.getStackTraceString(e1)); } } }
From source file:com.dexin.MainActivity.java
public void startGalleryChooser() { if (PermissionUtils.requestPermission(this, GALLERY_PERMISSIONS_REQUEST, Manifest.permission.READ_EXTERNAL_STORAGE)) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select a photo"), GALLERY_IMAGE_REQUEST); }/*from w ww .jav a 2s. co m*/ }