Java Code Examples for android.content.Intent#ACTION_PICK

The following examples show how to use android.content.Intent#ACTION_PICK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IntentHelper.java    From candybar with Apache License 2.0 6 votes vote down vote up
public static int getAction(@Nullable Intent intent) {
    if (intent == null) return ACTION_DEFAULT;
    String action = intent.getAction();
    if (action != null) {
        switch (action) {
            case ACTION_ADW_PICK_ICON:
            case ACTION_TURBO_PICK_ICON:
            case ACTION_LAWNCHAIR_ICONPACK:
            case ACTION_NOVA_LAUNCHER:
            case ACTION_ONEPLUS_PICK_ICON:
            case ACTION_PLUS_HOME:
                return ICON_PICKER;
            case Intent.ACTION_PICK:
            case Intent.ACTION_GET_CONTENT:
                return IMAGE_PICKER;
            case Intent.ACTION_SET_WALLPAPER:
                return WALLPAPER_PICKER;
            default:
                return ACTION_DEFAULT;
        }
    }

    return ACTION_DEFAULT;
}
 
Example 2
Source File: SelectImgUtil.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public ArrayList<String> listAlldir() {
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    Uri uri = intent.getData();
    ArrayList<String> list = new ArrayList<String>();
    String[] proj = {
            MediaStore.Images.Media.DATA
    };
    String orderBy = MediaStore.Images.Media.DATE_TAKEN + " DESC";
    Cursor cursor = context.getContentResolver().query(uri, proj, null, null, orderBy);
    if (cursor == null) {
        return null;
    }
    while (cursor.moveToNext()) {
        String path = cursor.getString(0);
        list.add(new File(path).getAbsolutePath());
    }
    return list;
}
 
Example 3
Source File: ActionPicture.java    From MagicalCamera with Apache License 2.0 6 votes vote down vote up
/**
 * This call the intent to selected the picture for activity screen
 * @param headerName the header name of popUp that you need to shown
 * @return return true if the photo was taken or false if it was not.
 */
public boolean selectedPicture(String headerName) {

    try {
        Intent intent = new Intent(
                Intent.ACTION_PICK,
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        intent.setType("image/*");
        this.actionPictureObject.getActivity().startActivityForResult(
                Intent.createChooser(intent, (!headerName.equals("") ? headerName : "Magical Camera")),
                MagicalCamera.SELECT_PHOTO);

        return true;
    }catch (Exception ev){
        return false;
    }
}
 
Example 4
Source File: CreateArticleActivity.java    From 1Rramp-Android with MIT License 6 votes vote down vote up
private void openGallery() {
  try {
    leftActivityWithPurpose = true;
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
      ||
      ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
      ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_IMAGE_SELECTOR);
    } else {
      Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      intent.setType("image/*");
      startActivityForResult(intent, REQUEST_IMAGE_SELECTOR);
    }
  }
  catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example 5
Source File: ImagePickerActivity.java    From Status with Apache License 2.0 5 votes vote down vote up
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);

    if (!StaticUtils.isPermissionsGranted(this, permissions)) {
        Toast.makeText(this, R.string.msg_missing_storage_permission, Toast.LENGTH_SHORT).show();
        finish();
    } else {
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        startActivityForResult(intent, ACTION_PICK_IMAGE);
    }
}
 
Example 6
Source File: ShareUtil.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
/**
 * Request a picture from gallery
 * Result will be available from {@link Activity#onActivityResult(int, int, Intent)}.
 * It will return the path to the image if locally stored. If retrieved from e.g. a cloud
 * service, the image will get copied to app-cache folder and it's path returned.
 */
public void requestGalleryPicture() {
    if (!(_context instanceof Activity)) {
        throw new RuntimeException("Error: ShareUtil.requestGalleryPicture needs an Activity Context.");
    }
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    try {
        ((Activity) _context).startActivityForResult(intent, REQUEST_PICK_PICTURE);
    } catch (Exception ex) {
        Toast.makeText(_context, "No gallery app installed!", Toast.LENGTH_SHORT).show();
    }
}
 
Example 7
Source File: BottomSheetImagePicker.java    From HaiNaBaiChuan with Apache License 2.0 5 votes vote down vote up
/**
 * This checks to see if there is a suitable activity to handle the `ACTION_PICK` intent
 * and returns it if found. {@link Intent#ACTION_PICK} is for picking an image from an external app.
 *
 * @return A prepared intent if found.
 */
@Nullable
private Intent createPickIntent() {
    if (pickerType != PickerType.CAMERA) {
        Intent picImageIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        if (picImageIntent.resolveActivity(getActivity().getPackageManager()) != null) {
            return picImageIntent;
        }
    }
    return null;
}
 
Example 8
Source File: MainActivity.java    From GPS2SMS with GNU General Public License v3.0 5 votes vote down vote up
public void chooseContact(View v) {
    Intent intent = new Intent(Intent.ACTION_PICK,
            ContactsContract.Contacts.CONTENT_URI);
    intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
    startActivityForResult(intent, ACT_RESULT_CHOOSE_CONTACT);
    //IncomingSms.sendNotification(MainActivity.this, "56.5555555,56.7777777");
}
 
Example 9
Source File: Sana.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Starts Activity for selecting and then viewing a previous encounter
 */
private void pickSavedProcedure() {
    Intent i = new Intent(Intent.ACTION_PICK);
    i.setType(Encounters.CONTENT_TYPE);
    i.setData(Encounters.CONTENT_URI);
    onSaveAppState(i);
    startActivityForResult(i, PICK_SAVEDPROCEDURE);
}
 
