Example usage for android.content Intent ACTION_PICK

List of usage examples for android.content Intent ACTION_PICK

Introduction

In this page you can find the example usage for android.content Intent ACTION_PICK.

Prototype

String ACTION_PICK

To view the source code for android.content Intent ACTION_PICK.

Click Source Link

Document

Activity Action: Pick an item from the data, returning what was selected.

Usage

From source file:com.misczak.joinmybridge.PhoneBookFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {

    case R.id.menu_item_import_contacts:
        Intent importContactIntent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts"));
        importContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
        startActivityForResult(importContactIntent, REQUEST_CONTACT);
        return true;
    case R.id.menu_item_import_calendar:
        Intent importCalendarIntent = new Intent(getActivity(), CalendarActivity.class);
        startActivity(importCalendarIntent);
        return true;
    case R.id.menu_item_settings:
        Intent settingsIntent = new Intent(getActivity(), SettingsActivity.class);
        startActivity(settingsIntent);//from w ww . j a  va  2  s . c  o m
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.ritul.truckshare.RegisterActivity.DriverLicenseActivity.java

public void Image_Picker_Dialog() {

    AlertDialog.Builder myAlertDialog = new AlertDialog.Builder(this);
    myAlertDialog.setTitle("Pictures Option");
    myAlertDialog.setMessage("Select Picture Mode");

    myAlertDialog.setPositiveButton("Gallery", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
            /* Utility.pictureActionIntent = new Intent(Intent.ACTION_GET_CONTENT, null);
             Utility.pictureActionIntent.setType("image*//*");
                                                          Utility.pictureActionIntent.putExtra("return-data", true);
                                                          startActivityForResult(Utility.pictureActionIntent, Utility.GALLERY_PICTURE);*/
            Intent i7 = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i7, Utility.GALLERY_PICTURE);
        }/* w w  w . j a  va  2  s.com*/
    });

    myAlertDialog.setNegativeButton("Camera", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface arg0, int arg1) {
            /*Utility.pictureActionIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(Utility.pictureActionIntent, Utility.CAMERA_PICTURE);*/

            Intent cameraIntent1 = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(cameraIntent1, Utility.CAMERA_PICTURE);

        }
    });
    myAlertDialog.show();

}

From source file:com.support.android.designlibdemo.activities.CampaignDetailActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    imageUrls = new ArrayList<String>();
    customProgress = (CustomProgress) findViewById(R.id.pbGoal);
    ivCampaignImage = (ImageView) findViewById(R.id.ivCampaighnImage);
    tvCampaignOverview = (TextView) findViewById(R.id.tvCampaignOverview);
    ivArrowDown = (ImageView) findViewById(R.id.ivArrowDown);
    //   tvCampaignText = (TextView) findViewById(R.id.tvCampaignDetails);
    tvGoal = (TextView) findViewById(R.id.tvCampaignGoal);
    btTakeActionRipple = (RippleView) findViewById(R.id.bt_take_an_action_ripple);
    campaign = (Campaign) getIntent().getSerializableExtra(ITENT_TAG);

    if (campaign.getIsSupported()) {
        btTakeActionRipple.setVisibility(View.GONE);
        ivArrowDown.setImageResource(R.drawable.ic_checked);
    } else {/* ww w . ja  v  a 2  s  . c om*/
        btTakeActionRipple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
            @Override
            public void onComplete(RippleView rippleView) {
                Intent i = new Intent(CampaignDetailActivity.this, SignPetitionActivity.class);
                i.putExtra(ITENT_TAG, campaign);
                startActivity(i);
            }
        });
    }

    getImagesUploadedByUserForCampaign(campaign.getObjectId());

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);

    collapsingToolbar.setTitle(campaign.getTitle());
    collapsingToolbar.getCollapsedTitleGravity();
    loadBackdrop(campaign.getImageUrl(), ivCampaignImage);

    PrettyText goal = new PrettyText();
    String decimalGoal = "";
    String decimalCount = "";

    //setting up progress bar
    customProgress.setProgressColor(getResources().getColor(R.color.green_500));
    customProgress.setProgressBackgroundColor(getResources().getColor(R.color.green_200));
    customProgress.setMaximumPercentage(calculatePercentage(campaign.getGoal(), campaign.getGoalCount()));
    customProgress.useRoundedRectangleShape(30.0f);
    customProgress.setShowingPercentage(true);
    //set text above progress
    tvCampaignOverview.setText(campaign.getShortDescription());

    expandableTextView = (ExpandableTextView) findViewById(R.id.viewmore);

    expandableTextView.setText(campaign.getLongDescription());

    //  tvCampaignText.setText(campaign.getLongDescription());

    //set goal text
    decimalGoal = goal.addComma(campaign.getGoal()) + " signatures";
    decimalCount = goal.addComma(campaign.getGoalCount());
    tvGoal.setText(decimalCount + " out of " + decimalGoal);

    ivCampaignImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (imageUrls.size() > 0) {
                Intent i = new Intent(CampaignDetailActivity.this, PhotoGalleryActivity.class);
                i.putExtra(ITENT_TAG, campaign.getObjectId());
                i.putStringArrayListExtra(ITENT_TAG, imageUrls);
                startActivity(i);
                overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
            } else {
                buildDialogNoPictures(CampaignDetailActivity.this).show();
            }
        }
    });

    //set floating action button
    floatingCamera = (FloatingActionButton) findViewById(R.id.bt_camera);
    final int[] selection = new int[1];

    floatingCamera.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            FragmentManager fm = getSupportFragmentManager();
            final CameraDialog dialog = CameraDialog.newInstance("Add a new picture:");

            dialog.setOnChoiceClickListener(new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    selection[0] = which;
                }
            });

            dialog.setPositiveListener(new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    if (selection[0] == 0) {
                        // create Intent to take a picture and return control to the calling application
                        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                        photoUri = Uri.fromFile(getOutputMediaFile()); // create a file to save the image
                        intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri); // set the image file name
                        // Start the image capture intent to take photo
                        startActivityForResult(intent, TAKE_PHOTO_CODE);
                    } else {
                        // Take the user to the gallery app to pick a photo
                        Intent photoGalleryIntent = new Intent(Intent.ACTION_PICK,
                                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(photoGalleryIntent, PICK_PHOTO_CODE);

                    }
                    dialog.dismiss();

                }
            });

            dialog.setCancelClickListener(new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                }

            });

            dialog.show(fm, "TAG_DIALOG");

        }

    });

}

