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:au.org.ala.fielddata.mobile.CollectSurveyData.java

/**
 * Launches the default gallery application to allow the user to select an
 * image to be attached to the supplied attribute.
 * // w ww . j  a v  a 2  s.  c om
 * @param attribute
 *            the attribute the image is being selected for.
 */
public void selectFromGallery(Attribute attribute) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    // Just saving the attribute we are working with.
    surveyViewModel.setTempValue(attribute, "");
    startActivityForResult(Intent.createChooser(intent, "Select Photo"),
            CollectSurveyData.SELECT_FROM_GALLERY_REQUEST);
}

From source file:itcr.gitsnes.MainActivity.java

public void uploadfile(View view) {
    flag = true;//  w  w w.  j  a va  2 s  .  c om
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    startActivityForResult(intent, RESULT_LOAD_IMAGE);
}

From source file:org.awesomeapp.messenger.ui.ConversationDetailActivity.java

void startFilePicker() {

    int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);

    if (permissionCheck == PackageManager.PERMISSION_DENIED) {
        // Should we show an explanation?
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {

            // Show an expanation to the user *asynchronously* -- don't block
            // this thread waiting for the user's response! After the user
            // sees the explanation, try again to request the permission.
            Snackbar.make(mConvoView.getHistoryView(), R.string.grant_perms, Snackbar.LENGTH_LONG).show();
        } else {// www  .j  ava2 s . c  o m

            // No explanation needed, we can request the permission.

            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
                    MY_PERMISSIONS_REQUEST_FILE);

            // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
            // app-defined int constant. The callback method gets the
            // result of the request.
        }
    } else {

        Intent selectFile = new Intent(Intent.ACTION_GET_CONTENT);
        Intent intentChooser = Intent.createChooser(selectFile, "Select File");

        if (intentChooser != null)
            startActivityForResult(Intent.createChooser(selectFile, "Select File"), REQUEST_SEND_FILE);
    }
}

From source file:org.catrobat.paintroid.MainActivity.java

private void importPng() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("image/*");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    startActivityForResult(intent, REQUEST_CODE_IMPORTPNG);
}

From source file:com.givon.anhao.activity.AnhaoMainActivity.java

/**
 * ?//  www. ja  v  a  2 s .  c om
 */
public void selectPicFromLocal() {
    Intent intent;
    if (Build.VERSION.SDK_INT < 19) {
        intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");

    } else {
        intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    }
    startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCAL);
}

From source file:org.totschnig.myexpenses.dialog.DialogUtils.java

public static void openBrowse(Uri uri, Fragment fragment) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);//TODO implement preference that allows to use ACTION_OPEN_DOCUMENT
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    intent.setDataAndType(uri, "*/*");

    try {// ww w  .jav  a  2s.  c o  m
        fragment.startActivityForResult(intent, ProtectedFragmentActivity.IMPORT_FILENAME_REQUESTCODE);
    } catch (ActivityNotFoundException e) {
        // No compatible file manager was found.
        Toast.makeText(fragment.getActivity(), R.string.no_filemanager_installed, Toast.LENGTH_SHORT).show();
    } catch (SecurityException ex) {
        Toast.makeText(fragment.getActivity(),
                String.format(
                        "Sorry, this destination does not accept %s request. Please select a different one.",
                        intent.getAction()),
                Toast.LENGTH_SHORT).show();
    }
}

From source file:com.andrew.apollo.ui.activities.ProfileActivity.java

/**
 * Starts an activity for result that returns an image from the Gallery.
 *///w  w  w . j  ava 2  s . c o m
public void selectNewPhoto() {
    // First remove the old image
    removeFromCache();
    // Now open the gallery
    final Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
    intent.setType("image/*");
    startActivityForResult(intent, NEW_PHOTO);
    // Make sure the notfication starts
    if (MusicUtils.isPlaying()) {
        MusicUtils.startBackgroundService(this);
    }
}

From source file:com.givon.anhao.activity.AnhaoMainActivity.java

private void loadPhotos() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("image/*");
    //      intent.putExtra("crop", "true");
    //      intent.putExtra("aspectX", 1);
    //      intent.putExtra("aspectY", 1);
    //      intent.putExtra("outputX", 80);
    //      intent.putExtra("outputY", 80);
    intent.putExtra("return-data", true);
    startActivityForResult(intent, ChatActivity.REQUEST_CODE_SELECT_FILE);
}

From source file:com.mocap.MocapFragment.java

public void SaveOBJ(Context context, MyGLSurfaceView glview) {
    Log.i(TAG, "DIR: ");
    float sVertices[] = glview.getsVertices();
    FileOutputStream fOut = null;
    OutputStreamWriter osw = null;

    File mFile;//  w ww . j  ava2s.  com

    if (Environment.DIRECTORY_PICTURES != null) {
        try {
            mFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                    "mocap.obj");

            Log.i(TAG, "Long Vertices: " + sVertices.length);
            fOut = new FileOutputStream(mFile);
            osw = new OutputStreamWriter(fOut);
            osw.write("# *.obj file (Generate by Mocap 3D)\n");
            osw.flush();

            for (int i = 0; i < sVertices.length - 4; i = i + 3) {

                try {
                    String data = "v " + Float.toString(sVertices[i]) + " " + Float.toString(sVertices[i + 1])
                            + " " + Float.toString(sVertices[i + 2]) + "\n";
                    Log.i(TAG, i + ": " + data);
                    osw.write(data);
                    osw.flush();

                } catch (Exception e) {
                    Toast.makeText(context, "erreur d'criture: " + e, Toast.LENGTH_SHORT).show();
                    Log.i(TAG, "Erreur: " + e);
                }

            }

            osw.write("# lignes:\n");
            osw.write("l ");
            osw.flush();
            ;
            for (int i = 1; i < (-1 + sVertices.length / 3); i++) {
                osw.write(i + " ");
                osw.flush();
            }
            //popup surgissant pour le rsultat
            Toast.makeText(getActivity(), "Save : " + Environment.DIRECTORY_PICTURES + "/mocap.obj ",
                    Toast.LENGTH_SHORT).show();

            //lancement d'un explorateur de fichiers vers le fichier crer
            //systeme des intend
            try {
                File root = new File(Environment.DIRECTORY_PICTURES);
                Uri uri = Uri.fromFile(mFile);

                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_GET_CONTENT);
                intent.setData(uri);

                // Verify that the intent will resolve to an activity
                if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
                    Log.i(TAG, "intent pk: ");
                    getActivity().startActivityForResult(intent, 1);
                }
            } catch (Exception e) {
                Log.i(TAG, "Erreur intent: " + e);
            }
        } catch (Exception e) {
            Toast.makeText(context, "Settings not saved", Toast.LENGTH_SHORT).show();
        } finally {
            try {
                osw.close();
                fOut.close();
            } catch (IOException e) {
                Toast.makeText(context, "Settings not saved", Toast.LENGTH_SHORT).show();
            }

        }

    } else {
        Toast.makeText(context, "Pas de carte ext", Toast.LENGTH_SHORT).show();
    }
}

From source file:org.fs.galleon.presenters.ToolsFragmentPresenter.java

private void dispatchSelectGalleryIntent() {
    if (view.isAvailable()) {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType(IMAGE_TYPE);//from  ww w . j a  v  a2 s . c om
        if (APICompats.isApiAvailable(Build.VERSION_CODES.JELLY_BEAN_MR2)) {
            intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
        }
        view.startActivityForResult(
                Intent.createChooser(intent, view.getContext().getString(R.string.app_name)),
                REQUEST_PICK_GALLERY);
    }
}