本文整理汇总了Java中android.content.Intent.ACTION_PICK属性的典型用法代码示例。如果您正苦于以下问题:Java Intent.ACTION_PICK属性的具体用法?Java Intent.ACTION_PICK怎么用?Java Intent.ACTION_PICK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.content.Intent
的用法示例。
在下文中一共展示了Intent.ACTION_PICK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onOptionsItemSelected
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_load_image && read_external_storage_granted) {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
return true;
} else if(!read_external_storage_granted) {
Log.e("MainActivity", "pick image failed");
return true;
}
return super.onOptionsItemSelected(item);
}
示例2: getPickImageIntent
public static Intent getPickImageIntent(Context context) {
Intent chooserIntent = null;
List<Intent> intentList = new ArrayList<>();
Intent pickIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePhotoIntent.putExtra("return-data", true);
takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(context)));
intentList = addIntentsToList(context, intentList, pickIntent);
intentList = addIntentsToList(context, intentList, takePhotoIntent);
if (intentList.size() > 0) {
chooserIntent = Intent.createChooser(intentList.remove(intentList.size() - 1),
context.getString(R.string.pick_image));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray(new Parcelable[]{}));
}
return chooserIntent;
}
示例3: selectPicture
/***
* 选择一张图片
* 图片类型,这里是image/*,当然也可以设置限制
* 如:image/jpeg等
*
* @param activity Activity
*/
@SuppressLint("InlinedApi")
public void selectPicture(Activity activity) {
try {
//每次选择图片吧之前的图片删除
clearCropFile(buildUri(activity));
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
if (!isIntentAvailable(activity, intent)) {
return;
}
activity.startActivityForResult(intent, INTENT_SELECT);
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: toGallery
/**
* 跳转相册
*/
private void toGallery() {
photoDialog.dismiss();
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*");
startActivityForResult(intent, GALLERY_REQUEST);
}
示例5: onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mProgressDialog = new ProgressDialog(PickImageActivity.this);
mProgressDialog.setMessage(getString(R.string.lc_please_wait));
mProgressDialog.setIndeterminate(true);
mProgressDialog.setCancelable(false);
Intent startIntent = getIntent();
if (savedInstanceState == null && startIntent != null) {
mCropImage = startIntent.getBooleanExtra(EXTRA_CROP, false);
mScale = startIntent.getBooleanExtra(EXTRA_SCALE, false);
mScaleUp = startIntent.getBooleanExtra(EXTRA_SCALE_UP, false);
if (startIntent.hasExtra(EXTRA_ASPECT_X) || startIntent.hasExtra(EXTRA_ASPECT_Y)) {
mAspectSize = new Point(startIntent.getIntExtra(EXTRA_ASPECT_X, 0),
startIntent.getIntExtra(EXTRA_ASPECT_Y, 0));
}
if (startIntent.hasExtra(EXTRA_OUTPUT_X) || startIntent.hasExtra(EXTRA_OUTPUT_Y)) {
mOutputSize = new Point(startIntent.getIntExtra(EXTRA_OUTPUT_X, 0),
startIntent.getIntExtra(EXTRA_OUTPUT_Y, 0));
}
if (startIntent.hasExtra(EXTRA_SPOTLIGHT_X) || startIntent.hasExtra(EXTRA_SPOTLIGHT_Y)) {
mSpotlightSize = new Point(startIntent.getIntExtra(EXTRA_SPOTLIGHT_X, 0),
startIntent.getIntExtra(EXTRA_SPOTLIGHT_Y, 0));
}
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, getString(R.string.imgpick_dialog_title)),
REQ_PICK_IMAGE);
} else {
finish();
}
}
示例6: onClick
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.setClassName(ShareActivity.this, BookmarkPickerActivity.class.getName());
startActivityForResult(intent, PICK_BOOKMARK);
}
示例7: demoStaticImage
@DebugLog
protected void demoStaticImage() {
if (mTestImgPath != null) {
Log.d(TAG, "demoStaticImage() launch a task to det");
runDetectAsync(mTestImgPath);
} else {
Log.d(TAG, "demoStaticImage() mTestImgPath is null, go to gallery");
Toast.makeText(MainActivity.this, "Pick an image to run algorithms", Toast.LENGTH_SHORT).show();
// Create intent to Open Image applications like Gallery, Google Photos
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
}
示例8: openGallery
private void openGallery() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
Toast.makeText(this, R.string.readStorageRequired, Toast.LENGTH_LONG).show();
}
else {
ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.READ_EXTERNAL_STORAGE }, REQUEST_READ);
}
return;
}
Intent gallery = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
gallery.setType("image/*");
startActivityForResult(gallery, REQUEST_PICK_IMAGE);
}
示例9: onClick
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
intent.setClassName(ShareActivity.this, AppPickerActivity.class.getName());
startActivityForResult(intent, PICK_APP);
}
示例10: changeAvatar
private void changeAvatar() {
List<Intent> otherImageCaptureIntent = new ArrayList<>();
List<ResolveInfo> otherImageCaptureActivities =
getPackageManager().queryIntentActivities(new Intent(MediaStore.ACTION_IMAGE_CAPTURE),
0); // finding all intents in apps which can handle capture image
// loop through all these intents and for each of these activities we need to store an intent
for (ResolveInfo info : otherImageCaptureActivities) { // Resolve info represents an activity on the system that does our work
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.setClassName(info.activityInfo.packageName,
info.activityInfo.name); // declaring explicitly the class where we will go
// where the picture activity dump the image
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempOutputFile));
otherImageCaptureIntent.add(captureIntent);
}
// above code is only for taking picture and letting it go through another app for cropping before setting to imageview
// now below is for choosing the image from device
Intent selectImageIntent = new Intent(Intent.ACTION_PICK);
selectImageIntent.setType("image/*");
Intent chooser = Intent.createChooser(selectImageIntent, "Choose Avatar");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, otherImageCaptureIntent.toArray(
new Parcelable[otherImageCaptureActivities.size()])); // add 2nd para as intent of parcelables.
startActivityForResult(chooser, REQUEST_SELECT_IMAGE);
}
示例11: startGallery
/**
* Función que lanza el selector de imágenes de la galería, debe haberse dado el permiso
* READ_EXTERNAL_STORAGE antes para abrir.
*/
public void startGallery() {
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(
Intent.createChooser(intent, getString(R.string.fragment_editar_datos_selecciona_una_imagen)),
SELECT_FROM_GALLERY);
}
示例12: startGallery
/**
* Función que lanza el selector de imágenes de la galería, debe haberse dado el permiso
* READ_EXTERNAL_STORAGE antes para abrir.
*/
public void startGallery() {
Intent intent = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(
Intent.createChooser(intent, "Selecciona una imagen"),
SELECT_FROM_GALLERY);
}
示例13: openGallery
public void openGallery() {
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
getIntent.setType("image/*");
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
pickIntent.setType("image/*");
Intent chooserIntent = Intent.createChooser(getIntent, "Select An Image");
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{pickIntent});
startActivityForResult(chooserIntent, SELECT_PICTURE);
}
示例14: btn_Palette
@OnClick(R.id.palette)
public void btn_Palette(View v) {
Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, RESULT_LOAD_IMAGE);
}
示例15: selectContactInfo
public static void selectContactInfo(Activity activity, int requestCode) {
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
activity.startActivityForResult(intent, requestCode);
}