这周我开发了应用程序Video Recorder,需要插入缩略图,如果单击缩略图则选择/选择视频
public class VideoRecorderFragment extends Fragment implements View.OnClickListener, ActivityCompat.OnRequestPermissionsResultCallback {
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_TAKE_GALLERY_VIDEO) {
Log.i(TAG,"requestCode == REQUEST_TAKE_GALLERY_VIDEO:"+(requestCode == REQUEST_TAKE_GALLERY_VIDEO));
Uri selectedMediaUri = data.getData();
Log.i(TAG,"selectedMediaUri:"+selectedMediaUri);
String selectedMediaPath = getPath(selectedMediaUri);
Log.i(TAG,"selectedMediaPath:"+selectedMediaPath);
Intent intent = new Intent();
intent.setClass(getActivity(), VideoEditViewControllerActivity.class);
intent.putExtra("currentVideoPath", selectedMediaPath);
startActivityForResult(intent, 01);
Log.i(TAG, "onActivityResult...end");
}
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Video.Media.DATA };
Cursor cursor = getActivity().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;
}}
}
选择任何视频然后回调到onActivityResult,在onActivityResult调用startActivityForResult中出现黑页
public boolean onOptionsItemSelected(MenuItem item)
不知道为什么?如何在onActivityResult中启动startActivityForResult?