moberwasserlechner / capacitor-filesharer

Capacitor plugin to download and share files for the Web, Android and iOS! Stop the war in Ukraine!
MIT License
82 stars 20 forks source link

Capacitor 3.0 support #29

Closed AshleyMedway closed 2 years ago

AshleyMedway commented 3 years ago

I've been able to test Android but haven't been able to test iOS yet. Related issue: #28

akram-globalizeme commented 3 years ago

@AshleyMedway Thanks man! This is working perfectly on iOS đź‘Ś

7freaks-otte commented 3 years ago

Works for me on iOS too. Would love to see that merged into the official repo @moberwasserlechner - thanks @AshleyMedway

moberwasserlechner commented 2 years ago

@7freaks-otte I merge the change and improved it with the learnings I made on another plugin upgrade I made recently. Unfortunately I have currently no app to test it with. I could release it though but you guys would need to test it. 🤷‍♂️

mishrasatyam commented 2 years ago

Please release it , I will test on android and post the results!

joel-daros commented 2 years ago

I'm testing the master branch (for Capacitor 3) my Ionic Android app crash.

Steps:

  1. Chose a file to share inside app.
  2. Shared menu is showed.
  3. I don't choose any option to share, just try to close the shared menu, swipe it down or click it outside.
  4. App crashs.

This is my MainActivity.java Repair that import com.byteowls.capacitor.filesharer.FileSharerPlugin; get byteowls in red, with message Cannot resolve symbol 'byteowls' image

Let me known if is there any additional log to provide.

onic:

   Ionic CLI                     : 6.17.0 (/Users/xxx/.nvm/versions/node/v14.17.3/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.6.14
   @angular-devkit/build-angular : 12.2.3
   @angular-devkit/schematics    : 12.2.3
   @angular/cli                  : 12.2.3
   @ionic/angular-toolkit        : 4.0.0

Capacitor:

   Capacitor CLI      : 3.2.0
   @capacitor/android : 3.2.0
   @capacitor/core    : 3.2.0
   @capacitor/ios     : not installed

Utility:

   cordova-res : 0.15.3
   native-run  : 1.4.0

System:

   NodeJS : v14.17.3 (/Users/xxx/.nvm/versions/node/v14.17.3/bin/node)
   npm    : 7.21.0
   OS     : macOS Big Sur
AshleyMedway commented 2 years ago

@MrSparklle have you done npx cap sync and npx cap copy?

also in the V3 version you don’t need to register the plugin in MainActivity. In V3 it can auto discover plugins like it does for iOS

joel-daros commented 2 years ago

@MrSparklle have you done npx cap sync and npx cap copy?

Sure, otherwise it will not even display the share menu.

EDIT: Solved the byteowls in red. Just clean and rebuild. But the app keeps crashing

also in the V3 version you don’t need to register the plugin in MainActivity. In V3 it can auto discover plugins like it does for iOS

Ok, removed all the code from MainActivity class. Rebuild the app, and get the same behavior. The app crashes.

Is there something else to add in Android native code? Maybe something inside the build.gradle or any other file? I only made that ones that are explain in the README.

AshleyMedway commented 2 years ago

Hmmm, there must be something else going on because the screenshot is a compile time error but what you’re describing it on runtime error. Do you have a screenshot of the runtime exception?

joel-daros commented 2 years ago

The compile error has been solved. I clean and rebuild the project. But the app keeps crashing.

my AndroidManifest.xml has these 2 entries:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

and App has granted permissions to read and write the external storage.

Below the runtime log:

2021-08-31 16:25:42.127 3431-3585/br.com.residencialalgarve V/Capacitor/Plugin: To native (Capacitor plugin): callbackId: 45144928, pluginId: FileSharer, methodName: share
2021-08-31 16:25:42.130 3431-3585/br.com.residencialalgarve V/Capacitor: callback: 45144928, pluginId: FileSharer, methodName: share, methodData: {"filename":"Algarve.Regras.Instalacao.Split.pdf","base64Data":"JVBERi0xLjMKJcTl8uXrp\/Og0MTGCjQgMCBvYmoKPDwgL0xlbmd0aCA1IDAgUiAvRmlsdGVyIC9GbGF0ZURlY29kZSA+PgpzdHJlYW0KeAGtXc2O3EhyvtdTlO31urSepkgWWazyrVeaXYwxHmmlHtuAx4fq6hpJA6mqp1stCDr6osNCA2MuA2P36rfxQ\/mLiC+SySSlJluDBppkZjIyMv4zMpP14\/xP8x\/n9x9cF\/Pd9TzXv+sdivKsrOxZbopyviqbbFPOd6\/mvz+b19YSl6qqsjzPUd9Us7NX8\/tnZ+W8mJ99P1\/8zb352Q\/zL8+0i0\/DO8kBpGzmZ7t5udRucSk2G8Be1\/OTslotu8D\/Y77427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Hg3a01xA7+6VPc3NKx4dU6x7Tt6n4kIOpLjVEGQh66gvnMycNjCR2kVhu+LLpQrLuFIkwDxcHwjLJSyli766Klw0\/\/9AemHGC\/IMel6lJyayEbMJnSBjHGL+bULN5HD5DjWR8yGxhO9pTS2D2G7jcS+oHTXVEze8JEnsw61QNUqCdIhly+BLEY7twtmYPIAKcLl54NeMEfDwwtIEi5sIA8IAbUIJIUOzTG\/Qz1mh\/j\/ks2sysoMmFUY\/HmtjecXlog1DFhlndqbxM0AvLY

    --------- beginning of system
2021-08-31 16:25:42.176 3431-3431/br.com.residencialalgarve D/Capacitor: App paused
2021-08-31 16:25:42.567 3431-3654/br.com.residencialalgarve E/DatabaseUtils: Writing exception to parcel
    java.lang.SecurityException: Permission Denial: reading com.byteowls.capacitor.filesharer.FileSharerProvider uri content://br.com.residencialalgarve.filesharer.fileprovider/capfilesharer/Algarve.Regras.Instalacao.Split.pdf from pid=4210, uid=1000 requires the provider be exported, or grantUriPermission()
        at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:729)
        at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:602)
        at android.content.ContentProvider$Transport.query(ContentProvider.java:231)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:104)
        at android.os.Binder.execTransactInternal(Binder.java:1021)
        at android.os.Binder.execTransact(Binder.java:994)
