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.igniva.filemanager.activities.MainActivity.java

@Override
public void onNewIntent(Intent i) {
    intent = i;//from   w w w  .j  a  va 2 s.  co  m
    path = i.getStringExtra("path");
    if (path != null) {
        if (new File(path).isDirectory()) {
            Fragment f = getDFragment();
            if ((f.getClass().getName().contains("TabFragment"))) {
                Main m = ((Main) getFragment().getTab());
                m.loadlist(path, false, 0);
            } else
                goToMain(path);
        } else
            utils.openFile(new File(path), mainActivity);
    } else if (i.getStringArrayListExtra("failedOps") != null) {
        ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra("failedOps");
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, i.getBooleanExtra("move", false), this);
        }
    } else if ((openprocesses = i.getBooleanExtra("openprocesses", false))) {

        android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewer());
        //   transaction.addToBackStack(null);
        select = 102;
        openprocesses = false;
        //title.setText(utils.getString(con, R.string.process_viewer));
        //Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null)
        if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {

            // file picker intent
            mReturnIntent = true;
            Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
            // ringtone picker intent
            mReturnIntent = true;
            mRingtonePickerIntent = true;
            Toast.makeText(this, utils.getString(con, R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
            // zip viewer intent
            Uri uri = intent.getData();
            zippath = uri.toString();
            openZip(zippath);
        }
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

@Override
public void onNewIntent(Intent i) {
    intent = i;//  w  w  w.java 2 s  .  c  o m
    path = i.getStringExtra("path");

    if (path != null) {
        if (new File(path).isDirectory()) {
            Fragment f = getDFragment();
            if ((f.getClass().getName().contains("TabFragment"))) {
                MainFragment m = ((MainFragment) getFragment().getTab());
                m.loadlist(path, false, OpenMode.FILE);
            } else
                goToMain(path);
        } else
            utils.openFile(new File(path), mainActivity);
    } else if (i.getStringArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS) != null) {
        ArrayList<BaseFile> failedOps = i.getParcelableArrayListExtra(TAG_INTENT_FILTER_FAILED_OPS);
        if (failedOps != null) {
            mainActivityHelper.showFailedOperationDialog(failedOps, i.getBooleanExtra("move", false), this);
        }
    } else if (i.getCategories() != null && i.getCategories().contains(CLOUD_AUTHENTICATOR_GDRIVE)) {

        // we used an external authenticator instead of APIs. Probably for Google Drive
        CloudRail.setAuthenticationResponse(intent);

    } else if ((openProcesses = i.getBooleanExtra(KEY_INTENT_PROCESS_VIEWER, false))) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.content_frame, new ProcessViewer(), KEY_INTENT_PROCESS_VIEWER);
        //   transaction.addToBackStack(null);
        selectedStorage = SELECT_102;
        openProcesses = false;
        //title.setText(utils.getString(con, R.string.process_viewer));
        //Commit the transaction
        transaction.commitAllowingStateLoss();
        supportInvalidateOptionsMenu();
    } else if (intent.getAction() != null) {
        if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {
            // file picker intent
            mReturnIntent = true;
            Toast.makeText(this, getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(RingtoneManager.ACTION_RINGTONE_PICKER)) {
            // ringtone picker intent
            mReturnIntent = true;
            mRingtonePickerIntent = true;
            Toast.makeText(this, getString(R.string.pick_a_file), Toast.LENGTH_LONG).show();
        } else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
            // zip viewer intent
            Uri uri = intent.getData();
            zippath = uri.toString();
            openZip(zippath);
        }

        if (SDK_INT >= Build.VERSION_CODES.KITKAT) {
            if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
                if (sharedPref.getString(KEY_PREF_OTG, null) == null) {
                    sharedPref.edit().putString(KEY_PREF_OTG, VALUE_PREF_OTG_NULL).apply();
                    refreshDrawer();
                }
            } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
                sharedPref.edit().putString(KEY_PREF_OTG, null).apply();
                refreshDrawer();
            }
        }
    }
}

