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.hp.mss.printsdksample.fragment.TabFragmentPrintLayout.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View inflatedView = inflater.inflate(R.layout.tab_fragment_print_layout, container, false);
    filePickerLayout = (RelativeLayout) inflatedView.findViewById(R.id.filePickerLayout);

    RadioGroup layoutRadioGroup = (RadioGroup) inflatedView.findViewById(R.id.layoutRadioGroup);
    layoutRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(layoutRadioGroup, layoutRadioGroup.getCheckedRadioButtonId());

    RadioGroup layoutMarginRadioGroup = (RadioGroup) inflatedView.findViewById(R.id.layoutMarginRadioGroup);
    layoutMarginRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(layoutMarginRadioGroup, layoutMarginRadioGroup.getCheckedRadioButtonId());

    SwitchCompat metricsSwitch = (SwitchCompat) inflatedView.findViewById(R.id.metricsRadioGroup);
    metricsSwitch.setOnCheckedChangeListener(this);
    onCheckedChanged(metricsSwitch, metricsSwitch.isChecked());

    RadioGroup contentRadioGroup = (RadioGroup) inflatedView.findViewById(R.id.contentRadioGroup);
    contentRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(contentRadioGroup, contentRadioGroup.getCheckedRadioButtonId());

    RadioGroup deviceIdRadioGroup = (RadioGroup) inflatedView.findViewById(R.id.deviceIdRadioGroup);
    deviceIdRadioGroup.setOnCheckedChangeListener(this);
    onCheckedChanged(deviceIdRadioGroup, deviceIdRadioGroup.getCheckedRadioButtonId());

    tagText = (EditText) inflatedView.findViewById(R.id.tagEditText);
    valueText = (EditText) inflatedView.findViewById(R.id.valueEditText);
    LinearLayout customData = (LinearLayout) inflatedView.findViewById(R.id.customData);
    showCustomData = customData.getVisibility() == View.VISIBLE;

    FloatingActionButton printButton = (FloatingActionButton) inflatedView.findViewById(R.id.printBtn);
    printButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            continueButtonClicked(v);/*from  w  w  w  . java 2  s  .co  m*/
        }
    });

    Button buttonPick = (Button) inflatedView.findViewById(R.id.buttonPick);
    buttonPick.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType(getContentMimeType());
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICKFILE_RESULT_CODE);
        }
    });

    mediaSize5x7 = new PrintAttributes.MediaSize("na_5x7_5x7in", "5 x 7", 5000, 7000);

    return inflatedView;
}

From source file:com.phonegap.CameraLauncher.java

/**
 * Get image from photo library./*from w  w w .j ava  2  s.  co m*/
 * 
 * @param quality         Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
 * @param srcType         The album to get image from.
 * @param returnType      Set the type of image to return. 
 */
// TODO: Images selected from SDCARD don't display correctly, but from CAMERA ALBUM do!
public void getImage(int quality, int srcType, int returnType) {
    this.mQuality = quality;

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    this.ctx.startActivityForResult((Plugin) this, Intent.createChooser(intent, new String("Get Picture")),
            (srcType + 1) * 16 + returnType + 1);
}

From source file:com.redoceanred.unity.android.RORAudioPlayer.java

public void pickAudioForApp() {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.setType("audio/*");
    if (mFragment != null) {
        mFragment.get().startActivityForResult(intent, REQUEST_PICK_AUDIO);
    } else if (mFragmentActivity != null) {
        mFragmentActivity.get().startActivityForResult(intent, REQUEST_PICK_AUDIO);
    } else {/*  w  w w .  j  a  v  a  2s.  com*/
        mActivity.get().startActivityForResult(intent, REQUEST_PICK_AUDIO);
    }
}

From source file:cz.maresmar.sfm.view.user.UserDetailFragment.java

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_user_detail, container, false);

    // Profile image
    mProfileImageButton = view.findViewById(R.id.profileImageButton);
    mProfileImageButton.setOnClickListener(view1 -> {
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, getString(R.string.user_pick_picture_button)),
                PICK_PROFILE_PICTURE);/*from w w w .j  a v a  2  s . c  om*/
    });

    // User name
    mNameText = view.findViewById(R.id.nameText);
    mNameText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (mGenerateBitmap) {
                setDefaultProfilePicture();
            }
        }
    });

    setProfilePicture(mPictureBitmap);

    return view;
}

