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:org.adaway.helper.ImportExportHelper.java

/**
 * Opens file manager to open file and return it in onActivityResult in Activity
 *
 * @param activity/*from  ww  w  . j  av a2  s  .  c o  m*/
 */
public static void openFileStream(final FragmentActivity activity) {
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("text/plain");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {
        activity.startActivityForResult(intent, REQUEST_CODE_IMPORT);
    } catch (ActivityNotFoundException e) {
        ActivityNotFoundDialogFragment notFoundDialog = ActivityNotFoundDialogFragment.newInstance(
                R.string.no_file_manager_title, R.string.no_file_manager,
                "market://details?id=org.openintents.filemanager", "OI File Manager");

        notFoundDialog.show(activity.getSupportFragmentManager(), "notFoundDialog");
    }
}

From source file:org.chromium.ChromeFileSystem.java

/**
 * Choose a file from the file system./*from   w w w .jav a  2  s  . co m*/
 * @throws JSONException
 */
public void chooseFile(JSONArray mimeTypes) throws JSONException {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    // Intent.setType doesn't support handling multiple mime types, so we need to settle on one.
    intent.setType(getIntentType(mimeTypes));

    if (this.cordova != null) {
        this.cordova.startActivityForResult((CordovaPlugin) this, Intent.createChooser(intent, "Get File"), 0);
    }
}

From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java

public static void showPictureLauncher(final Activity activity, final ClearImageCallback clearImageOption) {
    ArrayList<String> options = new ArrayList<String>();

    final Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    PackageManager pm = activity.getPackageManager();

    final boolean cameraAvailable = pm.queryIntentActivities(cameraIntent, 0).size() > 0;
    if (cameraAvailable)
        options.add(activity.getString(R.string.actfm_picture_camera));
    options.add(activity.getString(R.string.actfm_picture_gallery));

    if (clearImageOption != null)
        options.add(activity.getString(R.string.actfm_picture_clear));

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(activity,
            android.R.layout.simple_spinner_dropdown_item, options.toArray(new String[options.size()]));

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @SuppressWarnings("nls")
        @Override/*from ww  w.  j  a  va 2 s.  c  o m*/
        public void onClick(DialogInterface d, int which) {
            if (which == 0 && cameraAvailable) {
                lastTempFile = getTempFile(activity);
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                if (lastTempFile != null) {
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(lastTempFile));
                }
                activity.startActivityForResult(intent, REQUEST_CODE_CAMERA);
            } else if ((which == 1 && cameraAvailable) || (which == 0 && !cameraAvailable)) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("image/*");
                activity.startActivityForResult(
                        Intent.createChooser(intent, activity.getString(R.string.actfm_TVA_tag_picture)),
                        REQUEST_CODE_PICTURE);
            } else {
                if (clearImageOption != null)
                    clearImageOption.clearImage();
            }
        }
    };

    // show a menu of available options
    new AlertDialog.Builder(activity).setAdapter(adapter, listener).show().setOwnerActivity(activity);
}

From source file:io.hypertrack.sendeta.util.images.EasyImage.java

private static Intent createDocumentsIntent() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    return intent;
}

From source file:Main.java

public static Intent getIntentForAction(int action) {
    Log.d(TAG, "[AirImagePickerUtils] Entering getIntentForAction");
    Intent intent;//from w  w  w.j  av a 2s. com
    switch (action) {
    case GALLERY_IMAGES_ONLY_ACTION:
        intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        Log.d(TAG, "[AirImagePickerUtils] Exiting getIntentForAction");
        return intent;

    case GALLERY_VIDEOS_ONLY_ACTION:
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("video/*");
        Log.d(TAG, "[AirImagePickerUtils] Exiting getIntentForAction");
        return intent;

    case CAMERA_IMAGE_ACTION:
        Log.d(TAG, "[AirImagePickerUtils] Exiting getIntentForAction");
        return new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    case CAMERA_VIDEO_ACTION:
        Log.d(TAG, "[AirImagePickerUtils] Exiting getIntentForAction");
        return new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

    case CROP_ACTION:
        Log.d(TAG, "[AirImagePickerUtils] Exiting getIntentForAction");
        return new Intent("com.android.camera.action.CROP");

    default:
        Log.d(TAG, "[AirImagePickerUtils] Exiting getIntentForAction");
        return null;
    }
}

From source file:com.truemind.selidpic_v20.ui.GalleryActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gallery);

    initView();// w w w.j  a v a  2s.c o m
    initFooter();
    initFloating();
    floatingListener(getContext());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        checkPermission();
    } else {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE);
    }

}

From source file:id.nci.stm_9.FileHelper.java

private static Intent buildFileIntent(String filename, String mimeType) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    intent.setData(Uri.parse("file://" + filename));
    intent.setType(mimeType);//  ww  w . j a v a2  s  . co  m

    return intent;
}

From source file:com.commonsware.android.print.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.bitmap:
        Intent i = new Intent(Intent.ACTION_GET_CONTENT).setType("image/*");

        startActivityForResult(i, IMAGE_REQUEST_ID);

        return (true);

    case R.id.web:
        printWebPage();/*  ww  w .ja v  a 2  s . co  m*/

        return (true);

    case R.id.report:
        printReport();

        return (true);

    case R.id.pdf:
        print("Test PDF", new PdfDocumentAdapter(getApplicationContext()),
                new PrintAttributes.Builder().build());

        return (true);
    }

    return (super.onOptionsItemSelected(item));
}

From source file:com.steinwurf.petro.MainActivity.java

protected void openFileSelector(Class<?> nextActivity) {
    mTargetActivity = nextActivity;//from w  w  w .ja  va 2s.c  o m
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("video/*");
    startActivityForResult(intent, ACTIVITY_CHOOSE_FILE);
}

From source file:com.manning.androidhacks.hack035.MainActivity.java

public void onPickPicture(View v) {
    Intent pickIntent = new Intent(Intent.ACTION_GET_CONTENT);
    pickIntent.setType("image/*");
    Intent chooserIntent = Intent.createChooser(pickIntent, getString(R.string.activity_main_take_picture));
    startActivityForResult(chooserIntent, PICK_PICTURE);
}