From source file:com.android.music.ArtistAlbumBrowserFragment.java

@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

    mCurrentAlbumId = Long.valueOf(id).toString();

    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
    intent.setClass(getActivity(), TrackBrowserActivity.class);
    intent.putExtra("album", mCurrentAlbumId);
    Cursor c = (Cursor) mAdapter.getChild(groupPosition, childPosition);
    String album = c.getString(c.getColumnIndex(MediaStore.Audio.Albums.ALBUM));
    if (album == null || album.equals(MediaStore.UNKNOWN_STRING)) {
        // unknown album, so we should include the artist ID to limit the songs to songs only by that artist 
        mArtistCursor.moveToPosition(groupPosition);
        mCurrentArtistId = mArtistCursor.getString(mArtistCursor.getColumnIndex(MediaStore.Audio.Artists._ID));
        intent.putExtra("artist", mCurrentArtistId);
    }/*ww  w. j  a v  a  2 s .  c  o m*/
    startActivity(intent);
    return true;
}

From source file:com.freeme.filemanager.view.FileViewFragment.java

public void init() {
    long time1 = System.currentTimeMillis();
    //Debug.startMethodTracing("file_view");
    ViewStub stub = (ViewStub) mRootView.findViewById(R.id.viewContaniner);
    stub.setLayoutResource(R.layout.file_explorer_list);
    stub.inflate();/*  www .  j  a v a  2 s  .c o  m*/
    ActivitiesManager.getInstance().registerActivity(ActivitiesManager.ACTIVITY_FILE_VIEW, mActivity);

    mFileCagetoryHelper = new FileCategoryHelper(mActivity);
    mFileViewInteractionHub = new FileViewInteractionHub(this, 1);
    // */ modify by droi liuhaoran for stop run
    /*/ Added by tyd wulianghuan 2013-12-12
    mCleanUpDatabaseHelper = new CleanUpDatabaseHelper(mActivity);
    mDatabase = mCleanUpDatabaseHelper.openDatabase();
    mFolderNameMap = new HashMap<String, String>();
    //*/

    // */add by droi liuhaoran for get Sd listener on 20160419
    mApplication = (FileManagerApplication) mActivity.getApplication();
    // */

    // notifyFileChanged();
    Intent intent = mActivity.getIntent();
    String action = intent.getAction();
    if (!TextUtils.isEmpty(action)
            && (action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT))) {
        mFileViewInteractionHub.setMode(Mode.Pick);

        boolean pickFolder = intent.getBooleanExtra(PICK_FOLDER, false);
        if (!pickFolder) {
            String[] exts = intent.getStringArrayExtra(EXT_FILTER_KEY);
            if (exts != null) {
                mFileCagetoryHelper.setCustomCategory(exts);
            }
        } else {
            mFileCagetoryHelper.setCustomCategory(new String[] {} /*
                                                                  * folder
                                                                  * only
                                                                  */);
            mRootView.findViewById(R.id.pick_operation_bar).setVisibility(View.VISIBLE);

            mRootView.findViewById(R.id.button_pick_confirm).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    try {
                        Intent intent = Intent.parseUri(mFileViewInteractionHub.getCurrentPath(), 0);
                        mActivity.setResult(Activity.RESULT_OK, intent);
                        mActivity.finish();
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                }
            });

            mRootView.findViewById(R.id.button_pick_cancel).setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    mActivity.finish();
                }
            });
        }
    } else {
        mFileViewInteractionHub.setMode(Mode.View);
    }
    mVolumeSwitch = (ImageButton) mRootView.findViewById(R.id.volume_navigator);
    updateVolumeSwitchState();
    mGalleryNavigationBar = (RelativeLayout) mRootView.findViewById(R.id.gallery_navigation_bar);
    mVolumeSwitch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            int visibility = getVolumesListVisibility();
            if (visibility == View.GONE) {
                buildVolumesList();
                showVolumesList(true);
            } else if (visibility == View.VISIBLE) {
                showVolumesList(false);
            }
        }

    });
    mFileListView = (ListView) mRootView.findViewById(R.id.file_path_list);
    mFileIconHelper = new FileIconHelper(mActivity);
    mAdapter = new FileListAdapter(mActivity, R.layout.file_browser_item, mFileNameList,
            mFileViewInteractionHub, mFileIconHelper);

    boolean baseSd = intent.getBooleanExtra(GlobalConsts.KEY_BASE_SD,
            !FileExplorerPreferenceActivity.isReadRoot(mActivity));
    Log.i(LOG_TAG, "baseSd = " + baseSd);

    String rootDir = intent.getStringExtra(ROOT_DIRECTORY);
    if (!TextUtils.isEmpty(rootDir)) {
        if (baseSd && this.sdDir.startsWith(rootDir)) {
            rootDir = this.sdDir;
        }
    } else {
        rootDir = baseSd ? this.sdDir : GlobalConsts.ROOT_PATH;
    }

    String currentDir = FileExplorerPreferenceActivity.getPrimaryFolder(mActivity);
    Uri uri = intent.getData();
    if (uri != null) {
        if (baseSd && this.sdDir.startsWith(uri.getPath())) {
            currentDir = this.sdDir;
        } else {
            currentDir = uri.getPath();
        }
    }
    initVolumeState();
    mBackspaceExit = (uri != null) && (TextUtils.isEmpty(action)
            || (!action.equals(Intent.ACTION_PICK) && !action.equals(Intent.ACTION_GET_CONTENT)));

    mFileListView.setAdapter(mAdapter);
    IntentFilter intentFilter = new IntentFilter();
    // add by xueweili for get sdcard
    intentFilter.setPriority(1000);

    /*
     * intentFilter.addAction(Intent.ACTION_MEDIA_MOUNTED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
     * intentFilter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
     * intentFilter.addAction(Intent.ACTION_MEDIA_EJECT);
     */
    if (!mReceiverTag) {
        mReceiverTag = true;
        intentFilter.addAction(GlobalConsts.BROADCAST_REFRESH);
        intentFilter.addDataScheme("file");
        mActivity.registerReceiver(mReceiver, intentFilter);
    }

    // */add by droi liuhaoran for get Sd listener on 20160419
    mApplication.addSDCardChangeListener(this);
    // */

    setHasOptionsMenu(true);

    // add by mingjun for load file
    mRootView.addOnLayoutChangeListener(new OnLayoutChangeListener() {

        @Override
        public void onLayoutChange(View arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6,
                int arg7, int arg8) {
            isLayout = arg1;
        }
    });
    loadDialog = new ProgressDialog(mRootView.getContext());
}

