Reputation: 1
1 I want to pick image from a selected item (in that case, it is R.id.status ) from bottom navigation view and show the image in a recyclerview named statusList. How can I do this if startActivityForResult deprecated ?
Upvotes: -2
Views: 66
Reputation: 237
First of all you need to declare private ActivityResultLauncher<String> imagePickerLauncher;
After that here's how you launch the image picker
// Launch the image picker
imagePickerLauncher.launch("image/*");
And to retrieve the result you copy this code
// Initialize the imagePickerLauncher
imagePickerLauncher = registerForActivityResult(new
ActivityResultContracts.GetContent(), uri -> {
if (uri != null) {
// Do something with the selected image URI
// For example, add it to the RecyclerView adapter
}
});
Upvotes: 0