List of usage examples for android.content Intent createChooser
public static Intent createChooser(Intent target, CharSequence title)
From source file:com.roamprocess1.roaming4world.ui.messages.MessageActivity.java
private void showAudioFileChooser() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("audio/*"); intent.addCategory(Intent.CATEGORY_OPENABLE); try {//from w w w . ja va 2 s . co m startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), AUDIO_REQUEST); } catch (android.content.ActivityNotFoundException ex) { // Potentially direct the user to the Market with a Dialog Toast.makeText(this, "Please install a File Manager.", Toast.LENGTH_SHORT).show(); } }
From source file:com.dwdesign.tweetings.fragment.BaseStatusesListFragment.java
@Override public boolean onMenuItemClick(final MenuItem item) { final ParcelableStatus status = mSelectedStatus; if (status == null) return false; final long account_id = getDefaultAccountId(mApplication); switch (item.getItemId()) { case MENU_VIEW: { openStatus(getActivity(), status); break;//from w w w . jav a 2 s.co m } case MENU_SHARE: { final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, "@" + status.screen_name + ": " + status.text_plain); startActivity(Intent.createChooser(intent, getString(R.string.share))); break; } case MENU_TRANSLATE: { translate(status); break; } case MENU_RETWEET: { if (isMyRetweet(status)) { mService.destroyStatus(status.account_id, status.status_id); } else { final long id_to_retweet = mSelectedStatus.is_retweet && mSelectedStatus.retweet_id > 0 ? mSelectedStatus.retweet_id : mSelectedStatus.status_id; mService.retweetStatus(status.account_id, id_to_retweet); } break; } case MENU_QUOTE: { final Intent intent = new Intent(INTENT_ACTION_COMPOSE); final Bundle bundle = new Bundle(); bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id); bundle.putBoolean(INTENT_KEY_IS_QUOTE, true); bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.text_plain)); intent.putExtras(bundle); startActivity(intent); break; } case MENU_QUOTE_REPLY: { final Intent intent = new Intent(INTENT_ACTION_COMPOSE); final Bundle bundle = new Bundle(); bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id); bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id); bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name); bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name); bundle.putBoolean(INTENT_KEY_IS_QUOTE, true); bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.text_plain)); intent.putExtras(bundle); startActivity(intent); break; } case MENU_ADD_TO_BUFFER: { final Intent intent = new Intent(INTENT_ACTION_COMPOSE); final Bundle bundle = new Bundle(); bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id); bundle.putBoolean(INTENT_KEY_IS_BUFFER, true); bundle.putString(INTENT_KEY_TEXT, getQuoteStatus(getActivity(), status.screen_name, status.text_plain)); intent.putExtras(bundle); startActivity(intent); break; } case MENU_REPLY: { final Intent intent = new Intent(INTENT_ACTION_COMPOSE); final Bundle bundle = new Bundle(); final List<String> mentions = new Extractor().extractMentionedScreennames(status.text_plain); mentions.remove(status.screen_name); mentions.add(0, status.screen_name); bundle.putStringArray(INTENT_KEY_MENTIONS, mentions.toArray(new String[mentions.size()])); bundle.putLong(INTENT_KEY_ACCOUNT_ID, status.account_id); bundle.putLong(INTENT_KEY_IN_REPLY_TO_ID, status.status_id); bundle.putString(INTENT_KEY_IN_REPLY_TO_TWEET, status.text_plain); bundle.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, status.screen_name); bundle.putString(INTENT_KEY_IN_REPLY_TO_NAME, status.name); intent.putExtras(bundle); startActivity(intent); break; } case MENU_FAV: { if (mSelectedStatus.is_favorite) { mService.destroyFavorite(status.account_id, status.status_id); } else { mService.createFavorite(status.account_id, status.status_id); } break; } case MENU_CONVERSATION: { openConversation(getActivity(), status.account_id, status.status_id); break; } case MENU_DELETE: { mService.destroyStatus(status.account_id, status.status_id); break; } case MENU_EXTENSIONS: { final Intent intent = new Intent(INTENT_ACTION_EXTENSION_OPEN_STATUS); final Bundle extras = new Bundle(); extras.putParcelable(INTENT_KEY_STATUS, status); intent.putExtras(extras); startActivity(Intent.createChooser(intent, getString(R.string.open_with_extensions))); break; } case MENU_MULTI_SELECT: { if (!mApplication.isMultiSelectActive()) { mApplication.startMultiSelect(); } final NoDuplicatesLinkedList<Object> list = mApplication.getSelectedItems(); if (!list.contains(status)) { list.add(status); } break; } case MENU_BLOCK: { mService.createBlock(account_id, status.user_id); break; } case MENU_REPORT_SPAM: { mService.reportSpam(account_id, status.user_id); break; } case MENU_MUTE_USER: { final String screen_name = status.screen_name; final Uri uri = Filters.Users.CONTENT_URI; final ContentValues values = new ContentValues(); final SharedPreferences.Editor editor = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE).edit(); final ContentResolver resolver = getContentResolver(); values.put(Filters.Users.TEXT, screen_name); resolver.delete(uri, Filters.Users.TEXT + " = '" + screen_name + "'", null); resolver.insert(uri, values); editor.putBoolean(PREFERENCE_KEY_ENABLE_FILTER, true).commit(); Toast.makeText(getActivity(), R.string.user_muted, Toast.LENGTH_SHORT).show(); break; } case MENU_MAKE_GAP: { Uri uri = Statuses.CONTENT_URI; final Uri query_uri = buildQueryUri(uri, false); ContentResolver mResolver = getContentResolver(); final ContentValues values = new ContentValues(); values.put(Statuses.IS_GAP, 1); final StringBuilder where = new StringBuilder(); where.append(Statuses.ACCOUNT_ID + "=" + account_id); where.append(" AND " + Statuses.STATUS_ID + "=" + status.status_id); mResolver.update(query_uri, values, where.toString(), null); getActivity().sendBroadcast(new Intent(BROADCAST_FILTERS_UPDATED).putExtra(INTENT_KEY_SUCCEED, true)); break; } case MENU_COPY: { final CharSequence text = Html.fromHtml(status.text_html); if (ClipboardUtils.setText(getActivity(), text)) { Toast.makeText(getActivity(), R.string.text_copied, Toast.LENGTH_SHORT).show(); } break; } } return true; }
From source file:com.androidquery.simplefeed.activity.PostActivity.java
public void galleryClicked(View view) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, getString(R.string.photo)), Constants.ACTIVITY_GALLERY); }
From source file:li.barter.fragments.EditProfileFragment.java
@Override public void onDialogClick(final DialogInterface dialog, final int which) { if ((mChoosePictureDialogFragment != null) && mChoosePictureDialogFragment.getDialog().equals(dialog)) { if (which == 0) { // Pick from camera final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraImageCaptureUri); try { startActivityForResult(Intent.createChooser(intent, getString(R.string.complete_action_using)), PICK_FROM_CAMERA); } catch (final ActivityNotFoundException e) { e.printStackTrace();/*from ww w. jav a 2s.c o m*/ } } else if (which == 1) { // pick from file final Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, getString(R.string.complete_action_using)), PICK_FROM_FILE); } } else { super.onDialogClick(dialog, which); } }
From source file:br.com.anteros.vendas.gui.AnexoCadastroActivity.java
/** * Seleciona outros tipos de arquivos para anexar */// www . j a v a 2 s . c o m private void selecionarOutrosTiposArquivo() { Intent intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("file/*"); startActivityForResult(Intent.createChooser(intent, "Selecione"), SELECIONAR_ARQUIVO); }
From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedPost.java
public static void onActionMenuItemSelected(final RedditPreparedPost post, final Fragment fragmentParent, final Action action) { final Activity activity = fragmentParent.getSupportActivity(); switch (action) { case UPVOTE:/*ww w . ja v a2 s.c o m*/ post.action(activity, RedditAPI.RedditAction.UPVOTE); break; case DOWNVOTE: post.action(activity, RedditAPI.RedditAction.DOWNVOTE); break; case UNVOTE: post.action(activity, RedditAPI.RedditAction.UNVOTE); break; case SAVE: post.action(activity, RedditAPI.RedditAction.SAVE); break; case UNSAVE: post.action(activity, RedditAPI.RedditAction.UNSAVE); break; case HIDE: post.action(activity, RedditAPI.RedditAction.HIDE); break; case UNHIDE: post.action(activity, RedditAPI.RedditAction.UNHIDE); break; case REPORT: new AlertDialog.Builder(activity).setTitle(R.string.action_report) .setMessage(R.string.action_report_sure) .setPositiveButton(R.string.action_report, new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { post.action(activity, RedditAPI.RedditAction.REPORT); // TODO update the view to show the result // TODO don't forget, this also hides } }).setNegativeButton(R.string.dialog_cancel, null).show(); break; case EXTERNAL: { final Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(post.url)); activity.startActivity(intent); break; } case SELFTEXT_LINKS: { final HashSet<String> linksInComment = LinkHandler .computeAllLinks(StringEscapeUtils.unescapeHtml4(post.src.selftext)); if (linksInComment.isEmpty()) { General.quickToast(activity, R.string.error_toast_no_urls_in_self); } else { final String[] linksArr = linksInComment.toArray(new String[linksInComment.size()]); final AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setItems(linksArr, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { LinkHandler.onLinkClicked(activity, linksArr[which], false, post.src); dialog.dismiss(); } }); final AlertDialog alert = builder.create(); alert.setTitle(R.string.action_selftext_links); alert.setCanceledOnTouchOutside(true); alert.show(); } break; } case SAVE_IMAGE: { final RedditAccount anon = RedditAccountManager.getAnon(); CacheManager.getInstance(activity) .makeRequest(new CacheRequest(General.uriFromString(post.imageUrl), anon, null, Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY, Constants.FileType.IMAGE, false, false, false, activity) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onDownloadNecessary() { General.quickToast(context, R.string.download_downloading); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(RequestFailureType type, Throwable t, StatusLine status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status); General.showResultDialog(activity, error); } @Override protected void onProgress(long bytesRead, long totalBytes) { } @Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { File dst = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), General.uriFromString(post.imageUrl).getPath()); if (dst.exists()) { int count = 0; while (dst.exists()) { count++; dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), count + "_" + General.uriFromString(post.imageUrl).getPath().substring(1)); } } try { General.copyFile(cacheFile.getInputStream(), dst); } catch (IOException e) { notifyFailure(RequestFailureType.STORAGE, e, null, "Could not copy file"); return; } activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + dst.getAbsolutePath()))); General.quickToast(context, context.getString(R.string.action_save_image_success) + " " + dst.getAbsolutePath()); } }); break; } case SHARE: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, post.title); mailer.putExtra(Intent.EXTRA_TEXT, post.url); activity.startActivity(Intent.createChooser(mailer, activity.getString(R.string.action_share))); break; } case SHARE_COMMENTS: { final Intent mailer = new Intent(Intent.ACTION_SEND); mailer.setType("text/plain"); mailer.putExtra(Intent.EXTRA_SUBJECT, "Comments for " + post.title); mailer.putExtra(Intent.EXTRA_TEXT, Constants.Reddit.getUri(Constants.Reddit.PATH_COMMENTS + post.idAlone).toString()); activity.startActivity( Intent.createChooser(mailer, activity.getString(R.string.action_share_comments))); break; } case COPY: { ClipboardManager manager = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE); manager.setText(post.url); break; } case GOTO_SUBREDDIT: { final RedditSubreddit subreddit = new RedditSubreddit("/r/" + post.src.subreddit, "/r/" + post.src.subreddit, true); final Intent intent = new Intent(activity, PostListingActivity.class); intent.putExtra("subreddit", subreddit); activity.startActivityForResult(intent, 1); break; } case USER_PROFILE: UserProfileDialog.newInstance(post.src.author).show(activity); break; case PROPERTIES: PostPropertiesDialog.newInstance(post.src).show(activity); break; case COMMENTS: ((RedditPostView.PostSelectionListener) fragmentParent).onPostCommentsSelected(post); break; case LINK: ((RedditPostView.PostSelectionListener) fragmentParent).onPostSelected(post); break; case COMMENTS_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) fragmentParent).onPostCommentsSelected(post); break; case LINK_SWITCH: if (!(activity instanceof MainActivity)) activity.finish(); ((RedditPostView.PostSelectionListener) fragmentParent).onPostSelected(post); break; case ACTION_MENU: showActionMenu(activity, fragmentParent, post); break; case REPLY: final Intent intent = new Intent(activity, CommentReplyActivity.class); intent.putExtra("parentIdAndType", post.idAndType); activity.startActivity(intent); break; } }
From source file:org.bwgz.quotation.activity.QuotationActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { boolean result = false; switch (item.getItemId()) { case R.id.actionbar_back: { Log.d(TAG, String.format("onOptionsItemSelected - actionbar_back")); if (history.hasBack()) { loadQuote(history.back());/*w w w. java2 s . com*/ } menu.findItem(R.id.actionbar_back).setEnabled(history.hasBack()); menu.findItem(R.id.actionbar_forward).setEnabled(history.hasForward()); EasyTracker.getInstance(this) .send(MapBuilder.createEvent("ui_action", "button_press", "menu_back", null).build()); result = true; break; } case R.id.actionbar_forward: { Log.d(TAG, String.format("onOptionsItemSelected - actionbar_forward")); if (history.hasForward()) { loadQuote(history.forward()); } menu.findItem(R.id.actionbar_back).setEnabled(history.hasBack()); menu.findItem(R.id.actionbar_forward).setEnabled(history.hasForward()); EasyTracker.getInstance(this) .send(MapBuilder.createEvent("ui_action", "button_press", "menu_forward", null).build()); result = true; break; } case R.id.actionbar_new: { loadRandomQuote(); EasyTracker.getInstance(this) .send(MapBuilder.createEvent("ui_action", "button_press", "menu_new", null).build()); result = true; break; } case R.id.actionbar_share: { CharSequence text = ((TextView) findViewById(R.id.quotation)).getText(); if (text != null && text.length() != 0) { StringBuilder buffer = new StringBuilder(); buffer.append(text); text = ((TextView) findViewById(R.id.author)).getText(); if (text != null && text.length() != 0) { buffer.append(" ... "); buffer.append(text); } Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_TEXT, buffer.toString()); startActivity(Intent.createChooser(intent, getResources().getText(R.string.sharing_quote))); } EasyTracker.getInstance(this) .send(MapBuilder.createEvent("ui_action", "button_press", "menu_share", null).build()); result = true; break; } case R.id.settings: { Intent intent = new Intent().setClass(this, SettingsActivity.class); startActivity(intent); EasyTracker.getInstance(this) .send(MapBuilder.createEvent("ui_action", "button_press", "menu_settings", null).build()); result = true; break; } } return result; }
From source file:com.bitants.wally.fragments.ImageZoomFragment.java
private void setImageAsWallpaperPicker(Uri fileUri) { Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); intent.setType("image/*"); MimeTypeMap map = MimeTypeMap.getSingleton(); String mimeType = map.getMimeTypeFromExtension("png"); intent.setDataAndType(fileUri, mimeType); intent.putExtra("mimeType", mimeType); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(intent, getString(R.string.action_set_as))); }
From source file:com.adamas.client.android.MainActivity.java
@Override 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(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } else if (id == R.id.action_scan_qr_code) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { IntentIntegrator integrator = new IntentIntegrator(this); integrator.initiateScan();/*from w w w .j a v a 2s . c o m*/ } else { checkCameraPermission(); } } else if (id == R.id.action_delete_connector) { if (_connectorfragment != null) { _connectorfragment.deleteConnector(_selectedAdamasConnector); } } else if (id == R.id.action_add_connector_manually) { Intent intent = new Intent(this, AddConnectorActivity.class); startActivityForResult(intent, MANUALLY_ADD_CONNECTOR_REQUEST_CODE); } else if (id == R.id.action_edit_connector) { Intent intent = new Intent(this, EditConnectorActivity.class); Bundle mBundle = new Bundle(); mBundle.putSerializable(EditConnectorActivity.ADAMAS_CONNECTOR, _selectedAdamasConnector); intent.putExtras(mBundle); startActivityForResult(intent, MANUALLY_EDIT_CONNECTOR_REQUEST_CODE); } else if (id == R.id.action_import_connector_from_text) { Intent intent = new Intent(this, ImportTextActivity.class); startActivityForResult(intent, IMPORT_FROM_TEXT_REQUEST_CODE); } else if (id == R.id.action_import_connector_from_image) { if (false) { FileChooser fileChooser = new FileChooser(this); fileChooser.setFileListener(new FileChooser.FileSelectedListener() { @Override public void fileSelected(final File file) { String name = file.getAbsolutePath(); name = name; } }); fileChooser.showDialog(); } else { // this is much better Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .getAbsolutePath()); intent.setDataAndType(uri, "image/jpeg"); startActivityForResult(Intent.createChooser(intent, getString(R.string.open)), IMPORT_FROM_FILE_REQUEST_CODE); } } return super.onOptionsItemSelected(item); }
From source file:com.androzic.MainActivity.java
@Override public void onWaypointShare(Waypoint waypoint) { Intent i = new Intent(android.content.Intent.ACTION_SEND); i.setType("text/plain"); i.putExtra(Intent.EXTRA_SUBJECT, R.string.currentloc); String coords = StringFormatter.coordinates(" ", waypoint.latitude, waypoint.longitude); i.putExtra(Intent.EXTRA_TEXT, waypoint.name + " @ " + coords); startActivity(Intent.createChooser(i, getString(R.string.menu_share))); }