From source file:org.telegram.ui.ChatActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();
    switch (itemId) {
    case android.R.id.home:
        finishFragment();/*from  w  w w. j  a  v a 2s  .  com*/
        break;
    case R.id.attach_photo: {
        try {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File image = Utilities.generatePicturePath();
            if (image != null) {
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(image));
                currentPicturePath = image.getAbsolutePath();
            }
            startActivityForResult(takePictureIntent, 0);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        break;
    }
    case R.id.attach_gallery: {
        try {
            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
            photoPickerIntent.setType("image/*");
            startActivityForResult(photoPickerIntent, 1);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        break;
    }
    case R.id.attach_video: {
        try {
            Intent pickIntent = new Intent();
            pickIntent.setType("video/*");
            pickIntent.setAction(Intent.ACTION_GET_CONTENT);
            pickIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
            Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
            File video = Utilities.generateVideoPath();
            if (video != null) {
                if (android.os.Build.VERSION.SDK_INT > 16) {
                    takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(video));
                }
                takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, (long) (1024 * 1024 * 1000));
                currentPicturePath = video.getAbsolutePath();
            }
            Intent chooserIntent = Intent.createChooser(pickIntent, "");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { takeVideoIntent });

            startActivityForResult(chooserIntent, 2);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
        break;
    }
    case R.id.attach_location: {
        if (!isGoogleMapsInstalled()) {
            return true;
        }
        LocationActivity fragment = new LocationActivity();
        ((ApplicationActivity) parentActivity).presentFragment(fragment, "location", false);
        break;
    }
    case R.id.attach_document: {
        DocumentSelectActivity fragment = new DocumentSelectActivity();
        fragment.delegate = this;
        ((ApplicationActivity) parentActivity).presentFragment(fragment, "document", false);
        break;
    }
    }
    return true;
}

From source file:org.mdc.chess.MDChess.java

private void getFen() {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.setType("application/x-chess-fen");
    try {/* w w w  .java 2 s.  c  om*/
        startActivityForResult(i, RESULT_GET_FEN);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

From source file:com.irccloud.android.activity.MainActivity.java

private void insertPhoto() {
    if (buffer == null)
        return;//w  ww .j a  v a  2  s. c  om

    AlertDialog.Builder builder;
    AlertDialog dialog;
    builder = new AlertDialog.Builder(this);
    builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
    String[] items = (Build.VERSION.SDK_INT < 19 || !NetworkConnection.getInstance().uploadsAvailable())
            ? new String[] { "Take a Photo", "Choose Existing", "Start a Pastebin", "Pastebins" }
            : new String[] { "Take a Photo", "Choose Existing Photo", "Choose Existing Document",
                    "Start a Pastebin", "Pastebins" };
    if (NetworkConnection.getInstance().uploadsAvailable()) {
        items = Arrays.copyOf(items, items.length + 1);
        items[items.length - 1] = "File Uploads";
    }

    final String[] dialogItems = items;

    builder.setItems(dialogItems, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent i;
            if (buffer != null) {
                switch (dialogItems[which]) {
                case "Take a Photo":
                    try {
                        File imageDir = new File(Environment.getExternalStorageDirectory(), "IRCCloud");
                        imageDir.mkdirs();
                        new File(imageDir, ".nomedia").createNewFile();
                        imageCaptureURI = Uri
                                .fromFile(File.createTempFile("irccloudcapture", ".jpg", imageDir));
                        i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageCaptureURI);
                        startActivityForResult(i, REQUEST_CAMERA);
                    } catch (IOException e) {
                    }
                    break;
                case "Choose Existing":
                case "Choose Existing Photo":
                    i = new Intent(Intent.ACTION_GET_CONTENT,
                            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                    i.addCategory(Intent.CATEGORY_OPENABLE);
                    i.setType("image/*");
                    startActivityForResult(Intent.createChooser(i, "Select Picture"), REQUEST_PHOTO);
                    break;
                case "Choose Existing Document":
                    i = new Intent(Intent.ACTION_GET_CONTENT);
                    i.addCategory(Intent.CATEGORY_OPENABLE);
                    i.setType("*/*");
                    startActivityForResult(Intent.createChooser(i, "Select A Document"), REQUEST_DOCUMENT);
                    break;
                case "Start a Pastebin":
                    show_pastebin_prompt();
                    break;
                case "Pastebins":
                    i = new Intent(MainActivity.this, PastebinsActivity.class);
                    startActivity(i);
                    break;
                case "File Uploads":
                    i = new Intent(MainActivity.this, UploadsActivity.class);
                    i.putExtra("cid", buffer.cid);
                    i.putExtra("to", buffer.name);
                    i.putExtra("msg", messageTxt.getText().toString());
                    startActivityForResult(i, REQUEST_UPLOADS);
                    break;
                }
            }
            dialog.dismiss();
        }
    });
    dialog = builder.create();
    dialog.setOwnerActivity(MainActivity.this);
    dialog.show();
}

