I need so that I can add an image from the gallery to the ImageView. But for some reason I can add it on the emulator, but when I run the application on a real device, the image is not added, it just appears empty.
ivEditProfil.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); photoPickerIntent.setType("image/*"); startActivityForResult(photoPickerIntent, GALLERY_REQUEST); } }); @Override protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); switch (requestCode) { case GALLERY_REQUEST: if (resultCode == RESULT_OK) { try { final Uri imageUri = imageReturnedIntent.getData(); final InputStream imageStream = getContentResolver().openInputStream(imageUri); final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream); ivEditProfil.setImageBitmap(selectedImage); } catch (FileNotFoundException e) { e.printStackTrace(); } } } }
<application>tag in the manifest file:<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />- Alex Kisel