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.dongbang.yutian.activity.CommonScanActivity.java

public void showPictures(int requestCode) {
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType("image/*");
    startActivityForResult(intent, requestCode);
}

From source file:com.seekon.yougouhui.activity.shop.RegisterShopActivity.java

private void initViews() {
    licenseInfoView = mInflater.inflate(R.layout.shop_register_license, null);
    baseInfoView = mInflater.inflate(R.layout.shop_register_base, null);
    pwdInfoView = mInflater.inflate(R.layout.shop_register_pwd, null);

    viewPager = (ViewPager) findViewById(R.id.shop_register_viewpager);
    viewPager.setOnPageChangeListener(this);
    viewPager.setCurrentItem(0);//  w w  w . ja  v  a 2  s  . c  o  m

    List<View> pageViews = new ArrayList<View>();
    pageViews.add(licenseInfoView);
    pageViews.add(baseInfoView);
    pageViews.add(pwdInfoView);
    viewPager.setAdapter(new BasePagerAdapter(pageViews, pageTitles));

    GridView tradeView = (GridView) baseInfoView.findViewById(R.id.shop_trade_view);

    tradeAdapter = new TradeListAdapter(this, getTradeList());
    tradeView.setAdapter(tradeAdapter);

    loadTrades();

    nameView = (TextView) baseInfoView.findViewById(R.id.shop_name);
    addrView = (TextView) baseInfoView.findViewById(R.id.shop_address);
    descView = (TextView) baseInfoView.findViewById(R.id.shop_desc);
    shopImgView = (ImageView) baseInfoView.findViewById(R.id.shop_image);
    busiLicenseView = (ImageView) baseInfoView.findViewById(R.id.shop_busi_license);

    shopImgView.setLayoutParams(new FrameLayout.LayoutParams(SHOP_ICON_WIDTH, SHOP_ICON_WIDTH));
    shopImgView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(intent, LOAD_IMAGE_REQUEST_CODE);
        }
    });

    busiLicenseView.setLayoutParams(new FrameLayout.LayoutParams(SHOP_ICON_WIDTH, SHOP_ICON_WIDTH));
    busiLicenseView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(intent, LOAD_LICENSE_REQUEST_CODE);
        }
    });

    pwdView = (TextView) pwdInfoView.findViewById(R.id.password);
    pwdConfView = (TextView) pwdInfoView.findViewById(R.id.password_conf);
    userPhoneView = (TextView) pwdInfoView.findViewById(R.id.user_phone);
    userNameView = (TextView) pwdInfoView.findViewById(R.id.user_name);

    UserEntity user = RunEnv.getInstance().getUser();
    userPhoneView.setText(user.getPhone());
    ViewUtils.setEditTextReadOnly(userPhoneView);

    if (!UserUtils.isAnonymousUser()) {
        userNameView.setText(user.getName());
        ViewUtils.setEditTextReadOnly(userNameView);
    }
}

From source file:org.yammp.fragment.QueryFragment.java

public void onServiceConnected(ComponentName name, IBinder service) {

    Bundle bundle = getArguments();/* w w w . j  a  va  2s  . c  o m*/

    String action = bundle != null ? bundle.getString(INTENT_KEY_ACTION) : null;
    String data = bundle != null ? bundle.getString(INTENT_KEY_DATA) : null;

    if (Intent.ACTION_VIEW.equals(action)) {
        // this is something we got from the search bar
        Uri uri = Uri.parse(data);
        if (data.startsWith("content://media/external/audio/media/")) {
            // This is a specific file
            String id = uri.getLastPathSegment();
            long[] list = new long[] { Long.valueOf(id) };
            mUtils.playAll(list, 0);
            getActivity().finish();
            return;
        } else if (data.startsWith("content://media/external/audio/albums/")) {
            // This is an album, show the songs on it
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/track");
            i.putExtra("album", uri.getLastPathSegment());
            startActivity(i);
            return;
        } else if (data.startsWith("content://media/external/audio/artists/")) {
            // This is an artist, show the albums for that artist
            Intent i = new Intent(Intent.ACTION_PICK);
            i.setDataAndType(Uri.EMPTY, "vnd.android.cursor.dir/album");
            i.putExtra("artist", uri.getLastPathSegment());
            startActivity(i);
            return;
        }
    }

    mFilterString = bundle != null ? bundle.getString(SearchManager.QUERY) : null;
    if (MediaStore.INTENT_ACTION_MEDIA_SEARCH.equals(action)) {
        String focus = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_FOCUS) : null;
        String artist = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ARTIST) : null;
        String album = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_ALBUM) : null;
        String title = bundle != null ? bundle.getString(MediaStore.EXTRA_MEDIA_TITLE) : null;
        if (focus != null) {
            if (focus.startsWith("audio/") && title != null) {
                mFilterString = title;
            } else if (Audio.Albums.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (album != null) {
                    mFilterString = album;
                    if (artist != null) {
                        mFilterString = mFilterString + " " + artist;
                    }
                }
            } else if (Audio.Artists.ENTRY_CONTENT_TYPE.equals(focus)) {
                if (artist != null) {
                    mFilterString = artist;
                }
            }
        }
    }

    mTrackList = getListView();
    mTrackList.setTextFilterEnabled(true);
}