From source file:edu.cmu.cylab.starslinger.view.HomeActivity.java

private void showFileAttach() {
    final List<Intent> allIntents = new ArrayList<Intent>();

    // all openable...
    Intent contentIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentIntent.setType(SafeSlingerConfig.MIMETYPE_ADD_ATTACH);
    contentIntent.addCategory(Intent.CATEGORY_OPENABLE);

    // camera//ww  w.j  a va 2 s.c om
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    SafeSlinger.setTempCameraFileUri(SSUtil.makeCameraOutputUri());
    cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, SafeSlinger.getTempCameraFileUri());
    allIntents.add(cameraIntent);

    // audio recorder
    Intent recorderIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
    recorderIntent.putExtra(MediaStore.EXTRA_OUTPUT, SSUtil.makeRecorderOutputUri());
    allIntents.add(recorderIntent);

    // our custom browser
    if (SSUtil.isExternalStorageReadable()) {
        Intent filePickIntent = new Intent(HomeActivity.this, FilePickerActivity.class);
        LabeledIntent fileIntent = new LabeledIntent(filePickIntent, filePickIntent.getPackage(),
                R.string.menu_FileManager, R.drawable.ic_menu_directory);
        allIntents.add(fileIntent);
    }

    // Chooser of file system options.
    Intent chooserIntent = Intent.createChooser(contentIntent, getString(R.string.title_ChooseFileLoad));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, allIntents.toArray(new Parcelable[] {}));
    startActivityForResult(chooserIntent, VIEW_FILEATTACH_ID);
}

From source file:com.android.mail.compose.ComposeActivity.java

@SuppressLint("NewApi")
private void doAttach(String type) {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    i.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
    i.setType(type);// ww w . ja v  a 2s  .c  o m
    mAddingAttachment = true;
    startActivityForResult(Intent.createChooser(i, getText(R.string.select_attachment_type)),
            RESULT_PICK_ATTACHMENT);
}

From source file:im.vector.fragments.VectorSettingsPreferencesFragment.java

/**
 * Manage the e2e keys import./*from ww w.j av  a2 s .c o m*/
 */
@SuppressLint("NewApi")
private void importKeys() {
    Intent fileIntent = new Intent(Intent.ACTION_GET_CONTENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        fileIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false);
    }
    fileIntent.setType("*/*");
    startActivityForResult(fileIntent, REQUEST_E2E_FILE_REQUEST_CODE);
}

From source file:edu.mit.viral.shen.DroidFish.java

public final static boolean hasFenProvider(PackageManager manager) {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.setType("application/x-chess-fen");
    List<ResolveInfo> resolvers = manager.queryIntentActivities(i, 0);
    return (resolvers != null) && (resolvers.size() > 0);
}

From source file:edu.mit.viral.shen.DroidFish.java

private final void getFen() {
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.setType("application/x-chess-fen");
    try {/*from  w ww.  j  a v  a 2  s  . com*/
        startActivityForResult(i, RESULT_GET_FEN);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
}