Java Code Examples for android.content.Intent.ACTION_PICK

The following are Jave code examples for showing how to use ACTION_PICK of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MOAAP   File: MainActivity.java   View Source Code Vote up 7 votes
@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);
}
 
Example 2
Project: bcg   File: ImagePicker.java   View Source Code Vote up 7 votes
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;
}
 
Example 3
Project: rongyunDemo   File: PhotoUtils.java   View Source Code Vote up 7 votes
/***
 * 选择一张图片
 * 图片类型,这里是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();
    }
}
 
Example 4
Project: ChenYan   File: PublishAActivity.java   View Source Code Vote up 6 votes
/**
 * 跳转相册
 */
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);
}
 
Example 5
Project: GravityBox   File: PickImageActivity.java   View Source Code Vote up 6 votes
@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();
    }
}
 
Example 6
Project: weex-3d-map   File: ShareActivity.java   View Source Code Vote up 6 votes
@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);
}
 
Example 7
Project: face-landmark-android   File: MainActivity.java   View Source Code Vote up 6 votes
@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);
    }
}
 
Example 8
Project: Clases-2017c1   File: SelectPictureActivity.java   View Source Code Vote up 6 votes
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);
}
 
Example 9
Project: ZXingAndroidExt   File: ShareActivity.java   View Source Code Vote up 6 votes
@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);
}
 
Example 10
Project: FinalProject   File: MessageActivity.java   View Source Code Vote up 6 votes
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);
}
 
Example 11
Project: ZXingAndroidExt   File: ShareActivity.java   View Source Code Vote up 6 votes
@Override
public void onClick(View v) {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    intent.setClassName(ShareActivity.this, BookmarkPickerActivity.class.getName());
    startActivityForResult(intent, PICK_BOOKMARK);
}
 
Example 12
Project: ChenYan   File: MyInfoActivity.java   View Source Code Vote up 6 votes
/**
 * 跳转相册
 */
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);
}
 
Example 13
Project: Guanajoven   File: EditarDatosFragment.java   View Source Code Vote up 6 votes
/**
 * 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);
}
 
Example 14
Project: Guanajoven   File: RegistrarFragment.java   View Source Code Vote up 6 votes
/**
 * 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);
}
 
Example 15
Project: Custom-Vison-Service   File: MainActivity.java   View Source Code Vote up 6 votes
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);
}
 
Example 16
Project: MagicLight-Controller   File: MainActivity.java   View Source Code Vote up 5 votes
@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);
}
 
Example 17
Project: PeSanKita-android   File: AttachmentManager.java   View Source Code Vote up 5 votes
public static void selectContactInfo(Activity activity, int requestCode) {
  Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
  activity.startActivityForResult(intent, requestCode);
}
 
Example 18
Project: smart-device-cloud   File: MainActivity.java   View Source Code Vote up 5 votes
private void smart_select_image() {
    Intent pickPhotoIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(pickPhotoIntent, PICK_IMAGE_REQUEST);
}
 
Example 19
Project: face-landmark-android   File: BuildMaskActivity.java   View Source Code Vote up 5 votes
@Click({R.id.btn_load_face})
protected void launchGallery() {
    Toast.makeText(BuildMaskActivity.this, "选择一张人脸图片", Toast.LENGTH_SHORT).show();
    Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
}
 
Example 20
Project: izzati   File: MainActivity.java   View Source Code Vote up 5 votes
public void chooseFile(View view) {
    Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, PICK_IMAGE_REQUEST);
}