From source file:com.poinsart.votar.VotarMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    System.loadLibrary("VotAR");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    assetMgr = this.getAssets();

    imageView = (ImageView) findViewById(R.id.imageView);
    bar[0] = (ProgressBar) findViewById(R.id.bar_a);
    bar[1] = (ProgressBar) findViewById(R.id.bar_b);
    bar[2] = (ProgressBar) findViewById(R.id.bar_c);
    bar[3] = (ProgressBar) findViewById(R.id.bar_d);

    barLabel[0] = (TextView) findViewById(R.id.label_a);
    barLabel[1] = (TextView) findViewById(R.id.label_b);
    barLabel[2] = (TextView) findViewById(R.id.label_c);
    barLabel[3] = (TextView) findViewById(R.id.label_d);

    wifiLabel = (TextView) findViewById(R.id.label_wifi);

    mainLayout = ((LinearLayout) findViewById(R.id.mainLayout));
    controlLayout = ((LinearLayout) findViewById(R.id.controlLayout));
    imageLayout = ((LinearLayout) findViewById(R.id.imageLayout));

    adjustLayoutForOrientation(getResources().getConfiguration().orientation);

    findViewById(R.id.buttonCamera).setOnClickListener(new View.OnClickListener() {
        @Override//from   w  w  w. j  a v  a  2 s  . co m
        public void onClick(View v) {
            Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

            cameraFileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, cameraFileUri); // set the image file name

            startActivityForResult(cameraIntent, CAMERA_REQUEST);
        }
    });
    findViewById(R.id.buttonGallery).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_REQUEST);
        }
    });
    votarwebserver = new VotarWebServer(51285, this);
    try {
        votarwebserver.start();
    } catch (IOException e) {
        Log.w("Votar MainAct", "The webserver could not be started, remote display wont be available");
    }
}

From source file:com.codebutler.farebot.activities.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    try {/*from  www  .  j a v a 2  s.  c o  m*/
        if (item.getItemId() == R.id.supported_cards) {
            startActivity(new Intent(this, SupportedCardsActivity.class));
            return true;

        } else if (item.getItemId() == R.id.about) {
            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://codebutler.github.com/farebot")));
            return true;

        } else if (item.getItemId() == R.id.import_clipboard) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            onCardsImported(ExportHelper.importCardsXml(this, clipboard.getText().toString()));
            return true;

        } else if (item.getItemId() == R.id.import_file) {
            Uri uri = Uri.fromFile(Environment.getExternalStorageDirectory());
            Intent i = new Intent(Intent.ACTION_GET_CONTENT);
            i.putExtra(Intent.EXTRA_STREAM, uri);
            i.setType("application/xml");
            startActivityForResult(Intent.createChooser(i, "Select File"), SELECT_FILE);
            return true;

        } else if (item.getItemId() == R.id.import_sd) {
            String xml = FileUtils.readFileToString(new File(SD_EXPORT_PATH));
            onCardsImported(ExportHelper.importCardsXml(this, xml));
            return true;

        } else if (item.getItemId() == R.id.copy_xml) {
            ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            clipboard.setText(ExportHelper.exportCardsXml(this));
            Toast.makeText(this, "Copied to clipboard.", 5).show();
            return true;

        } else if (item.getItemId() == R.id.share_xml) {
            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, ExportHelper.exportCardsXml(this));
            startActivity(intent);
            return true;

        } else if (item.getItemId() == R.id.save_xml) {
            String xml = ExportHelper.exportCardsXml(this);
            File file = new File(SD_EXPORT_PATH);
            FileUtils.writeStringToFile(file, xml, "UTF-8");
            Toast.makeText(this, "Wrote FareBot-Export.xml to USB Storage.", 5).show();
            return true;

        } else if (item.getItemId() == R.id.prefs) {
            startActivity(new Intent(this, FareBotPreferenceActivity.class));
        }
    } catch (Exception ex) {
        Utils.showError(this, ex);
    }
    return false;
}

From source file:com.mifos.mifosxdroid.dialogfragments.DocumentDialogFragment.java

