ahmadreza gh
ahmadreza gh

Reputation: 1

android studio AVD not showing the MediaStore.ACTION_PICK_IMAGES

This is my code

public static void ChooseVideo(ActivityResultLauncher<Intent> resultLauncher) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && SdkExtensions.getExtensionVersion(Build.VERSION_CODES.R) >= 2) {
            Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
            intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"video/*"});
            resultLauncher.launch(intent);
        }else {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("video/*");
            resultLauncher.launch(intent);
        }
        Log.i("FilesUtil", "loading video");
    }

my problem is in this part

Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"video/*"});
resultLauncher.launch(intent);

This section should trigger the media picker on Android 13 and above in my application, as shown in this image: Android 13 image

It functions correctly on Android 13 AVD and real devices running Android 13 and above.

The issue is that it doesn't function on Android 14 and 15 in the Android Studio AVD.it doesn't display any media to select: Android 14 and 15 AVD image

It works fine in real devices but not working in AVD

I tried out these versions AVD ver image

The videos I imported to the device are only visible in the Files app and do not appear in the gallery app at all. However, I attempted to record a video using the AVD camera, and the recorded video was fine; both my app and other apps can access it.

Upvotes: 0

Views: 44

Answers (2)

ahmadreza gh
ahmadreza gh

Reputation: 1

I upgraded my Android Studio, and it only resolved the issue in Android 14,15 (Google Play). However, the other versions are still not functioning.

Upvotes: 0

VishV
VishV

Reputation: 367

Try this PickVisualMediaRequest in ActivityResultLauncher,

private ActivityResultLauncher<PickVisualMediaRequest> pickMultipleMedia;

private void ChooseVideo() {
    pickMultipleMedia.launch(new PickVisualMediaRequest.Builder()
            .setMediaType(ActivityResultContracts.PickVisualMedia.VideoOnly.INSTANCE)
            .build());
}
pickMultipleMedia = registerForActivityResult(
                new ActivityResultContracts.PickMultipleVisualMedia(), new 
    ActivityResultCallback<List<Uri>>(){
    @Override
    public void onActivityResult(List<Uri> uris) {
        if (!uris.isEmpty()) {
            Log.d(TAG, "Number of items selected: " + uris.size());
        } else {
            Log.d(TAG, "No media selected");
        }
    }
});

Upvotes: 0

Related Questions