Example usage for android.content Intent ACTION_GET_CONTENT

List of usage examples for android.content Intent ACTION_GET_CONTENT

Introduction

In this page you can find the example usage for android.content Intent ACTION_GET_CONTENT.

Prototype

String ACTION_GET_CONTENT

To view the source code for android.content Intent ACTION_GET_CONTENT.

Click Source Link

Document

Activity Action: Allow the user to select a particular kind of data and return it.

Usage

From source file:com.yandex.disk.rest.example.ListExampleFragment.java

private void openAddFileDialog() {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    startActivityForResult(//from w  w  w.j a  v a2 s.  c  o  m
            Intent.createChooser(intent, getText(R.string.example_loading_get_file_to_upload_chooser_title)),
            GET_FILE_TO_UPLOAD);
}

From source file:java_lang_programming.com.android_media_demo.ImageSelectionCropDemo.java

/**
 * start ExternalApp if the required READ_EXTERNAL_STORAGE permission has been granted.
 *//*from ww w .ja v a2 s.  co  m*/
private void startExternalAppSelectableImage() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

    // Filter to only show results that can be "opened", such as a
    // file (as opposed to a list of contacts or timezones)
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        intent.putExtra(Intent.EXTRA_MIME_TYPES, types.toArray());
    }
    startActivityForResult(Intent.createChooser(intent, null), ImageSelectionCropDemo.REQUEST_CODE_CHOOSER);
}

From source file:bizapps.com.healthforusPatient.activity.RegisterActivity.java

private void galleryIntent() {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);//
    startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
}

From source file:com.snail.imagechooser.api.MediaChooserManager.java

private void chooseMedia() throws Exception {
    checkDirectory();//from   w  w  w  .jav  a2s.com
    try {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        if (extras != null) {
            intent.putExtras(extras);
        }
        intent.setType("video/*, images/*");
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        throw new Exception("Activity not found");
    }
}

From source file:com.cars.manager.utils.imageChooser.api.ImageChooserManager.java

private void choosePicture() throws Exception {
    checkDirectory();//from w w w.  j  av  a2 s .  c o m
    try {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        throw new Exception("Activity not found");
    }
}

From source file:com.lithidsw.wallbox.app.randomizer.RandomizerFrag.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_add:
        Intent in = new Intent();
        in.setType("image/*");
        in.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(in, "Select Image"), GET_IMAGE_CODE);
        return true;
    case R.id.action_interval:
        if (mGalItems.size() > 1) {
            singleDialog();/*  w  w w .j  a  v a2s.co m*/
        } else {
            mUtils.sendToast("Need at least 2 wallpapers to start!");
        }
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:io.flutter.plugins.imagepicker.ImagePickerPlugin.java

