0

I let users select an image from gallery, after that I show this in an imageview. It works on my phone and in nexus 5 emulator but not working in nexus 5x. Any ideas?

case R.id.imageToUpload:
                Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
                break;

and

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && data != null) {
        Uri selectedImage = data.getData();
        imageToUpload.setImageURI(selectedImage);
    }
}

why this code is not working on nexus 5x? (the image is not showing after user selected it)

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
RGS
  • 4,062
  • 4
  • 31
  • 67
  • 1
    https://stackoverflow.com/questions/32635704/android-permission-doesnt-work-even-if-i-have-declared-it (and, also, do not use `setImageURI()`, use [an image-loading library](https://android-arsenal.com/tag/46) instead, so you do not freeze your UI while loading the image) – CommonsWare May 09 '17 at 19:20
  • Maybe they are running different OS. Are you getting any onActivityResult() for the Nexus 5X? – Doron Yakovlev Golani May 09 '17 at 19:27
  • thank you @CommonsWare I'll check it! – RGS May 09 '17 at 19:33
  • @DoronYakovlev-Golani they are. nexus 5x is running android 6. No, I'm not getting any result for nexus 5x. – RGS May 09 '17 at 19:34

1 Answers1

-1

this solved my problem: I added it inside case.

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
            if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
                String[] permissions = {Manifest.permission.READ_EXTERNAL_STORAGE};
                requestPermissions(permissions, PERMISSION_REQUEST_CODE);
            }
        }
RGS
  • 4,062
  • 4
  • 31
  • 67