I want to make "Select Image From Gallery or Camera". You can say there are a lot of library on the internet for this. I know but I have an another problem. I can make both select images from gallery and camera capture. But camera resulted in image rotated after the capture. I solved the problem with rotating. Now I want to show an imageview that image. Some devices didn't show the image in imageview(Samsung Note 3 Android version 5.0). I made a lot of searches and find advice. I applied the recommendations. But I can not solve that problem. Please help me.
4 Answers
Same problem happened with me. I am not able to see captured images on Samsung and MI devices mostly.
By using this library I have solved my issue.

- 781
- 7
- 28
It might be too late for the answer but I hope it will help others.
Instead of using external libraries it is better to create your own layout and use it.
Step 1: Create layout for options.
image_choose_bottom_sheet.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvClickImageText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_vector_camera_icon"
android:gravity="center"
android:padding="10dp"
android:text="Take Photo"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/tvChooseGalleryText"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvChooseGalleryText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="@drawable/ic_vector_gallery_icon"
android:gravity="center"
android:padding="10dp"
android:text="Choose Image"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/tvClickImageText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/tvClickImageText"
app:layout_constraintTop_toTopOf="@+id/tvClickImageText" />
</android.support.constraint.ConstraintLayout>
</layout>
Step 2: Create a BottomSheetDialog where you can inflate the layout and configure it.
DialogImageChooser.java
public class DialogImageChooser extends BottomSheetDialogFragment {
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
View view;
// DialogNationalitySelectionBinding mBinding;
Context mContext;
private bottomSheetListener mListener;
TextView tvClickImageText, tvChooseGalleryText;
public DialogImageChooser() {
}
@SuppressLint("ValidFragment")
public DialogImageChooser(@NonNull Context context, bottomSheetListener mListener) {
this.mListener = mListener;
mContext = context;
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
view = inflater.inflate(R.layout.image_choose_bottom_sheet, container, false);
tvClickImageText = view.findViewById(R.id.tvClickImageText);
tvChooseGalleryText = view.findViewById(R.id.tvChooseGalleryText);
tvClickImageText.setOnClickListener(v -> {
mListener.onCardClicked("camera");
dismiss();
});
tvChooseGalleryText.setOnClickListener(v -> {
mListener.onCardClicked("gallery");
dismiss();
});
return view;
}
public interface bottomSheetListener {
void onCardClicked(String option);
}
}
Step 3: Finally in the Activity just make a call for Dialog.
YourActivity.java
ivItemImage.setOnClickListener(v -> {
new DialogImageChooser(YourActivity.this, selectedOption -> {
if (selectedOption.equalsIgnoreCase("camera")) {
TakePictureIntent(CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
} else if (selectedOption.equalsIgnoreCase("gallery")) {
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, SELECT_IMAGE);
}
}).show(getSupportFragmentManager(), "add_photo_dialog");
});
That's it. Custom "Select Image From Gallery or Camera Dialog" is integrated without use of any external libraries.

- 83
- 1
- 8
On which version of android image is not shown in imageview
If it is Android N you give provider in Manifest
add this code to your manifest
<application
android:name=".MyApplication"
android:theme="@style/MyAppTheme">
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
provider_paths.xml
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
provider_paths is in resource-xml folder

- 141
- 1
- 9
-
Samsung Note 3, Android version 5.0 – Andev Jul 14 '17 at 08:53
-
1This does not correspond to the question, it serves to share files of your application, not to select an image – from56 Jul 14 '17 at 09:19
So that the user can choose an image of the gallery do this in your Activity :
The method that shows the gallery :
private static final int SELECT_PHOTO = 1;
public void showGallery() {
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, SELECT_PHOTO);
}
And this will be called when the user picks one image, the image path, if any, will be stored in imagePath
private String imagePath;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
imagePath = "";
if (requestCode == SELECT_PHOTO && resultCode == RESULT_OK) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
imagePath = cursor.getString(columnIndex);
cursor.close();
//Here you can call a method that loads the image and
//show it in an ImageView
}
}
}
you will need a permission in your manifest :
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

- 3,976
- 2
- 13
- 23