From source file:info.shibafu528.gallerymultipicker.MultiPickerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    super.onOptionsItemSelected(item);
    int id = item.getItemId();
    if (id == android.R.id.home) {
        if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
            getSupportFragmentManager().popBackStack();
        } else {/* w ww  . j  a va2s  .  c om*/
            setResult(RESULT_CANCELED);
            finish();
        }
    } else if (id == R.id.info_shibafu528_gallerymultipicker_action_decide) {
        accept(getSelectedUris());
    } else if (id == R.id.info_shibafu528_gallerymultipicker_action_gallery) {
        Intent intent = new Intent(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? Intent.ACTION_PICK
                : Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        startActivityForResult(intent, REQUEST_GALLERY);
    } else if (id == R.id.info_shibafu528_gallerymultipicker_action_take_a_photo) {
        boolean existExternal = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
        if (!existExternal) {
            Toast.makeText(this, R.string.info_shibafu528_gallerymultipicker_storage_error, Toast.LENGTH_SHORT)
                    .show();
            return true;
        } else {
            File extDestDir = new File(
                    Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM),
                    mCameraDestDir != null ? mCameraDestDir : "Camera");
            if (!extDestDir.exists()) {
                extDestDir.mkdirs();
            }
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
            String fileName = sdf.format(new Date(System.currentTimeMillis()));
            File destFile = new File(extDestDir.getPath(), fileName + ".jpg");
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.TITLE, fileName);
            values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
            values.put(MediaStore.Images.Media.DATA, destFile.getPath());
            mCameraTemp = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraTemp);
            startActivityForResult(intent, REQUEST_CAMERA);
        }
    }
    return true;
}

