我已经使用以下代码从画廊中挑选视频,直到棉花糖工作正常但它似乎不适合oreo似乎
try {
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
i.setType("image/* video/*");
startActivityForResult(i, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);
} catch (Exception e) {
e.printStackTrace();
}
我也试过这个但是没有用
try {
Intent i = new Intent(Intent.ACTION_GET_CONTENT,
android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
i.setType("*/*");
startActivityForResult(i, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);
} catch (Exception e) {
e.printStackTrace();
}
答案 0 :(得分:0)
试试这个..
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Video"),REQUEST_TAKE_GALLERY_VIDEO);
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_TAKE_GALLERY_VIDEO) {
Uri selectedImageUri = data.getData();
// OI FILE Manager
filemanagerstring = selectedImageUri.getPath();
// MEDIA GALLERY
selectedImagePath = getPath(selectedImageUri);
if (selectedImagePath != null) {
Intent intent = new Intent(HomeActivity.this,
VideoplayAvtivity.class);
intent.putExtra("path", selectedImagePath);
startActivity(intent);
}
}
}
}
// UPDATED!
public String getPath(Uri uri) {
String[] projection = { MediaStore.Video.Media.DATA };
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
if (cursor != null) {
// HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
// THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else
return null;
}