private void pickImageFromGallery(Activity activity) {
    boolean hasPermission = ActivityCompat.checkSelfPermission(activity,
            Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;

    if (hasPermission) {
        Intent pickImageIntent = new Intent(Intent.ACTION_GET_CONTENT);
        pickImageIntent.setType("image/*");

        activity.startActivityForResult(pickImageIntent, REQUEST_CODE_PICK);
    } else {/*from w  w w. ja  v  a  2 s .c om*/
        requestReadExternalStoragePermission();
    }
}

From source file:com.dexin.MainActivity.java

public void startGalleryChooser() {
    if (PermissionUtils.requestPermission(this, GALLERY_PERMISSIONS_REQUEST,
            Manifest.permission.READ_EXTERNAL_STORAGE)) {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select a photo"), GALLERY_IMAGE_REQUEST);
    }//from  w  ww  .  ja  va2s. c o m
}

From source file:com.kbeanie.imagechooser.api.VideoChooserManager.java

private void pickVideo() throws ChooserException {
    checkDirectory();//  ww  w  .ja v  a2  s  . co  m
    try {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        if (extras != null) {
            intent.putExtras(extras);
        }
        intent.setType("video/*");
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        throw new ChooserException(e);
    }
}

From source file:org.odk.collect.android.widgets.ImageWidget.java

public ImageWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);

    mInstanceFolder = Collect.getInstance().getFormController().getInstancePath().getParent();

    TableLayout.LayoutParams params = new TableLayout.LayoutParams();
    params.setMargins(7, 5, 7, 5);/*from   w  ww . j a  v a  2 s  . c  o m*/

    mErrorTextView = new TextView(context);
    mErrorTextView.setId(QuestionWidget.newUniqueId());
    mErrorTextView.setText("Selected file is not a valid image");

    // setup capture button
    mCaptureButton = new Button(getContext());
    mCaptureButton.setId(QuestionWidget.newUniqueId());
    mCaptureButton.setText(getContext().getString(R.string.capture_image));
    mCaptureButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mCaptureButton.setPadding(20, 20, 20, 20);
    mCaptureButton.setEnabled(!prompt.isReadOnly());
    mCaptureButton.setLayoutParams(params);

    // launch capture intent on click
    mCaptureButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "captureButton", "click",
                    mPrompt.getIndex());
            mErrorTextView.setVisibility(View.GONE);
            Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            // We give the camera an absolute filename/path where to put the
            // picture because of bug:
            // http://code.google.com/p/android/issues/detail?id=1480
            // The bug appears to be fixed in Android 2.0+, but as of feb 2,
            // 2010, G1 phones only run 1.6. Without specifying the path the
            // images returned by the camera in 1.6 (and earlier) are ~1/4
            // the size. boo.

            // if this gets modified, the onActivityResult in
            // FormEntyActivity will also need to be updated.
            i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, FileProvider.getUriForFile(getContext(),
                    BuildConfig.APPLICATION_ID + ".provider", new File(Collect.TMPFILE_PATH)));
            try {
                Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex());
                ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CAPTURE);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getContext(),
                        getContext().getString(R.string.activity_not_found, "image capture"),
                        Toast.LENGTH_SHORT).show();
                Collect.getInstance().getFormController().setIndexWaitingForData(null);
            }

        }
    });

    // setup chooser button
    mChooseButton = new Button(getContext());
    mChooseButton.setId(QuestionWidget.newUniqueId());
    mChooseButton.setText(getContext().getString(R.string.choose_image));
    mChooseButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mChooseButton.setPadding(20, 20, 20, 20);
    mChooseButton.setEnabled(!prompt.isReadOnly());
    mChooseButton.setLayoutParams(params);

    // launch capture intent on click
    mChooseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Collect.getInstance().getActivityLogger().logInstanceAction(this, "chooseButton", "click",
                    mPrompt.getIndex());
            mErrorTextView.setVisibility(View.GONE);
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("image/*");

            try {
                Collect.getInstance().getFormController().setIndexWaitingForData(mPrompt.getIndex());
                ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.IMAGE_CHOOSER);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(getContext(),
                        getContext().getString(R.string.activity_not_found, "choose image"), Toast.LENGTH_SHORT)
                        .show();
                Collect.getInstance().getFormController().setIndexWaitingForData(null);
            }

        }
    });

    // finish complex layout
    LinearLayout answerLayout = new LinearLayout(getContext());
    answerLayout.setOrientation(LinearLayout.VERTICAL);
    answerLayout.addView(mCaptureButton);
    answerLayout.addView(mChooseButton);
    answerLayout.addView(mErrorTextView);

    // and hide the capture and choose button if read-only
    if (prompt.isReadOnly()) {
        mCaptureButton.setVisibility(View.GONE);
        mChooseButton.setVisibility(View.GONE);
    }
    mErrorTextView.setVisibility(View.GONE);

    // retrieve answer from data model and update ui
    mBinaryName = prompt.getAnswerText();

    // Only add the imageView if the user has taken a picture
    if (mBinaryName != null) {
        mImageView = new ImageView(getContext());
        mImageView.setId(QuestionWidget.newUniqueId());
        Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE))
                .getDefaultDisplay();
        int screenWidth = display.getWidth();
        int screenHeight = display.getHeight();

        File f = new File(mInstanceFolder + File.separator + mBinaryName);

        if (f.exists()) {
            Bitmap bmp = FileUtils.getBitmapScaledToDisplay(f, screenHeight, screenWidth);
            if (bmp == null) {
                mErrorTextView.setVisibility(View.VISIBLE);
            }
            mImageView.setImageBitmap(bmp);
        } else {
            mImageView.setImageBitmap(null);
        }

        mImageView.setPadding(10, 10, 10, 10);
        mImageView.setAdjustViewBounds(true);
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Collect.getInstance().getActivityLogger().logInstanceAction(this, "viewButton", "click",
                        mPrompt.getIndex());
                Intent i = new Intent("android.intent.action.VIEW");
                Uri uri = MediaUtils
                        .getImageUriFromMediaProvider(mInstanceFolder + File.separator + mBinaryName);
                if (uri != null) {
                    Log.i(t, "setting view path to: " + uri);
                    i.setDataAndType(uri, "image/*");
                    try {
                        getContext().startActivity(i);
                    } catch (ActivityNotFoundException e) {
                        Toast.makeText(getContext(),
                                getContext().getString(R.string.activity_not_found, "view image"),
                                Toast.LENGTH_SHORT).show();
                    }
                }
            }
        });
        answerLayout.addView(mImageView);
    }
    addAnswerView(answerLayout);
}