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.cars.manager.utils.imageChooser.api.VideoChooserManager.java

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

From source file:com.afwsamples.testdpc.common.Util.java

public static void showFileViewerForImportingCertificate(PreferenceFragment fragment, int requestCode) {
    Intent certIntent = new Intent(Intent.ACTION_GET_CONTENT);
    certIntent.setTypeAndNormalize("*/*");
    try {// www  . j  av  a  2 s  .  c  om
        fragment.startActivityForResult(certIntent, requestCode);
    } catch (ActivityNotFoundException e) {
        Log.e(TAG, "showFileViewerForImportingCertificate: ", e);
    }
}

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

public ImageWebViewWidget(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  w w .  j av  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.
            Uri tempPath = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".provider",
                    new File(Collect.TMPFILE_PATH));
            i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, tempPath);
            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) {
        mImageDisplay = new WebView(getContext());
        mImageDisplay.setId(QuestionWidget.newUniqueId());
        mImageDisplay.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
        mImageDisplay.getSettings().setBuiltInZoomControls(true);
        mImageDisplay.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
        mImageDisplay.setVisibility(View.VISIBLE);
        mImageDisplay.setLayoutParams(params);

        // HTML is used to display the image.
        String html = "<body>" + constructImageElement() + "</body>";

        mImageDisplay.loadDataWithBaseURL("file:///" + mInstanceFolder + File.separator, html, "text/html",
                "utf-8", "");
        answerLayout.addView(mImageDisplay);
    }
    addAnswerView(answerLayout);
}