From source file:Rangoli.testapp.Feed.NewPostActivity.java

@AfterPermissionGranted(RC_CAMERA_PERMISSIONS)
private void showImagePicker() {
    // Check for camera permissions
    if (!EasyPermissions.hasPermissions(this, cameraPerms)) {
        EasyPermissions.requestPermissions(this, "This sample will upload a picture from your Camera",
                RC_CAMERA_PERMISSIONS, cameraPerms);
        return;//from w ww  .j  a  v a  2s  .  c  om
    }

    // Choose file storage location
    File file = new File(getExternalCacheDir(), UUID.randomUUID().toString());
    mFileUri = Uri.fromFile(file);

    // Camera
    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    final PackageManager packageManager = getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mFileUri);
        cameraIntents.add(intent);
    }

    // Image Picker
    Intent pickerIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

    Intent chooserIntent = Intent.createChooser(pickerIntent, "");
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            cameraIntents.toArray(new Parcelable[cameraIntents.size()]));
    startActivityForResult(chooserIntent, TC_PICK_IMAGE);
}

From source file:edu.cens.loci.ui.PlaceListActivity.java

/**
 * USE CASES:/*from www.java2s  .  c  om*/
 * 
 * 1. DEFAULT :
 *       list places and when selected, ACTION_VIEW
 * 
 *       ACTION ... send ACTION_VIEW content://places/pid 
 *       SHOW ...
 *    - Suggested places ... add "View GPS Places"
 *    - Registered places ...
 *    - Blocked places ...
 *    - Filter by tag ...
 * 
 * 2. INSERT_OR_EDIT :
 *    list "create a new place" and "registered" places, when selected, ACTION_EDIT
 *    
 *    ACTION ... send ACTION_EDIT content://places/pid or ACTION_INSERT content://places
 *    - show all suggested/registered/blocked places
 *    SHOW...
 *    - "create a new place" and "registered places"
 *    
 * 3. PICK :
 *       list places and when selected, return with a uri.
 * 
 *       ACTION ... return a data URL back to the caller
 *       SHOW... 
 * 
 * 4. SEARCH :
 *     TBD
 * 
 */

@Override
protected void onCreate(Bundle icicle) {

    super.onCreate(icicle);

    setContentView(R.layout.place_list);

    // Resolve the intent
    final Intent intent = getIntent();

    String title = intent.getStringExtra(UI.TITLE_EXTRA_KEY);
    if (title != null) {
        setTitle(title);
    }

    String action = intent.getAction();

    if (Intent.ACTION_VIEW.equals(action)) {
        mMode = MODE_VIEW;
    } else if (Intents.UI.ACTION_INSERT.equals(action)) {
        mMode = MODE_INSERT;
    } else if (Intents.UI.ACTION_CREATE_OR_ADDTO_FROM_SUGGESTED_PLACE.equals(action)) {
        mMode = MODE_REGISTER_SUGGESTED;
    } else if (Intent.ACTION_PICK.equals(action)) {
        mMode = MODE_PICK;
    }

    MyLog.i(LociConfig.D.UI.DEBUG, TAG, String.format("List: mode=%d (%s)", mMode, action));

    Bundle extras = intent.getExtras();

    if (extras != null) {
        if (extras.containsKey(Intents.UI.FILTER_STATE_EXTRA_KEY))
            mFilterState = extras.getInt(Intents.UI.FILTER_STATE_EXTRA_KEY);
        if (extras.containsKey(Intents.UI.FILTER_TYPE_EXTRA_KEY))
            mFilterType = extras.getInt(Intents.UI.FILTER_TYPE_EXTRA_KEY);
        if (extras.containsKey(Intents.UI.FILTER_TAG_EXTRA_KEY))
            mFilterTag = extras.getString(Intents.UI.FILTER_TAG_EXTRA_KEY);
        if (extras.containsKey(Intents.UI.LIST_ORDER_EXTRA_KEY))
            mListOrder = extras.getInt(Intents.UI.LIST_ORDER_EXTRA_KEY);
    }

    mDbUtils = new LociDbUtils(this);
}

