joutvhu / open_file_plus

A plug-in that can call native APP to open files with string result in flutter, support iOS(UTI) / android(intent) / PC(ffi) / web(dart:html)
https://pub.dev/packages/open_file_plus
BSD 3-Clause "New" or "Revised" License
5 stars 11 forks source link

Crash when trying to open apk #2

Closed Lukas-Heiligenbrunner closed 1 year ago

Lukas-Heiligenbrunner commented 1 year ago

Hey,

your package causes an application crash when trying to open a file with apk extension. Maybe one should delete void openApkFile() or have the same behaviour as with other file extensions.

kind regards lukas

E/AndroidRuntime(25770): java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=33432, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.example.flutter_rust_bridge_template/com.example.flutter_rust_bridge_template.MainActivity}: java.lang.SecurityException: Need to declare android.permission.REQUEST_INSTALL_PACKAGES to call this api
E/AndroidRuntime(25770):    at android.app.ActivityThread.deliverResults(ActivityThread.java:6068)
E/AndroidRuntime(25770):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:6107)
E/AndroidRuntime(25770):    at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
E/AndroidRuntime(25770):    at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
E/AndroidRuntime(25770):    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(25770):    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(25770):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2498)
E/AndroidRuntime(25770):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(25770):    at android.os.Looper.loopOnce(Looper.java:226)
E/AndroidRuntime(25770):    at android.os.Looper.loop(Looper.java:313)
E/AndroidRuntime(25770):    at android.app.ActivityThread.main(ActivityThread.java:8855)
E/AndroidRuntime(25770):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(25770):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/AndroidRuntime(25770):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
E/AndroidRuntime(25770): Caused by: java.lang.SecurityException: Need to declare android.permission.REQUEST_INSTALL_PACKAGES to call this api
E/AndroidRuntime(25770):    at android.os.Parcel.createExceptionOrNull(Parcel.java:2438)
E/AndroidRuntime(25770):    at android.os.Parcel.createException(Parcel.java:2422)
E/AndroidRuntime(25770):    at android.os.Parcel.readException(Parcel.java:2405)
E/AndroidRuntime(25770):    at android.os.Parcel.readException(Parcel.java:2347)
E/AndroidRuntime(25770):    at android.content.pm.IPackageManager$Stub$Proxy.canRequestPackageInstalls(IPackageManager.java:9976)
E/AndroidRuntime(25770):    at android.app.ApplicationPackageManager.canRequestPackageInstalls(ApplicationPackageManager.java:3921)
E/AndroidRuntime(25770):    at com.joutvhu.openfile.OpenFilePlugin.canInstallApk(OpenFilePlugin.java:371)
E/AndroidRuntime(25770):    at com.joutvhu.openfile.OpenFilePlugin.openApkFile(OpenFilePlugin.java:353)
E/AndroidRuntime(25770):    at com.joutvhu.openfile.OpenFilePlugin.onRequestPermissionsResult(OpenFilePlugin.java:391)
E/AndroidRuntime(25770):    at io.flutter.embedding.engine.FlutterEngineConnectionRegistry$FlutterEngineActivityPluginBinding.onRequestPermissionsResult(FlutterEngineConnectionRegistry.java:777)
E/AndroidRuntime(25770):    at io.flutter.embedding.engine.FlutterEngineConnectionRegistry.onRequestPermissionsResult(FlutterEngineConnectionRegistry.java:409)
E/AndroidRuntime(25770):    at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onRequestPermissionsResult(FlutterActivityAndFragmentDelegate.java:757)
E/AndroidRuntime(25770):    at io.flutter.embedding.android.FlutterActivity.onRequestPermissionsResult(FlutterActivity.java:748)
E/AndroidRuntime(25770):    at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8861)
E/AndroidRuntime(25770):    at android.app.Activity.dispatchActivityResult(Activity.java:8691)
E/AndroidRuntime(25770):    at android.app.ActivityThread.deliverResults(ActivityThread.java:6061)
E/AndroidRuntime(25770):    ... 13 more
E/AndroidRuntime(25770): Caused by: android.os.RemoteException: Remote stack trace:
E/AndroidRuntime(25770):    at com.android.server.pm.PackageManagerService.canRequestPackageInstallsInternal(PackageManagerService.java:35336)
E/AndroidRuntime(25770):    at com.android.server.pm.PackageManagerService.canRequestPackageInstalls(PackageManagerService.java:35305)
E/AndroidRuntime(25770):    at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:4581)
E/AndroidRuntime(25770):    at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:10407)
E/AndroidRuntime(25770):    at android.os.Binder.execTransactInternal(Binder.java:1215)
E/AndroidRuntime(25770): 
I/Process (25770): Sending signal. PID: 25770 SIG: 9
Lost connection to device.
joutvhu commented 1 year ago

The issues has been fixed by version 3.4.0. https://github.com/joutvhu/open_file_plus/commit/3afd6e177063e1360c26e2e3a4d7f75f5c4d5405

However, to open the APK file, you need to add <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/> to your AndroidManifest.xml file.

Lukas-Heiligenbrunner commented 1 year ago

Thanks a lot!