From source file:de.questmaster.fatremote.fragments.RemoteFragment.java

/**
 * Define menu action/*from   www . j  av a2 s.  co  m*/
 * 
 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
    case R.id.MENU_ITEM_SELECTFAT: {
        Intent selectFAT = new Intent(Intent.ACTION_PICK);
        selectFAT.setClass(c, SelectFATActivity.class);
        selectFAT.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(selectFAT);

        break;
    }
    case R.id.MENU_ITEM_SETTINGS: {
        Intent iSettings = new Intent();
        iSettings.setClass(c, FatRemoteSettings.class);
        startActivityForResult(iSettings, ON_SETTINGS_CHANGE);

        break;
    }
    case R.id.MENU_ITEM_DEBUG: {
        c.setContentView(R.layout.debug);
        break;
    }
    default:
        // should not happen
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:info.staticfree.android.units.Units.java

private void handleIntent(Intent intent) {
    final String action = intent.getAction();
    if (Intent.ACTION_SEARCH.equals(action)) {
        final Intent pickUnit = new Intent(Intent.ACTION_PICK, UsageEntry.CONTENT_URI);
        final String query = intent.getExtras().getString(SearchManager.QUERY);
        pickUnit.putExtra(UnitList.EXTRA_UNIT_QUERY, query);

        startActivityForResult(pickUnit, REQUEST_PICK_UNIT);

    } else if (ACTION_USE_UNIT.equals(action)) {
        sendUnitAsSoftKeyboard(intent.getData());
    }//from  w  ww .  j a va 2s  . c  o  m
}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.ReportAccident.ReportAccidentForm.java

private void galleryIntent() {
    //        Intent intent = new Intent();
    //        intent.setType("image/*");
    //        intent.setAction(Intent.ACTION_GET_CONTENT);//
    //        startActivityForResult(Intent.createChooser(intent, "Select File"),SELECT_FILE);
    Log.d("", "galleryIntent: SSCARD Button");
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_PICK);//
    startActivityForResult(Intent.createChooser(intent, "Select File"), SELECT_FILE);
}

From source file:com.money.manager.ex.settings.PerDatabaseFragment.java

/**
 * select the base currency in a currency picker instead of a list.
 *//*from w  w  w  .j  ava 2 s.  c  om*/
private void initBaseCurrency() {
    Preference baseCurrency = findPreference(getString(PreferenceConstants.PREF_BASE_CURRENCY));
    if (baseCurrency == null)
        return;

    // Display the current default currency as the summary.
    showCurrentDefaultCurrency();

    // After the currency is selected in the Currencies screen, the change is handled
    // in onActivityResult

    Preference.OnPreferenceClickListener clickListener = new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {
            // show the currencies activity
            Intent intent = new Intent(getActivity(), CurrencyListActivity.class);
            intent.setAction(Intent.ACTION_PICK);
            startActivityForResult(intent, REQUEST_PICK_CURRENCY);

            return true;
        }
    };

    baseCurrency.setOnPreferenceClickListener(clickListener);
}