From source file:org.opendatakit.services.preferences.fragments.DeviceSettingsFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    PropertiesSingleton props = ((IOdkAppPropertiesActivity) this.getActivity()).getProps();

    addPreferencesFromResource(R.xml.device_preferences);

    // not super safe, but we're just putting in this mode to help
    // administrate
    // would require code to access it
    boolean adminMode;
    adminMode = (this.getArguments() == null) ? false
            : (this.getArguments().containsKey(IntentConsts.INTENT_KEY_SETTINGS_IN_ADMIN_MODE)
                    ? this.getArguments().getBoolean(IntentConsts.INTENT_KEY_SETTINGS_IN_ADMIN_MODE)
                    : false);//w w w. j  a  v a  2  s  . c om

    String adminPwd = props.getProperty(CommonToolProperties.KEY_ADMIN_PW);
    boolean adminConfigured = (adminPwd != null && adminPwd.length() != 0);

    PreferenceCategory deviceCategory = (PreferenceCategory) findPreference(
            CommonToolProperties.GROUPING_DEVICE_CATEGORY);

    boolean fontAvailable = !adminConfigured
            || props.getBooleanProperty(CommonToolProperties.KEY_CHANGE_FONT_SIZE);
    mFontSizePreference = (ListPreference) findPreference(CommonToolProperties.KEY_FONT_SIZE);
    if (props.containsKey(CommonToolProperties.KEY_FONT_SIZE)) {
        String chosenFontSize = props.getProperty(CommonToolProperties.KEY_FONT_SIZE);
        CharSequence entryValues[] = mFontSizePreference.getEntryValues();
        for (int i = 0; i < entryValues.length; i++) {
            String entry = entryValues[i].toString();
            if (entry.equals(chosenFontSize)) {
                mFontSizePreference.setValue(entry);
                mFontSizePreference.setSummary(mFontSizePreference.getEntries()[i]);
            }
        }
    }

    mFontSizePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            int index = ((ListPreference) preference).findIndexOfValue(newValue.toString());
            String entry = (String) ((ListPreference) preference).getEntries()[index];
            preference.setSummary(entry);

            PropertiesSingleton props = ((IOdkAppPropertiesActivity) DeviceSettingsFragment.this.getActivity())
                    .getProps();
            props.setProperty(CommonToolProperties.KEY_FONT_SIZE, newValue.toString());
            return true;
        }
    });

    mFontSizePreference.setEnabled(fontAvailable || adminMode);

    boolean splashAvailable = !adminConfigured
            || props.getBooleanProperty(CommonToolProperties.KEY_CHANGE_SPLASH_SETTINGS);

    mShowSplashPreference = (CheckBoxPreference) findPreference(CommonToolProperties.KEY_SHOW_SPLASH);
    if (props.containsKey(CommonToolProperties.KEY_SHOW_SPLASH)) {
        boolean checked = props.getBooleanProperty(CommonToolProperties.KEY_SHOW_SPLASH);
        mShowSplashPreference.setChecked(checked);
    }
    mShowSplashPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PropertiesSingleton props = ((IOdkAppPropertiesActivity) DeviceSettingsFragment.this.getActivity())
                    .getProps();
            props.setProperty(CommonToolProperties.KEY_SHOW_SPLASH, newValue.toString());
            return true;
        }
    });

    mShowSplashPreference.setEnabled(adminMode || splashAvailable);

    mSplashPathPreference = (PreferenceScreen) findPreference(CommonToolProperties.KEY_SPLASH_PATH);
    if (props.containsKey(CommonToolProperties.KEY_SPLASH_PATH)) {
        mSplashPathPreference.setSummary(props.getProperty(CommonToolProperties.KEY_SPLASH_PATH));
    }
    mSplashPathPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        private void launchImageChooser() {
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.setType("image/*");
            DeviceSettingsFragment.this.startActivityForResult(i, AppPropertiesActivity.SPLASH_IMAGE_CHOOSER);
        }

        @Override
        public boolean onPreferenceClick(Preference preference) {
            // if you have a value, you can clear it or select new.
            CharSequence cs = mSplashPathPreference.getSummary();
            if (cs != null && cs.toString().contains("/")) {

                final CharSequence[] items = { getString(R.string.select_another_image),
                        getString(R.string.use_odk_default) };

                AlertDialog.Builder builder = new AlertDialog.Builder(
                        DeviceSettingsFragment.this.getActivity());
                builder.setTitle(getString(R.string.change_splash_path));
                builder.setNeutralButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                    }
                });
                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int item) {
                        if (items[item].equals(getString(R.string.select_another_image))) {
                            launchImageChooser();
                        } else {
                            PropertiesSingleton props = ((IOdkAppPropertiesActivity) DeviceSettingsFragment.this
                                    .getActivity()).getProps();

                            String path = getString(R.string.default_splash_path);
                            props.setProperty(CommonToolProperties.KEY_SPLASH_PATH, path);
                            mSplashPathPreference.setSummary(path);
                        }
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();

            } else {
                launchImageChooser();
            }

            return true;
        }
    });

    mSplashPathPreference.setEnabled(adminMode || splashAvailable);

    if (!adminMode && (!fontAvailable || !splashAvailable)) {
        deviceCategory.setTitle(R.string.device_restrictions_apply);
    }
}

From source file:com.amytech.android.library.views.imagechooser.api.VideoChooserManager.java

private void pickVideo() throws Exception {
    checkDirectory();//  w  w  w  . ja v  a  2  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 Exception("Activity not found");
    }
}

From source file:com.dvn.vindecoder.ui.seller.AddDriverActivity.java

private void startDilog() {
    AlertDialog.Builder myAlertDilog = new AlertDialog.Builder(AddDriverActivity.this);
    myAlertDilog.setTitle("Upload picture option..");
    myAlertDilog.setMessage("Take Photo");
    myAlertDilog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
        @Override//from ww  w . ja v  a 2  s .c o  m
        public void onClick(DialogInterface dialog, int which) {
            Intent picIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
            picIntent.setType("image/*");
            picIntent.putExtra("return_data", true);
            startActivityForResult(picIntent, GALLERY_REQUEST);
        }
    });
    myAlertDilog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (checkPermission(Manifest.permission.CAMERA, AddDriverActivity.this)) {
                    openCameraApplication();
                } else {
                    requestPermission(AddDriverActivity.this, new String[] { Manifest.permission.CAMERA },
                            REQUEST_ACESS_CAMERA);
                }
            } else {
                openCameraApplication();
            }
        }
    });
    myAlertDilog.show();
}

From source file:info.guardianproject.gpg.FileDialogFragment.java