From source file:com.vmihalachi.turboeditor.activity.HomeActivity.java

/**
 * When a file is saved//from   w  ww  . jav  a2 s . c o  m
 * Invoked by the EditorFragment
 *
 * @param event The event called
 */
public void onEvent(FileSavedEvent event) {
    try {
        closeKeyBoard();
    } catch (NullPointerException e) {
        Log.e(TAG, e.getMessage(), e);
    }
    // Get intent, action and MIME type
    final Intent intent = getIntent();
    final String action = intent.getAction();
    final String type = intent.getType();

    if (Intent.ACTION_VIEW.equals(action) || Intent.ACTION_EDIT.equals(action)
            || Intent.ACTION_PICK.equals(action) && type != null) {
        //This Activity was called by startActivityForResult
        final Intent returnIntent = new Intent();
        setResult(Activity.RESULT_OK, returnIntent);
        // finish the activity
        finish();
    } else {
        //This Activity was called by startActivity
        //
        mDrawerLayout.openDrawer(Gravity.LEFT);
        //
        getActionBar().setTitle(getString(R.string.nome_app_turbo_editor));
        // Replace fragment
        getFragmentManager().beginTransaction().replace(R.id.fragment_editor, new NoFileOpenedFragment())
                .commit();
    }
}

From source file:org.benetech.secureapp.activities.MainActivity.java

/**
 * Stores the path of selected instance in the parent class and finishes.
 *///from   w w  w.  j av a 2  s .c  o  m
@Override
protected void onListItemClick(ListView listView, View view, int position, long id) {
    Cursor cursor = (Cursor) getListAdapter().getItem(position);
    startManagingCursor(cursor);
    Uri instanceUri = ContentUris.withAppendedId(InstanceProviderAPI.InstanceColumns.CONTENT_URI,
            cursor.getLong(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns._ID)));

    Collect.getInstance().getActivityLogger().logAction(this, "onListItemClick", instanceUri.toString());

    String action = getIntent().getAction();
    if (Intent.ACTION_PICK.equals(action)) {
        // caller is waiting on a picked form
        setResult(RESULT_OK, new Intent().setData(instanceUri));
    } else {
        // the form can be edited if it is incomplete or if, when it was
        // marked as complete, it was determined that it could be edited
        // later.
        String status = cursor.getString(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.STATUS));
        String canEditWhenCompleteSetting = cursor
                .getString(cursor.getColumnIndex(InstanceProviderAPI.InstanceColumns.CAN_EDIT_WHEN_COMPLETE));

        boolean canEdit = status.equals(InstanceProviderAPI.STATUS_INCOMPLETE)
                || Boolean.parseBoolean(canEditWhenCompleteSetting);
        if (canEdit) {
            startForm(instanceUri);
        }
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.PhotoUploadWidget.java