Example 10
Source File: NewsfeedTry.java    From Nimbus with GNU General Public License v3.0 5 votes vote down vote up
private void createChooser() {
    if (ContextCompat.checkSelfPermission(NewsfeedTry.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 121);
        }

        return;

    }

    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    startActivityForResult(Intent.createChooser(intent, "CHOOSE PHOTO"), PICK_IMAGE_REQUEST);
}
 
Example 11
Source File: ShareActivity.java    From zxingfragmentlib with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
  Intent intent = new Intent(Intent.ACTION_PICK);
  intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
  intent.setClassName(ShareActivity.this, AppPickerActivity.class.getName());
  startActivityForResult(intent, PICK_APP);
}
 
Example 12
Source File: ContactManager.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
/**
 * Launches the Contact Picker to select a single contact.
 */
private void pickContactAsync() {
    final CordovaPlugin plugin = (CordovaPlugin) this;
    Runnable worker = new Runnable() {
        public void run() {
            Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
            plugin.cordova.startActivityForResult(plugin, contactPickerIntent, CONTACT_PICKER_RESULT);
        }
    };
    this.cordova.getThreadPool().execute(worker);
}
 
Example 13
Source File: UploadNewsFeedActivity.java    From Nimbus with GNU General Public License v3.0 5 votes vote down vote up
private void createChooser() {
    if(ContextCompat.checkSelfPermission(UploadNewsFeedActivity.this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)== PackageManager.PERMISSION_DENIED){

        if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M){
            requestPermissions(new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 121);
        }

        return;

    }

    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    intent.setType("image/*");
    startActivityForResult(Intent.createChooser(intent, "CHOOSE PHOTO"), PICK_IMAGE_REQUEST);
}
 
Example 14
Source File: NewPostActivity.java    From friendlypix-android with Apache License 2.0 5 votes vote down vote up
@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;
    }

    // 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,
            getString(R.string.picture_chooser_title));
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new
            Parcelable[cameraIntents.size()]));
    startActivityForResult(chooserIntent, TC_PICK_IMAGE);
}
 
Example 15
Source File: PickImageActivity.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mProgressDialog = new ProgressDialog(PickImageActivity.this);
    mProgressDialog.setMessage(getString(R.string.lc_please_wait));
    mProgressDialog.setIndeterminate(true);
    mProgressDialog.setCancelable(false);

    Intent startIntent = getIntent();
    if (savedInstanceState == null && startIntent != null) {
        mCropImage = startIntent.getBooleanExtra(EXTRA_CROP, false);
        mScale = startIntent.getBooleanExtra(EXTRA_SCALE, false);
        mScaleUp = startIntent.getBooleanExtra(EXTRA_SCALE_UP, false);
        if (startIntent.hasExtra(EXTRA_ASPECT_X) || startIntent.hasExtra(EXTRA_ASPECT_Y)) {
            mAspectSize = new Point(startIntent.getIntExtra(EXTRA_ASPECT_X, 0),
                    startIntent.getIntExtra(EXTRA_ASPECT_Y, 0));
        }
        if (startIntent.hasExtra(EXTRA_OUTPUT_X) || startIntent.hasExtra(EXTRA_OUTPUT_Y)) {
            mOutputSize = new Point(startIntent.getIntExtra(EXTRA_OUTPUT_X, 0),
                    startIntent.getIntExtra(EXTRA_OUTPUT_Y, 0));
        }
        if (startIntent.hasExtra(EXTRA_SPOTLIGHT_X) || startIntent.hasExtra(EXTRA_SPOTLIGHT_Y)) {
            mSpotlightSize = new Point(startIntent.getIntExtra(EXTRA_SPOTLIGHT_X, 0),
                    startIntent.getIntExtra(EXTRA_SPOTLIGHT_Y, 0));
        }

        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");
        startActivityForResult(Intent.createChooser(intent, getString(R.string.imgpick_dialog_title)),
                REQ_PICK_IMAGE);
    } else {
        finish();
    }
}
 
Example 16
Source File: BlurActivity.java    From Blur with Apache License 2.0 4 votes vote down vote up
public static void chooseGalleryImage(Activity activity, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_PICK, null);
    intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            "image/*");
    activity.startActivityForResult(intent, requestCode);
}
 
Example 17
Source File: MainActivity.java    From MagicLight-Controller with Apache License 2.0 4 votes vote down vote up
@OnClick(R.id.palette)
public void btn_Palette(View v) {
    Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(intent, RESULT_LOAD_IMAGE);
}
 
Example 18
Source File: ExampleSocialActivity.java    From android-profile with Apache License 2.0 4 votes vote down vote up
private void chooseImageFile() {
    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, SELECT_PHOTO_ACTION);
}
 
Example 19
Source File: UploadFragment.java    From abelana with Apache License 2.0 4 votes vote down vote up
/**
 * Starts the select photo intent.
 */
private void selectPhoto() {
    Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
    photoPickerIntent.setType("image/*");
    startActivityForResult(photoPickerIntent, SELECT_PHOTO_INTENT);
}
 
Example 20
Source File: PhotoSelector.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Activity调用系统相册
 *
 * @param activity
 * @param requestCode
 */
public void requestPhotoPick(Activity activity, int requestCode) {
    Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    activity.startActivityForResult(intent, requestCode);
}