0

I'm trying to take a picture from the gallery in the fragment, although it finds the path, I get a null pointer error while setting the bitmap, how can I edit this code

@Override
        public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            if (requestCode == 777 && resultCode == getActivity().RESULT_OK && data != null) {
                Uri path = data.getData();
                try {
                    bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), path);
                    imageView.setImageBitmap(bitmap);
                    imageView.setVisibility(View.VISIBLE);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

1 Answers1

0

To get data from MediaStore. You have to get permission.

If you're targeting API version 28 or lower. You have to set this in your AndroidManifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Kyle
  • 154
  • 3
  • 9