/**
 * Opens the preferred installed file manager on Android and shows a toast
 * if no manager is installed./*  w  w w  .  j  ava  2  s . c  o m*/
 * 
 * @param activity
 * @param filename default selected file, not supported by all file managers
 * @param type can be text/plain for example
 * @param requestCode requestCode used to identify the result coming back
 *            from file manager to onActivityResult() in your activity
 */
public static void openFile(Activity activity, String filename, String type, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    intent.setData(Uri.parse("file://" + filename));
    intent.setType(type);

    try {
        activity.startActivityForResult(intent, requestCode);
    } catch (ActivityNotFoundException e) {
        // No compatible file manager was found.
        Toast.makeText(activity, R.string.error_no_file_manager_installed, Toast.LENGTH_SHORT).show();
    }
}

From source file:com.itime.team.itime.fragments.ProfileFragment.java

@Override
public void onClick(View v) {
    int id = v.getId();
    Bundle bundle = new Bundle();
    switch (id) {
    case R.id.setting_profile_picture: {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(intent, REQUEST_IMAGE_SELECT);
        break;// w  w  w .  ja  v  a 2  s  .  c  om
    }
    case R.id.setting_profile_name: {
        final Intent intent = new Intent(getActivity(), InputDialogActivity.class);
        intent.putExtra(InputDialogActivity.INPUT_DIALOG_TITLE, "Edit User Name");
        startActivityForResult(intent, REQUEST_SET_USER_NAME);
        break;
    }

    case R.id.setting_profile_qrcode:
        final QRCodeFragment qrCodeFragment = new QRCodeFragment();
        final Bundle args = new Bundle();
        args.putString(QRCodeFragment.QRCODE_STRING, mUserId);
        qrCodeFragment.setArguments(args);
        qrCodeFragment.show(getActivity().getSupportFragmentManager(), "qrcode_fragment");
        //FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
        //ft.add(qrCodeFragment, "qrcode_fragment");
        //ft.commit();
        break;

    case R.id.setting_profile_email: {
        final Intent intent = new Intent(getActivity(), InputDialogActivity.class);
        intent.putExtra(InputDialogActivity.INPUT_DIALOG_TITLE, "Edit Your Email");
        startActivityForResult(intent, REQUEST_SET_EMAIL);
        break;
    }
    case R.id.setting_profile_phone_number: {
        final Intent intent = new Intent(getActivity(), InputDialogActivity.class);
        intent.putExtra(InputDialogActivity.INPUT_DIALOG_TITLE, "Edit Your Phone Number");
        startActivityForResult(intent, REQUEST_SET_PHONE_NUMBER);
        break;
    }
    }

}

From source file:com.codebutler.farebot.fragment.CardsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ClipboardManager clipboardManager = (ClipboardManager) getActivity()
            .getSystemService(Context.CLIPBOARD_SERVICE);
    try {// w ww .  ja v  a2 s .co  m
        int itemId = item.getItemId();
        switch (itemId) {
        case R.id.import_file:
            Intent target = new Intent(Intent.ACTION_GET_CONTENT);
            target.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(Environment.getExternalStorageDirectory()));
            target.setType("*/*");
            startActivityForResult(Intent.createChooser(target, getString(R.string.select_file)),
                    REQUEST_SELECT_FILE);
            return true;
        case R.id.import_clipboard:
            ClipData clip = clipboardManager.getPrimaryClip();
            if (clip != null && clip.getItemCount() > 0) {
                String text = clip.getItemAt(0).coerceToText(getActivity()).toString();
                onCardsImported(mExportHelper.importCards(text));
            }
            return true;
        case R.id.copy:
            clipboardManager.setPrimaryClip(ClipData.newPlainText(null, mExportHelper.exportCards()));
            Toast.makeText(getActivity(), R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
            return true;
        case R.id.share:
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, mExportHelper.exportCards());
            startActivity(intent);
            return true;
        case R.id.save:
            exportToFile();
            return true;
        }
    } catch (Exception ex) {
        Utils.showError(getActivity(), ex);
    }
    return false;
}