0

Hi I have used below code to pick video from gallery

Intent intent = new Intent();
  intent.setType("video/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
             intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent = Intent.createChooser(intent, context.getString(R.string.choose_video));
            startActivity(activity, fragment, intent, REQUEST_VIDEO_FROM_GALLERY);

 private static void startActivity(Activity activity, Fragment fragment, Intent intent, int requestCode) {
        if (fragment != null) {
            fragment.startActivityForResult(intent, requestCode);
        } else {
            activity.startActivityForResult(intent, requestCode);
        }
    }

But its not only showing the local video's like in WhatsApp Messenger, when opening gallery. I'm in need to restrict to show only local video while opening gallery like in WhatsApp Messenger. Please suggest me some idea.

I have also tried EXTRA_LOCAL_ONLY only like in below mentioned link. It shows local videos, but it also shows other documents.

Android : Why Intent.EXTRA_LOCAL_ONLY shows Google Photos

Can any one please suggest me an idea to show the local video when picking video from gallery using intent? Thanks in advance.

Community
  • 1
  • 1
Sangeetha
  • 496
  • 1
  • 7
  • 25

1 Answers1

1

There is no way to request local-only content using ACTION_GET_CONTENT. EXTRA_LOCAL_ONLY is for ACTION_OPEN_DOCUMENT, and even there it is a request, not a demand.

EXTRA_LOCAL_ONLY is now documented for use with ACTION_GET_CONTENT. However, there is no guarantee that all ACTION_GET_CONTENT implementations will honor it.

You are welcome to query the MediaStore for videos directly and render your own selection UI. AFAIK, MediaStore should only contain videos that are available on the device itself.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I agree with you that it is only a request, but according to documentation for `ACTION_GET_CONTENT`, callers can optionally specify `EXTRA_LOCAL_ONLY` to request that the launched content chooser only returns results representing data that is locally available on the device. https://developer.android.com/reference/android/content/Intent?hl=en#ACTION_GET_CONTENT – Misagh Emamverdi Sep 30 '20 at 12:18
  • 1
    @MisaghEmamverdi: They may have updated the documentation in the four years since I wrote this answer. Thanks for the clarification! – CommonsWare Sep 30 '20 at 12:21