List of usage examples for android.content Intent ACTION_GET_CONTENT
String ACTION_GET_CONTENT
To view the source code for android.content Intent ACTION_GET_CONTENT.
Click Source Link
From source file:io.ingame.squarecamera.CameraLauncher.java
/** * Get image from photo library.//w w w.j a v a2s . 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.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java
/** * Get image from photo library./*from w w w .ja v a2s . c om*/ * * @param quality * Compression quality hint (0-100: 0=low quality & high * compression, 100=compress of max quality) * @param srcType * The album to get image from. * @param returnType * Set the type of image to return. */ // TODO: Images selected from SDCARD don't display correctly, but from // CAMERA ALBUM do! public void getImage(int srcType, int returnType) { final int srcTypeFinal = srcType; final int returnTypeFinal = returnType; String[] choices = { "Upload a Photo", "Upload a Video" }; AlertDialog.Builder builder = new AlertDialog.Builder(this.cordova.getActivity()); builder.setItems(choices, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Log.d(LOG_TAG, "Index #" + which + " chosen."); Intent intent = new Intent(); if (which == 0) { // set up photo intent WsiCameraLauncher.this.mediaType = PICTURE; intent.setType("image/*"); } else if (which == 1) { // set up video intent WsiCameraLauncher.this.mediaType = VIDEO; intent.setType("video/*"); } else { WsiCameraLauncher.this.failPicture("Selection cancelled."); return; } intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); if (WsiCameraLauncher.this.cordova != null) { WsiCameraLauncher.this.cordova.startActivityForResult((CordovaPlugin) WsiCameraLauncher.this, Intent.createChooser(intent, new String("Pick")), (srcTypeFinal + 1) * 16 + returnTypeFinal + 1); } } }); builder.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) { dialog.cancel(); WsiCameraLauncher.this.failPicture("Selection cancelled."); return true; } return false; } }); builder.show(); }
From source file:com.google.android.apps.muzei.gallery.GallerySettingsActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { super.onPrepareOptionsMenu(menu); // Make sure the 'Import photos' MenuItem is set up properly based on the number of // activities that handle ACTION_GET_CONTENT // 0 = hide the MenuItem // 1 = show 'Import photos from APP_NAME' to go to the one app that exists // 2 = show 'Import photos...' to have the user pick which app to import photos from Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); List<ResolveInfo> getContentActivities = getPackageManager().queryIntentActivities(intent, 0); mGetContentActivites.clear();// w w w .j a va 2 s. c om for (ResolveInfo info : getContentActivities) { // Filter out the default system UI if (!TextUtils.equals(info.activityInfo.packageName, "com.android.documentsui")) { mGetContentActivites.add(info.activityInfo); } } // Hide the 'Import photos' action if there are no activities found MenuItem importPhotosMenuItem = menu.findItem(R.id.action_import_photos); importPhotosMenuItem.setVisible(!mGetContentActivites.isEmpty()); // If there's only one app that supports ACTION_GET_CONTENT, tell the user what that app is if (mGetContentActivites.size() == 1) { importPhotosMenuItem.setTitle(getString(R.string.gallery_action_import_photos_from, mGetContentActivites.get(0).loadLabel(getPackageManager()))); } else { importPhotosMenuItem.setTitle(R.string.gallery_action_import_photos); } return true; }
From source file:com.cyanogenmod.eleven.ui.activities.HomeActivity.java
/** * Starts an activity for result that returns an image from the Gallery. */// w w w . j av a 2 s .c om public void selectNewPhoto(String key) { mKey = key; // Now open the gallery final Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); intent.setType("image/*"); startActivityForResult(intent, NEW_PHOTO); }
From source file:com.silentcircle.contacts.detail.PhotoSelectionHandler.java
/** * Constructs an intent for picking a photo from Gallery, cropping it and returning the bitmap. *//*from ww w .j a v a 2s . c o m*/ private Intent getPhotoPickIntent(String photoFile) { final String croppedPhotoPath = ContactPhotoUtils.pathForCroppedPhoto(mContext, photoFile); final Uri croppedPhotoUri = Uri.fromFile(new File(croppedPhotoPath)); final Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); intent.setType("image/*"); ContactPhotoUtils.addGalleryIntentExtras(intent, croppedPhotoUri, mPhotoPickSize); return intent; }
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 av a 2s .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:biz.bokhorst.xprivacy.ActivityShare.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Check privacy service client if (!PrivacyService.checkClient()) return;//w ww .j av a 2 s. c o m // Get data int userId = Util.getUserId(Process.myUid()); final Bundle extras = getIntent().getExtras(); final String action = getIntent().getAction(); final int[] uids = (extras != null && extras.containsKey(cUidList) ? extras.getIntArray(cUidList) : new int[0]); final String restrictionName = (extras != null ? extras.getString(cRestriction) : null); int choice = (extras != null && extras.containsKey(cChoice) ? extras.getInt(cChoice) : -1); if (action.equals(ACTION_EXPORT)) mFileName = (extras != null && extras.containsKey(cFileName) ? extras.getString(cFileName) : null); // License check if (action.equals(ACTION_IMPORT) || action.equals(ACTION_EXPORT)) { if (!Util.isProEnabled() && Util.hasProLicense(this) == null) { Util.viewUri(this, ActivityMain.cProUri); finish(); return; } } else if (action.equals(ACTION_FETCH) || (action.equals(ACTION_TOGGLE) && uids.length > 1)) { if (Util.hasProLicense(this) == null) { Util.viewUri(this, ActivityMain.cProUri); finish(); return; } } // Registration check if (action.equals(ACTION_SUBMIT) && !registerDevice(this)) { finish(); return; } // Check whether we need a user interface if (extras != null && extras.containsKey(cInteractive) && extras.getBoolean(cInteractive, false)) mInteractive = true; // Set layout setContentView(R.layout.sharelist); setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar)); // Reference controls final TextView tvDescription = (TextView) findViewById(R.id.tvDescription); final ScrollView svToggle = (ScrollView) findViewById(R.id.svToggle); final RadioGroup rgToggle = (RadioGroup) findViewById(R.id.rgToggle); final Spinner spRestriction = (Spinner) findViewById(R.id.spRestriction); RadioButton rbClear = (RadioButton) findViewById(R.id.rbClear); RadioButton rbTemplateFull = (RadioButton) findViewById(R.id.rbTemplateFull); RadioButton rbODEnable = (RadioButton) findViewById(R.id.rbEnableOndemand); RadioButton rbODDisable = (RadioButton) findViewById(R.id.rbDisableOndemand); final Spinner spTemplate = (Spinner) findViewById(R.id.spTemplate); final CheckBox cbClear = (CheckBox) findViewById(R.id.cbClear); final Button btnOk = (Button) findViewById(R.id.btnOk); final Button btnCancel = (Button) findViewById(R.id.btnCancel); // Set title if (action.equals(ACTION_TOGGLE)) { mActionId = R.string.menu_toggle; getSupportActionBar().setSubtitle(R.string.menu_toggle); } else if (action.equals(ACTION_IMPORT)) { mActionId = R.string.menu_import; getSupportActionBar().setSubtitle(R.string.menu_import); } else if (action.equals(ACTION_EXPORT)) { mActionId = R.string.menu_export; getSupportActionBar().setSubtitle(R.string.menu_export); } else if (action.equals(ACTION_FETCH)) { mActionId = R.string.menu_fetch; getSupportActionBar().setSubtitle(R.string.menu_fetch); } else if (action.equals(ACTION_SUBMIT)) { mActionId = R.string.menu_submit; getSupportActionBar().setSubtitle(R.string.menu_submit); } else { finish(); return; } // Get localized restriction name List<String> listRestrictionName = new ArrayList<String>( PrivacyManager.getRestrictions(this).navigableKeySet()); listRestrictionName.add(0, getString(R.string.menu_all)); // Build restriction adapter SpinnerAdapter saRestriction = new SpinnerAdapter(this, android.R.layout.simple_spinner_item); saRestriction.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); saRestriction.addAll(listRestrictionName); // Setup restriction spinner int pos = 0; if (restrictionName != null) for (String restriction : PrivacyManager.getRestrictions(this).values()) { pos++; if (restrictionName.equals(restriction)) break; } spRestriction.setAdapter(saRestriction); spRestriction.setSelection(pos); // Build template adapter SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item); spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); String defaultName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, "0", getString(R.string.title_default)); spAdapter.add(defaultName); for (int i = 1; i <= 4; i++) { String alternateName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, Integer.toString(i), getString(R.string.title_alternate) + " " + i); spAdapter.add(alternateName); } spTemplate.setAdapter(spAdapter); // Build application list AppListTask appListTask = new AppListTask(); appListTask.executeOnExecutor(mExecutor, uids); // Import/export filename if (action.equals(ACTION_EXPORT) || action.equals(ACTION_IMPORT)) { // Check for availability of sharing intent Intent file = new Intent(Intent.ACTION_GET_CONTENT); file.setType("file/*"); boolean hasIntent = Util.isIntentAvailable(ActivityShare.this, file); // Get file name if (mFileName == null) if (action.equals(ACTION_EXPORT)) { String packageName = null; if (uids.length == 1) try { ApplicationInfoEx appInfo = new ApplicationInfoEx(this, uids[0]); packageName = appInfo.getPackageName().get(0); } catch (Throwable ex) { Util.bug(null, ex); } mFileName = getFileName(this, hasIntent, packageName); } else mFileName = (hasIntent ? null : getFileName(this, false, null)); if (mFileName == null) fileChooser(); else showFileName(); if (action.equals(ACTION_IMPORT)) cbClear.setVisibility(View.VISIBLE); } else if (action.equals(ACTION_FETCH)) { tvDescription.setText(getBaseURL()); cbClear.setVisibility(View.VISIBLE); } else if (action.equals(ACTION_TOGGLE)) { tvDescription.setVisibility(View.GONE); spRestriction.setVisibility(View.VISIBLE); svToggle.setVisibility(View.VISIBLE); // Listen for radio button rgToggle.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { btnOk.setEnabled(checkedId >= 0); spRestriction.setVisibility( checkedId == R.id.rbEnableOndemand || checkedId == R.id.rbDisableOndemand ? View.GONE : View.VISIBLE); spTemplate.setVisibility(checkedId == R.id.rbTemplateCategory || checkedId == R.id.rbTemplateFull || checkedId == R.id.rbTemplateMergeSet || checkedId == R.id.rbTemplateMergeReset ? View.VISIBLE : View.GONE); } }); boolean ondemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingOnDemand, true); rbODEnable.setVisibility(ondemand ? View.VISIBLE : View.GONE); rbODDisable.setVisibility(ondemand ? View.VISIBLE : View.GONE); if (choice == CHOICE_CLEAR) rbClear.setChecked(true); else if (choice == CHOICE_TEMPLATE) rbTemplateFull.setChecked(true); } else tvDescription.setText(getBaseURL()); if (mInteractive) { // Enable ok // (showFileName does this for export/import) if (action.equals(ACTION_SUBMIT) || action.equals(ACTION_FETCH)) btnOk.setEnabled(true); // Listen for ok btnOk.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { btnOk.setEnabled(false); // Toggle if (action.equals(ACTION_TOGGLE)) { mRunning = true; for (int i = 0; i < rgToggle.getChildCount(); i++) ((RadioButton) rgToggle.getChildAt(i)).setEnabled(false); int pos = spRestriction.getSelectedItemPosition(); String restrictionName = (pos == 0 ? null : (String) PrivacyManager.getRestrictions(ActivityShare.this).values().toArray()[pos - 1]); new ToggleTask().executeOnExecutor(mExecutor, restrictionName); // Import } else if (action.equals(ACTION_IMPORT)) { mRunning = true; cbClear.setEnabled(false); new ImportTask().executeOnExecutor(mExecutor, new File(mFileName), cbClear.isChecked()); } // Export else if (action.equals(ACTION_EXPORT)) { mRunning = true; new ExportTask().executeOnExecutor(mExecutor, new File(mFileName)); // Fetch } else if (action.equals(ACTION_FETCH)) { if (uids.length > 0) { mRunning = true; cbClear.setEnabled(false); new FetchTask().executeOnExecutor(mExecutor, cbClear.isChecked()); } } // Submit else if (action.equals(ACTION_SUBMIT)) { if (uids.length > 0) { if (uids.length <= cSubmitLimit) { mRunning = true; new SubmitTask().executeOnExecutor(mExecutor); } else { String message = getString(R.string.msg_limit, cSubmitLimit + 1); Toast.makeText(ActivityShare.this, message, Toast.LENGTH_LONG).show(); btnOk.setEnabled(false); } } } } }); } else btnOk.setEnabled(false); // Listen for cancel btnCancel.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { if (mRunning) { mAbort = true; Toast.makeText(ActivityShare.this, getString(R.string.msg_abort), Toast.LENGTH_LONG).show(); } else finish(); } }); }
From source file:org.awesomeapp.messenger.ui.ConversationDetailActivity.java
/** * Create a chooser intent to select the source to get image from.<br/> * The source can be camera's (ACTION_IMAGE_CAPTURE) or gallery's (ACTION_GET_CONTENT).<br/> * All possible sources are added to the intent chooser. *//* w w w. j a v a2s . c o m*/ public Intent getPickImageChooserIntent() { List<Intent> allIntents = new ArrayList<>(); PackageManager packageManager = getPackageManager(); // collect all gallery intents Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT); galleryIntent.setType("image/*"); List<ResolveInfo> listGallery = packageManager.queryIntentActivities(galleryIntent, 0); for (ResolveInfo res : listGallery) { Intent intent = new Intent(galleryIntent); intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name)); intent.setPackage(res.activityInfo.packageName); allIntents.add(intent); } // the main intent is the last in the list (fucking android) so pickup the useless one Intent mainIntent = allIntents.get(allIntents.size() - 1); for (Intent intent : allIntents) { if (intent.getComponent().getClassName().equals("com.android.documentsui.DocumentsActivity")) { mainIntent = intent; break; } } allIntents.remove(mainIntent); // Create a chooser from the main intent Intent chooserIntent = Intent.createChooser(mainIntent, getString(R.string.choose_photos)); // Add all other intents chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[allIntents.size()])); return chooserIntent; }
From source file:com.remobile.camera.CameraLauncher.java
/** * Get image from photo library.// ww w . jav a 2 s. c o m * * @param quality Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality) * @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); intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, 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.treefrogapps.friendlychat.MainActivity.java
private Intent createChooserIntent(String mimeType) { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(mimeType); return intent; }