ShoutSocial / share_handler

A plugin to facilitate receiving and handling share intents
41 stars 39 forks source link

[Android] Some cloud videos throw FileNotFoundException. #75

Open hazzo opened 10 months ago

hazzo commented 10 months ago

When sharing content from Google Photos, images seem to work okey. But some video files throw the following exception.

W/Parcel: Expecting binder but got null!
D/EGL_emulation: app_time_stats: avg=3703.46ms min=19.50ms max=7387.42ms count=2
I/FileDirectory: File name: VID_20160330_192102.mp4
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.shoutsocial.share_handler_android_example, PID: 1632
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:558)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
     Caused by: java.io.FileNotFoundException
        at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:151)
        at android.content.ContentProviderProxy.openTypedAssetFile(ContentProviderNative.java:780)
        at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:2027)
        at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1842)
        at android.content.ContentResolver.openInputStream(ContentResolver.java:1518)
        at com.shoutsocial.share_handler.FileDirectory.getDataColumn(FileDirectory.kt:122)
        at com.shoutsocial.share_handler.FileDirectory.getAbsolutePath(FileDirectory.kt:73)
        at com.shoutsocial.share_handler.ShareHandlerPlugin.attachmentForUri(ShareHandlerPlugin.kt:212)
        at com.shoutsocial.share_handler.ShareHandlerPlugin.attachmentsFromIntent(ShareHandlerPlugin.kt:198)
        at com.shoutsocial.share_handler.ShareHandlerPlugin.handleIntent(ShareHandlerPlugin.kt:162)
        at com.shoutsocial.share_handler.ShareHandlerPlugin.onNewIntent(ShareHandlerPlugin.kt:150)
        at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onNewIntent(FlutterEngineConnectionRegistry.java:838)
        at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onNewIntent(FlutterEngineConnectionRegistry.java:450)
        at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onNewIntent(FlutterActivityAndFragmentDelegate.java:838)
        at io.flutter.embedding.android.FlutterActivity.onNewIntent(FlutterActivity.java:937)
        at android.app.Activity.performNewIntent(Activity.java:8321)
        at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1517)
        at android.app.Instrumentation.callActivityOnNewIntent(Instrumentation.java:1530)
        at android.app.ActivityThread.deliverNewIntents(ActivityThread.java:3822)
        at android.app.ActivityThread.handleNewIntent(ActivityThread.java:3829)
        at android.app.servertransaction.NewIntentItem.execute(NewIntentItem.java:56)
        at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
        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:2307)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7872)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
Disconnected from the target VM, address: 'localhost:56951', transport: 'socket'
I/Process: Sending signal. PID: 1632 SIG: 9

I debugged the android code but It seems to be crashing in the following code in the FileDirectory.kt file.

context.contentResolver.openInputStream(uri)?.use { input ->
                FileOutputStream(targetFile).use { fileOut ->
                    input.copyTo(fileOut)
                }
            }

That's a Java IO method, so don't really know what it's happening. My theory it's that some large videos are stored in the cloud and not in the device and not found.