Picking a image from Camera works, but not from the Gallary [VIDEO DEMO]

后端 未结 1 1834
盖世英雄少女心
盖世英雄少女心 2021-01-22 20:39

I have followed some examples on SO of how to retrive an image from Camera or Gallary. The camera part works, but the gallary part dosn\'t. The code seems very diffuclt to under

相关标签:
1条回答
  • 2021-01-22 21:19

    Use below code to pick image from Gallery.

       Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
       intent.setType("image/*");
       //Here PICK_FROM_GALLERY is a requestCode
       startActivityForResult(intent, PICK_FROM_GALLERY);
    

    In onActivityResult():

     if (resultCode == Activity.RESULT_OK && requestCode == PICK_FROM_GALLERY) {
          if (data.getData() != null) {
               mImageUri = data.getData();
          } else {
              //showing toast when unable to capture the image
               Debug.toastValid(context, "Unable to upload Image Please Try again ...");
          }
    }
    
    0 讨论(0)
提交回复
热议问题