@OnClick(R.id.tv_choose_file)
public void openFilePicker() {
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    intent.setType("*/*");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {//from w w  w. j  a v a2s.c  om
        startActivityForResult(Intent.createChooser(intent, "Select a File to Upload"), FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(getActivity(), "Please install a File Manager.", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.pacoapp.paco.ui.FindMyExperimentsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.debug("FindMyExperimentsActivity onCreate");
    mainLayout = (ViewGroup) getLayoutInflater().inflate(R.layout.find_experiments, null);
    setContentView(mainLayout);//from w  w w . j av  a2 s .  c o  m

    ActionBar actionBar = getSupportActionBar();
    actionBar.setLogo(R.drawable.ic_launcher);
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setBackgroundDrawable(new ColorDrawable(0xff4A53B3));
    actionBar.setDisplayHomeAsUpEnabled(true);

    Intent intent = getIntent();
    if (intent.getData() == null) {
        intent.setData(ExperimentColumns.CONTENT_URI);
    }

    // Set up the drawer.
    // mNavigationDrawerFragment = (NavigationDrawerFragment)
    // getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
    // mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout)
    // findViewById(R.id.drawer_layout));

    userPrefs = new UserPreferences(this);
    list = (ListView) findViewById(R.id.find_experiments_list);
    // createListHeader();
    // createRefreshHeader();

    experimentProviderUtil = new ExperimentProviderUtil(this);

    progressBar = (ProgressBar) findViewById(R.id.findExperimentsProgressBar);

    reloadAdapter();
    list.setItemsCanFocus(false);
    list.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> listview, View textview, int position, long id) {
            Experiment experiment = experiments.get(position);
            getIntent().putExtra(Experiment.EXPERIMENT_SERVER_ID_EXTRA_KEY, experiment.getServerId());

            String action = getIntent().getAction();
            if (Intent.ACTION_PICK.equals(action) || Intent.ACTION_GET_CONTENT.equals(action)) {
                // The caller is waiting for us to return an experiment selected by
                // the user. The have clicked on one, so return it now.
                Intent resultIntent = new Intent();
                resultIntent.putExtra(Experiment.EXPERIMENT_SERVER_ID_EXTRA_KEY, experiment.getServerId());
                setResult(RESULT_OK, resultIntent);
            } else {
                Intent experimentIntent = new Intent(FindMyExperimentsActivity.this,
                        ExperimentDetailActivity.class);
                experimentIntent.putExtra(Experiment.EXPERIMENT_SERVER_ID_EXTRA_KEY, experiment.getServerId());
                experimentIntent.putExtra(ExperimentDetailActivity.ID_FROM_MY_EXPERIMENTS_FILE, true);
                startActivityForResult(experimentIntent, JOIN_REQUEST_CODE);
            }
        }
    });
    // registerForContextMenu(list);
}

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

private void performFileSearch() {
    Intent intent = new Intent(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT
            ? Intent.ACTION_OPEN_DOCUMENT
            : Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType("*/*"); // all file types
    ((FormEntryActivity) getContext()).startActivityForResult(intent,
            ApplicationConstants.RequestCodes.ARBITRARY_FILE_CHOOSER);
}

From source file:de.enlightened.peris.ProfileFragment.java

private void setupElements() {
    this.tvCreated = (TextView) this.activity.findViewById(R.id.profileCreated);
    this.tvPostCount = (TextView) this.activity.findViewById(R.id.profilePostCount);
    this.tvActivity = (TextView) this.activity.findViewById(R.id.profileLastActivity);
    this.tvTagline = (TextView) this.activity.findViewById(R.id.profileTagline);
    this.tvAbout = (TextView) this.activity.findViewById(R.id.profileAbout);
    this.ivProfilePic = (ImageView) this.activity.findViewById(R.id.profilePicture);

    final String userid = this.application.getSession().getServer().serverUserId;
    final LinearLayout avatarButtons = (LinearLayout) this.activity
            .findViewById(R.id.profile_avatar_editor_buttons);

    if (this.userId == null) {
        avatarButtons.setVisibility(View.GONE);
    } else if (!this.userId.equals(userid)) {
        avatarButtons.setVisibility(View.GONE);
    }// ww w. j  av a 2s  . com

    final Button btnPicFromCamera = (Button) this.activity.findViewById(R.id.profile_upload_avatar_camera);
    final Button btnPicFromGallery = (Button) this.activity.findViewById(R.id.profile_upload_avatar_gallery);
    if (!this.canHandleCameraIntent()) {
        btnPicFromCamera.setVisibility(View.GONE);
    }
    btnPicFromGallery.setOnClickListener(new View.OnClickListener() {
        public void onClick(final View v) {
            final Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent, "Select Picture"), GALLERY_PIC_REQUEST);
        }
    });

    btnPicFromCamera.setOnClickListener(new View.OnClickListener() {
        public void onClick(final View v) {
            final Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            final File imagesFolder = new File(Environment.getExternalStorageDirectory(), "temp");
            imagesFolder.mkdirs();
            final File image = new File(imagesFolder, "temp.jpg");
            final Uri uriSavedImage = Uri.fromFile(image);
            imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
            startActivityForResult(imageIntent, CAMERA_PIC_REQUEST);
        }
    });

}