0

I am having trouble trying to select photos on Android. I am using the code below to launch the activity.

var intent = new Intent ();
intent.SetType ("video/*");
intent.SetAction (Intent.ActionGetContent);
intent.PutExtra (MediaStore.ExtraVideoQuality, 0);
intent.PutExtra (MediaStore.ExtraDurationLimit, Globals.VideoMaxDuration);
this.StartActivityForResult (Intent.CreateChooser (intent, "Select video"), 200);

Then in the OnActivityResult callback I use the following code to get the URI of the data.

if (resultCode == Result.Ok && data.Data != null)
{
    String[] proj = { MediaStore.Images.Media.InterfaceConsts.Data };
    ICursor cursor = this.ContentResolver.Query(data.Data, proj, null, null, null);
    int colIndex = cursor.GetColumnIndexOrThrow (MediaStore.Video.Media.InterfaceConsts.Data);
    cursor.MoveToFirst ();
    vid = cursor.GetString(colIndex);

    // do stuff with vid
}

This works great when choosing videos from the "gallery" option, but when I try to select a video from the "recent" or "download" sections of the chooser the VID is always null.

Does anyone have any idea how to get video data from the video chooser intent reliably? Also, the code is in C# as this is an Monotouch (Xamarin) app, but I have created a test app in native Android and have the exact same issue.

Thanks!

miken.mkndev
  • 1,821
  • 3
  • 25
  • 39

1 Answers1

2

Basically this code is from this post. Please refer this link for more information or how to get path from uri?.

To check if it is download document or not you have to use following code.

/**
 * @param uri The Uri to check.
 * @return Whether the Uri authority is DownloadsProvider.
 */
public static boolean isDownloadsDocument(Uri uri) {
    return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}

/**
 * @param uri The Uri to check.
 * @return Whether the Uri authority is MediaProvider.
 */
public static boolean isMediaDocument(Uri uri) {
    return "com.android.providers.media.documents".equals(uri.getAuthority());
}
Community
  • 1
  • 1
shreyash mashru
  • 301
  • 2
  • 9