List of usage examples for android.content Intent createChooser
public static Intent createChooser(Intent target, CharSequence title)
From source file:com.amaze.carbonfilemanager.utils.files.Futils.java
public void openunknown(DocumentFile f, Context c, boolean forcechooser) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); String type = f.getType();/*from www .j ava2 s . c om*/ if (type != null && type.trim().length() != 0 && !type.equals("*/*")) { intent.setDataAndType(f.getUri(), type); Intent startintent; if (forcechooser) startintent = Intent.createChooser(intent, c.getResources().getString(R.string.openwith)); else startintent = intent; try { c.startActivity(startintent); } catch (ActivityNotFoundException e) { e.printStackTrace(); Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show(); openWith(f, c); } } else { openWith(f, c); } }
From source file:com.app.uafeed.fragment.EntryFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mEntriesIds != null) { Activity activity = getActivity(); switch (item.getItemId()) { case R.id.menu_star: { mFavorite = !mFavorite;//from www .jav a 2 s .c om if (mFavorite) { item.setTitle(R.string.menu_unstar).setIcon(R.drawable.rating_important); } else { item.setTitle(R.string.menu_star).setIcon(R.drawable.rating_not_important); } final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentValues values = new ContentValues(); values.put(EntryColumns.IS_FAVORITE, mFavorite ? 1 : 0); ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, values, null, null); // Update the cursor Cursor updatedCursor = cr.query(uri, null, null, null, null); updatedCursor.moveToFirst(); mEntryPagerAdapter.setUpdatedCursor(mCurrentPagerPos, updatedCursor); } }.start(); break; } case R.id.menu_share: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); String link = cursor.getString(mLinkPos); if (link != null) { String title = cursor.getString(mTitlePos); startActivity(Intent.createChooser( new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_SUBJECT, title) .putExtra(Intent.EXTRA_TEXT, link).setType(Constants.MIMETYPE_TEXT_PLAIN), getString(R.string.menu_share))); } break; } case R.id.menu_full_screen: { toggleFullScreen(); break; } case R.id.menu_copy_clipboard: { Cursor cursor = mEntryPagerAdapter.getCursor(mCurrentPagerPos); String link = cursor.getString(mLinkPos); ClipboardManager clipboard = (ClipboardManager) activity .getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied Text", link); clipboard.setPrimaryClip(clip); Toast.makeText(activity, R.string.copied_clipboard, Toast.LENGTH_SHORT).show(); break; } case R.id.menu_mark_as_unread: { final Uri uri = ContentUris.withAppendedId(mBaseUri, mEntriesIds[mCurrentPagerPos]); new Thread() { @Override public void run() { ContentResolver cr = MainApplication.getContext().getContentResolver(); cr.update(uri, FeedData.getUnreadContentValues(), null, null); } }.start(); activity.finish(); break; } } } return true; }
From source file:com.dvdprime.mobile.android.ui.DocumentViewActivity.java
@Override public boolean onContextItemSelected(android.view.MenuItem menuItem) { switch (menuItem.getItemId()) { default:/*from w w w . j a v a 2 s. c o m*/ case CONTEXT_MENU_COPY_URL: SystemUtil.copyToClipboard(mActivity, contextUrl); break; case CONTEXT_MENU_BROWSER: AndroidUtil.clickedLinkAction(mActivity, contextUrl); break; case CONTEXT_MENU_SHARE_LINK: Intent localIntent = new Intent("android.intent.action.SEND"); localIntent.setType("text/plain"); localIntent.putExtra("android.intent.extra.TEXT", contextUrl); startActivity(Intent.createChooser(localIntent, getString(R.string.action_bar_share_with))); break; case CONTEXT_MENU_SAVE_IMAGE: DownloadManager dm = (DownloadManager) getSystemService("download"); DownloadManager.Request req = new DownloadManager.Request(Uri.parse(this.contextUrl)); req.setTitle("DP Downloader"); req.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, StringUtil.substringAfterLast(this.contextUrl, "/")); req.setAllowedNetworkTypes(DownloadManager.PAUSED_QUEUED_FOR_WIFI); req.setMimeType("image/" + StringUtil.substringAfterLast(contextUrl, ".")); File localFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); if (!(localFile.exists())) localFile.mkdirs(); dm.enqueue(req); break; } return false; }
From source file:com.vuze.android.remote.AndroidUtils.java
public static void openFileChooser(Activity activity, String mimeType, int requestCode) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(mimeType);//w w w .j a va2s . c o m intent.addCategory(Intent.CATEGORY_OPENABLE); // special intent for Samsung file manager Intent sIntent = new Intent("com.sec.android.app.myfiles.PICK_DATA"); sIntent.putExtra("CONTENT_TYPE", mimeType); sIntent.addCategory(Intent.CATEGORY_DEFAULT); Intent chooserIntent; if (activity.getPackageManager().resolveActivity(sIntent, 0) != null) { chooserIntent = Intent.createChooser(sIntent, "Open file"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { intent }); } else { chooserIntent = Intent.createChooser(intent, "Open file"); } if (chooserIntent != null) { try { activity.startActivityForResult(chooserIntent, requestCode); return; } catch (android.content.ActivityNotFoundException ex) { } } Toast.makeText(activity.getApplicationContext(), activity.getResources().getString(R.string.no_file_chooser), Toast.LENGTH_SHORT).show(); }
From source file:com.android.deskclock.stopwatch.StopwatchFragment.java
/** * Send stopwatch time and lap times to an external sharing application. */// w w w . j ava 2s .c o m private void doShare() { final String[] subjects = getResources().getStringArray(R.array.sw_share_strings); final String subject = subjects[(int) (Math.random() * subjects.length)]; final String text = mLapsAdapter.getShareText(); @SuppressLint("InlinedApi") @SuppressWarnings("deprecation") final Intent shareIntent = new Intent(Intent.ACTION_SEND) .addFlags(Utils.isLOrLater() ? Intent.FLAG_ACTIVITY_NEW_DOCUMENT : Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) .putExtra(Intent.EXTRA_SUBJECT, subject).putExtra(Intent.EXTRA_TEXT, text).setType("text/plain"); final Context context = getActivity(); final String title = context.getString(R.string.sw_share_button); final Intent shareChooserIntent = Intent.createChooser(shareIntent, title); try { context.startActivity(shareChooserIntent); } catch (ActivityNotFoundException anfe) { LogUtils.e("No compatible receiver is found"); } }
From source file:io.ingame.squarecamera.CameraLauncher.java
/** * Get image from photo library.//from w ww . j a va 2 s .c o m * * @param srcType The album to get image from. * @param returnType Set the type of image to return. * @param encodingType */ // TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do! // TODO: Images from kitkat filechooser not going into crop function public void getImage(int srcType, int returnType, int encodingType) { Intent intent = new Intent(); String title = GET_PICTURE; croppedUri = null; if (this.mediaType == PICTURE) { intent.setType("image/*"); if (this.allowEdit) { intent.setAction(Intent.ACTION_PICK); intent.putExtra("crop", "true"); if (targetWidth > 0) { intent.putExtra("outputX", targetWidth); } if (targetHeight > 0) { intent.putExtra("outputY", targetHeight); } if (targetHeight > 0 && targetWidth > 0 && targetWidth == targetHeight) { intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); } File photo = createCaptureFile(encodingType); croppedUri = Uri.fromFile(photo); setOutputUri(intent, croppedUri); } else { intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } } else if (this.mediaType == VIDEO) { intent.setType("video/*"); title = GET_VIDEO; intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } else if (this.mediaType == ALLMEDIA) { // I wanted to make the type 'image/*, video/*' but this does not work on all versions // of android so I had to go with the wildcard search. intent.setType("*/*"); title = GET_All; intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); } if (this.cordova != null) { this.cordova.startActivityForResult((CordovaPlugin) this, Intent.createChooser(intent, new String(title)), (srcType + 1) * 16 + returnType + 1); } }
From source file:com.richtodd.android.quiltdesign.app.BlockEditActivity.java
@Override public void onShareOptionsPositiveClick(DialogFragment dialog, RenderStyles renderStyle, RenderFormats renderFormat, String intentAction) throws Exception { Uri uriFile;//from w w w . java 2 s. c o m String type; switch (renderFormat) { case Bitmap: uriFile = saveBitmap(renderStyle); type = "image/png"; break; case PDF: uriFile = savePDF(renderStyle); type = "application/pdf"; break; case QuiltDesign: uriFile = saveQuiltDesign(); type = "application/vnd.richtodd.quiltdesign"; break; default: throw new IllegalArgumentException("Unknown render format " + renderFormat); } Intent intent = new Intent(intentAction); if (intentAction.equals(Intent.ACTION_SEND)) { intent.putExtra(Intent.EXTRA_STREAM, uriFile); intent.setType(type); startActivity(Intent.createChooser(intent, "Share With")); } else { intent.setDataAndType(uriFile, type); startActivity(Intent.createChooser(intent, "View With")); } }
From source file:com.nexes.manager.EventHandler.java
/** * This method, handles the button presses of the top buttons found in the * Main activity.//www . jav a2 s. c o m */ @Override public void onClick(View v) { switch (v.getId()) { case R.id.back_button: if (mFileMang.getCurrentDir() != "/") { if (multi_select_flag) { mDelegate.killMultiSelect(true); Toast.makeText(mContext, "Multi-select is now off", Toast.LENGTH_SHORT).show(); } stopThumbnailThread(); updateDirectory(mFileMang.getPreviousDir()); if (mPathLabel != null) mPathLabel.setText(mFileMang.getCurrentDir()); } break; case R.id.home_button: if (multi_select_flag) { mDelegate.killMultiSelect(true); Toast.makeText(mContext, "Multi-select is now off", Toast.LENGTH_SHORT).show(); } stopThumbnailThread(); updateDirectory(mFileMang.setHomeDir("/sdcard")); if (mPathLabel != null) mPathLabel.setText(mFileMang.getCurrentDir()); break; case R.id.info_button: Intent info = new Intent(mContext, DirectoryInfo.class); info.putExtra("PATH_NAME", mFileMang.getCurrentDir()); mContext.startActivity(info); break; case R.id.help_button: Intent help = new Intent(mContext, HelpManager.class); mContext.startActivity(help); break; case R.id.manage_button: display_dialog(MANAGE_DIALOG); break; case R.id.multiselect_button: if (multi_select_flag) { mDelegate.killMultiSelect(true); } else { LinearLayout hidden_lay = (LinearLayout) ((Activity) mContext).findViewById(R.id.hidden_buttons); multi_select_flag = true; hidden_lay.setVisibility(LinearLayout.VISIBLE); } break; /* * three hidden buttons for multiselect */ case R.id.hidden_attach: /* check if user selected objects before going further */ if (mMultiSelectData == null || mMultiSelectData.isEmpty()) { mDelegate.killMultiSelect(true); break; } ArrayList<Uri> uris = new ArrayList<Uri>(); int length = mMultiSelectData.size(); Intent mail_int = new Intent(); mail_int.setAction(android.content.Intent.ACTION_SEND_MULTIPLE); mail_int.setType("application/mail"); mail_int.putExtra(Intent.EXTRA_BCC, ""); mail_int.putExtra(Intent.EXTRA_SUBJECT, " "); for (int i = 0; i < length; i++) { File file = new File(mMultiSelectData.get(i)); uris.add(Uri.fromFile(file)); } mail_int.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); mContext.startActivity(Intent.createChooser(mail_int, "Email using...")); mDelegate.killMultiSelect(true); break; case R.id.hidden_move: case R.id.hidden_copy: /* check if user selected objects before going further */ if (mMultiSelectData == null || mMultiSelectData.isEmpty()) { mDelegate.killMultiSelect(true); break; } if (v.getId() == R.id.hidden_move) delete_after_copy = true; mInfoLabel.setText("Holding " + mMultiSelectData.size() + " file(s)"); mDelegate.killMultiSelect(false); break; case R.id.hidden_delete: /* check if user selected objects before going further */ if (mMultiSelectData == null || mMultiSelectData.isEmpty()) { mDelegate.killMultiSelect(true); break; } final String[] data = new String[mMultiSelectData.size()]; int at = 0; for (String string : mMultiSelectData) data[at++] = string; AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage( "Are you sure you want to delete " + data.length + " files? This cannot be " + "undone."); builder.setCancelable(false); builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new BackgroundWork(DELETE_TYPE).execute(data); mDelegate.killMultiSelect(true); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mDelegate.killMultiSelect(true); dialog.cancel(); } }); builder.create().show(); break; } }
From source file:com.amaze.filemanager.utils.Futils.java
public void openunknown(File f, Context c, boolean forcechooser) { Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); String type = MimeTypes.getMimeType(f); if (type != null && type.trim().length() != 0 && !type.equals("*/*")) { Uri uri = fileToContentUri(c, f); if (uri == null) uri = Uri.fromFile(f);//from ww w .ja v a 2 s .c o m intent.setDataAndType(uri, type); Intent startintent; if (forcechooser) startintent = Intent.createChooser(intent, c.getResources().getString(R.string.openwith)); else startintent = intent; try { c.startActivity(startintent); } catch (ActivityNotFoundException e) { e.printStackTrace(); Toast.makeText(c, R.string.noappfound, Toast.LENGTH_SHORT).show(); openWith(f, c); } } else { openWith(f, c); } }
From source file:com.app.sample.chatting.activity.chat.ChatActivity.java
/** * ?//from ww w .ja v a2 s. c o m */ private void goToAlbum() { Intent intent; if (Build.VERSION.SDK_INT < 19) { intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, ""), REQUEST_CODE_GETIMAGE_BYSDCARD); } else { intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); intent.setType("image/*"); startActivityForResult(Intent.createChooser(intent, ""), REQUEST_CODE_GETIMAGE_BYSDCARD); } }