@Override
public void initializeWidget() {
    mImagePreview = (ImageView) findViewById(R.id.image_preview);
    mSourceButton = (Button) findViewById(R.id.select_picture);
    mSourceButton.setText(R.string.get_picture);
    mPhotoSelected = false;//from  w ww . java  2  s .  c o m

    mRatio = (String) mWidgetMap.get("ratio");
    mQuality = (String) mWidgetMap.get("quality");

    mSourceButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            final SafeRunnable runnableContinue = new SafeRunnable() {
                @Override
                protected void safeRun() throws Exception {
                    getPicture();
                }
            };

            final SafeRunnable runnableCheckStorage = new SafeRunnable() {
                @Override
                protected void safeRun() throws Exception {
                    if (mActivity.askPermissionIfNeeded(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                            ServiceMessageDetailActivity.PERMISSION_REQUEST_PHOTO_UPLOAD_WIDGET,
                            runnableContinue, mActivity.showMandatoryPermissionPopup(mActivity,
                                    Manifest.permission.WRITE_EXTERNAL_STORAGE)))
                        return;
                    runnableContinue.run();
                }
            };

            if (TRUE.equals(mWidgetMap.get("camera"))) {
                if (mActivity.askPermissionIfNeeded(Manifest.permission.CAMERA,
                        ServiceMessageDetailActivity.PERMISSION_REQUEST_PHOTO_UPLOAD_WIDGET,
                        runnableCheckStorage,
                        mActivity.showMandatoryPermissionPopup(mActivity, Manifest.permission.CAMERA)))
                    return;
            }

            runnableCheckStorage.run();
        }

        private void getPicture() {
            File image;
            try {
                image = getTmpUploadPhotoLocation();
            } catch (IOException e) {
                L.d(e.getMessage());
                UIUtils.showLongToast(getContext(), e.getMessage());
                return;
            }
            mUriSavedImage = Uri.fromFile(image);

            Intent cameraIntent = null;
            boolean hasCamera = mActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
            boolean hasCameraPermission = mActivity.getMainService().isPermitted(Manifest.permission.CAMERA);
            if (hasCamera && hasCameraPermission) {
                cameraIntent = ActivityUtils.buildTakePictureIntent(mActivity, mUriSavedImage, Facing.BACK);
            }

            Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            galleryIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUriSavedImage);
            galleryIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
            galleryIntent.setType("image/*");

            final Intent chooserIntent;
            if (TRUE.equals(mWidgetMap.get("gallery")) && TRUE.equals(mWidgetMap.get("camera"))) {
                chooserIntent = Intent.createChooser(galleryIntent,
                        mActivity.getString(R.string.select_source));
                if (cameraIntent != null) {
                    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { cameraIntent });
                }

                mActivity.startActivityForResult(chooserIntent, PICK_IMAGE);
            } else if (TRUE.equals(mWidgetMap.get("gallery"))) {
                chooserIntent = Intent.createChooser(galleryIntent,
                        mActivity.getString(R.string.select_source));
                mActivity.startActivityForResult(chooserIntent, PICK_IMAGE);
            } else if (TRUE.equals(mWidgetMap.get("camera"))) {
                if (cameraIntent != null) {
                    mActivity.startActivityForResult(cameraIntent, PICK_IMAGE);
                } else if (!hasCamera) {
                    UIUtils.showDialog(mActivity, R.string.no_camera_available_title,
                            R.string.no_camera_available);
                } else if (!hasCameraPermission) {
                    String title = mActivity.getString(R.string.need_camera_permission_title);
                    String message = mActivity.getString(R.string.need_camera_permission);
                    SafeDialogClick onPositiveClick = new SafeDialogClick() {
                        @Override
                        public void safeOnClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                            Intent intent = new Intent();
                            intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            Uri uri = Uri.fromParts("package", mActivity.getPackageName(), null);
                            intent.setData(uri);
                            mActivity.startActivity(intent);
                        }
                    };
                    UIUtils.showDialog(mActivity, title, message, R.string.go_to_app_settings, onPositiveClick,
                            R.string.cancel, null);
                }
            }
        }
    });
}

From source file:ca.ualberta.app.activity.CreateQuestionActivity.java

public void select_question_pic(View view) {
    Intent intent = new Intent(Intent.ACTION_PICK, null);
    intent.setType("image/*");
    startActivityForResult(intent, GET_IMAGE_ACTIVITY_REQUEST_CODE);
}

From source file:com.microsoft.assetmanagement.DisplayCarActivity.java

/**
 * Select picture./*from w  w w.  j a  v a 2 s  .com*/
 */
private void selectPicture() {
    final Activity that = this;

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            CharSequence[] sources = { "From Library", "From Camera" };
            AlertDialog.Builder builder = new AlertDialog.Builder(that);
            builder.setTitle("Select an option:").setSingleChoiceItems(sources, 0,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int item) {
                            dialog.dismiss();
                            openPhotoSource(item);
                        }

                        private void openPhotoSource(int itemSelected) {
                            switch (itemSelected) {
                            case 0:
                                invokePhotoLibrayIntent();
                                break;
                            case 1:
                                invokeFromCameraIntent();
                                break;
                            default:
                                break;
                            }
                        }

                        private void invokeFromCameraIntent() {
                            dispatchTakePictureIntent();
                        }

                        private void invokePhotoLibrayIntent() {
                            Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
                            photoPickerIntent.setType("image/*");
                            startActivityForResult(photoPickerIntent, SELECT_PHOTO);
                        }
                    });
            builder.create().show();
        }
    });
}