无法从图库棉花糖设备中选取视频

时间:2019-08-08 05:32:37

标签: java

当我要使用棉花糖设备时,视频拾取中的光标变为空

Android Studio 3.4.2

public void cv_video(View view) {

       Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
       intent.setType("video/*");
       String[] mimeTypes = {"video/mp4"};
       intent.putExtra(Intent.EXTRA_MIME_TYPES,mimeTypes);
       startActivityForResult(intent,REQUEST_TAKE_GALLERY_VIDEO);
   }
@Override
   protected void onActivityResult(int requestCode,int resultCode,@Nullable Intent data) {
       // Result code is RESULT_OK only if the user selects an Image
       if (resultCode == Activity.RESULT_OK)

            if (requestCode == REQUEST_TAKE_GALLERY_VIDEO) {

               Uri selectedImage = data.getData();
               String[] filePath = { MediaStore.Video.Media.DATA };
               Cursor c = getContentResolver().query(selectedImage, filePath,
                       null, null, null);
               c.moveToFirst();
               int columnIndex = c.getColumnIndex(filePath[0]);
               String videoPath = c.getString(columnIndex);
               c.close();

               Intent intent = new Intent(this,VideoEdit.class);
               intent.putExtra("videoPath",videoPath);
               startActivity(intent);


           }
   }

例外

Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'int android.database.Cursor.getColumnIndex(java.lang.String)' on a null object reference

0 个答案:

没有答案