带有FileProvider的Samsung android 5上的视频捕获崩溃 [英] Video capturing crash on Samsung android 5 with FileProvider

查看:114
本文介绍了带有FileProvider的Samsung android 5上的视频捕获崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

型号:三星SM-G900F(Android 5.0)

Model: Samsung SM-G900F (Android 5.0)

启动摄像头的代码:

        File file = new File(getExternalFilesDir(null),"video.mp4");

        Uri uri = FileProvider.getUriForFile(this, "example.com.myapplication.fileprovider", file);

        final Intent takePictureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION| Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
            final List<ResolveInfo> resInfoList =
                    getPackageManager()
                            .queryIntentActivities(takePictureIntent, PackageManager.MATCH_DEFAULT_ONLY);

            for (final ResolveInfo resolveInfo : resInfoList) {
                final String packageName = resolveInfo.activityInfo.packageName;
                grantUriPermission(packageName, uri,
                                   Intent.FLAG_GRANT_WRITE_URI_PERMISSION |
                                   Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }
        }
        startActivityForResult(takePictureIntent, 42);

日志:

11-03 11:40:00.073 30377-30377/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   Process: com.sec.android.app.camera, PID: 30377
                                                   java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2002, result=-1, data=Intent { act=inline-data dat=content://example.com.myapplication.fileprovider/external/Android/data/example.com.myapplication/files/video.mp4 (has extras) }} to activity {com.sec.android.app.camera/com.sec.android.app.camera.Camcorder}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
                                                       at android.app.ActivityThread.deliverResults(ActivityThread.java:3974)
                                                       at android.app.ActivityThread.handleSendResult(ActivityThread.java:4017)
                                                       at android.app.ActivityThread.access$1400(ActivityThread.java:172)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1471)
                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                       at android.os.Looper.loop(Looper.java:145)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5832)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
                                                    Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.  Make sure the Cursor is initialized correctly before accessing data from it.
                                                       at android.database.CursorWindow.nativeGetLong(Native Method)
                                                       at android.database.CursorWindow.getLong(CursorWindow.java:524)
                                                       at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java:75)
                                                       at android.database.CursorWrapper.getLong(CursorWrapper.java:106)
                                                       at com.sec.android.app.camera.Camera.onActivityResult(Camera.java:6956)
                                                       at android.app.Activity.dispatchActivityResult(Activity.java:6475)
                                                       at android.app.ActivityThread.deliverResults(ActivityThread.java:3970)
                                                       at android.app.ActivityThread.handleSendResult(ActivityThread.java:4017) 
                                                       at android.app.ActivityThread.access$1400(ActivityThread.java:172) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1471) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                       at android.os.Looper.loop(Looper.java:145) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5832) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at java.lang.reflect.Method.invoke(Method.java:372) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

看起来视频捕获仅适用于文件uri,不适用于内容uri.

  Looks like video capturing works only with file uri and doesn't work with content uri.

您有同样的问题吗?您能提出一些一般的解决方案吗?

Do you have the same issues? Could you suggest some general solution?

推荐答案

这对我有帮助:

    Uri uri;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", f);
    } else {
        uri = Uri.fromFile(f);
    }
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);

这篇关于带有FileProvider的Samsung android 5上的视频捕获崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