2021-08-31 16:26:00.022 3431-3431/br.com.residencialalgarve D/Capacitor: Unable to find a Capacitor plugin to handle requestCode, trying Cordova plugins 1721108809
2021-08-31 16:26:00.023 3431-3431/br.com.residencialalgarve D/AndroidRuntime: Shutting down VM

    --------- beginning of crash
2021-08-31 16:26:00.024 3431-3431/br.com.residencialalgarve E/AndroidRuntime: FATAL EXCEPTION: main
    Process: br.com.residencialalgarve, PID: 3431
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1721108809, result=0, data=null} to activity {br.com.residencialalgarve/br.com.residencialalgarve.MainActivity}: java.lang.IllegalArgumentException: method com.byteowls.capacitor.filesharer.FileSharerPlugin.callbackComplete argument 2 has type android.app.Instrumentation$ActivityResult, got androidx.activity.result.ActivityResult
        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)
     Caused by: java.lang.IllegalArgumentException: method com.byteowls.capacitor.filesharer.FileSharerPlugin.callbackComplete argument 2 has type android.app.Instrumentation$ActivityResult, got androidx.activity.result.ActivityResult
        at java.lang.reflect.Method.invoke(Native Method)
        at com.getcapacitor.Plugin.triggerActivityCallback(Plugin.java:154)
        at com.getcapacitor.Plugin.lambda$initializeActivityLaunchers$0$Plugin(Plugin.java:116)
        at com.getcapacitor.-$$Lambda$Plugin$9tit0PZrRMA5UA4Z_xqI4yDk4JY.onActivityResult(Unknown Source:6)
        at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:362)
        at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:322)
        at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:634)
        at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:164)
        at com.getcapacitor.BridgeActivity.onActivityResult(BridgeActivity.java:216)
        at android.app.Activity.dispatchActivityResult(Activity.java:8110)
        at android.app.ActivityThread.deliverResults(ActivityThread.java:4838)
        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) 
2021-08-31 16:26:00.461 3431-3473/br.com.residencialalgarve D/TransportRuntime.SQLiteEventStore: Storing event with priority=HIGHEST, name=FIREBASE_CRASHLYTICS_REPORT for destination cct
2021-08-31 16:26:00.480 3431-3473/br.com.residencialalgarve D/TransportRuntime.JobInfoScheduler: Upload for context TransportContext(cct, HIGHEST, MSRodHRwczovL2NyYXNobHl0aWNzcmVwb3J0cy1wYS5nb29nbGVhcGlzLmNvbS92MS9maXJlbG9nL2xlZ2FjeS9iYXRjaGxvZ1xBSXphU3lCcnBTWVQ0RkZMMDlyZUhKaTZIOUZZZGVpU25VVE92Mk0=) is already scheduled. Returning...
2021-08-31 16:26:00.517 3431-3431/br.com.residencialalgarve I/Process: Sending signal. PID: 3431 SIG: 9
joel-daros commented 2 years ago

There are some related issues in Stackoverflow that maybe can help to solve:

https://stackoverflow.com/questions/57689792/permission-denial-while-sharing-file-with-fileprovider https://stackoverflow.com/questions/62323291/coulnt-sharing-file-requires-the-provider-be-exported-or-granturipermission https://stackoverflow.com/questions/24467696/android-file-provider-permission-denial

Let me known If you needed any additional info.

moberwasserlechner commented 2 years ago

I just released the 3.0.0 version to npm. I had no problem while testing on iOS 12.x and 14.x and Android 11.