我想从图库中上传视频。我使用startActivityForResualt
并从
onActivityResualt
然后将uri传递到获取真实路径的方法,这是我的方法:
private static String getRealPath(Context context, Uri uri) {
final String column = "_data";
String[] proj = {MediaStore.Video.Media.DATA};
try (Cursor cursor = context.getContentResolver().query(uri, proj, null, null, null)) {
if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(index);
}
}
return null;
}
因此它适用于除Android 10以外的所有API。>在android 10中,它会打开视频选择器活动,我可以选择一个视频,但是当我选择视频时,它想回到主要活动崩溃并显示此错误!:
java.lang.IllegalArgumentException:无效的列纬度
这是我的日志:
2020-05-26 20:39:53.736 6048-6705/com.google.android.apps.photos E/DatabaseUtils: Writing exception to parcel java.lang.IllegalArgumentException: Invalid column latitude at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140) at android.content.ContentProviderProxy.query(ContentProviderNative.java:423) at android.content.ContentResolver.query(ContentResolver.java:944) at android.content.ContentResolver.query(ContentResolver.java:880) at android.content.ContentResolver.query(ContentResolver.java:836) at _1194.a(PG:97) at com.google.android.apps.photos.contentprovider.impl.MediaContentProvider.a(PG:32) at alca.query(PG:34) at android.content.ContentProvider.query(ContentProvider.java:1214) at alca.query(PG:10) at android.content.ContentProvider.query(ContentProvider.java:1307) at android.content.ContentProvider$Transport.query(ContentProvider.java:267) at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:104) at android.os.Binder.execTransactInternal(Binder.java:1021) at android.os.Binder.execTransact(Binder.java:994) 2020-05-26 20:39:53.755 7315-7315/diar.neo.mainactivvity E/AndroidRuntime: FATAL EXCEPTION: main Process: diar.neo.mainactivvity, PID: 7315 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/-1/2/content://media/external/video/media/30/ORIGINAL/NONE/893152725 flg=0x1 clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/-1/2/content%3A%2F%2Fmedia%2Fexternal%2Fvideo%2Fmedia%2F30/ORIGINAL/NONE/893152725} }} to activity {diar.neo.mainactivvity/diar.neo.mainactivvity.MainActivity}: java.lang.IllegalArgumentException: Invalid column latitude at android.app.ActivityThread.deliverResults(ActivityThread.java:4845) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886) at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
我该怎么办?
我想从图库中上传视频。我使用startActivityForResualt并从onActivityResualt获取数据,然后将uri传递给获取真实路径的方法,这是我的方法:private static String ...
我通常使用此文件从库中获取所有内容的完整路径。