capacitor-community / file-opener

Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri. This plugin is similar to cordova-plugin-file-opener2 without installation support.
MIT License
64 stars 13 forks source link

Plugin no longer working with Android 14 #59

Closed cos-mh closed 5 months ago

cos-mh commented 5 months ago

Describe the bug Opening a file with the plugin on Android 14 throws the following error:

Activity not found: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://io.ionic.starter.file.opener.provider/... typ=image/png flg=0x1 } android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=content://io.ionic.starter.file.opener.provider/... typ=image/png flg=0x1 } at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:2363) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1949) at android.app.Activity.startActivityForResult(Activity.java:5743) at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:780) at android.app.Activity.startActivityForResult(Activity.java:5701) at androidx.activity.ComponentActivity.startActivityForResult(ComponentActivity.java:761) at android.app.Activity.startActivity(Activity.java:6199) at android.app.Activity.startActivity(Activity.java:6166) at com.ryltsov.alex.plugins.file.opener.FileOpenerPlugin.open(FileOpenerPlugin.java:46) at java.lang.reflect.Method.invoke(Native Method) at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:138) at com.getcapacitor.Bridge.lambda$callPluginMethod$0(Bridge.java:816) at com.getcapacitor.Bridge.$r8$lambda$ehFTi5f4HhVNFKTbCKAYDkpQYRA(Unknown Source:0) at com.getcapacitor.Bridge$$ExternalSyntheticLambda3.run(Unknown Source:8) at android.os.Handler.handleCallback(Handler.java:959) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loopOnce(Looper.java:232) at android.os.Looper.loop(Looper.java:317) at android.os.HandlerThread.run(HandlerThread.java:68)

I cannot reproduce this error on a device with android 11, which makes me think that its a problem with Android 14.

To Reproduce Steps to reproduce the behavior:

  1. Use reproduction app: https://github.com/cos-mh/capacitor-file-opener
  2. Install app with npm i and ng build
  3. Start the app with ionic capacitor run android -l --external on an android device
  4. Press the Test-button top left in the corner
  5. On an android 14 device you will now get an error in the console. On android 11 the saved picture will open.

Expected behavior The file should open

Smartphone 1

Smartphone 2

Additional context Help would be much appreciated

ryaa commented 5 months ago

There are two problems with the repo to reproduce the problem

1) package.json.lock references local npm server which makes npm install fail - see below

alexryltsov@Alexs-MacBook-Pro-2 master % npm install
npm ERR! code ETIMEDOUT
npm ERR! syscall connect
npm ERR! errno ETIMEDOUT
npm ERR! network request to http://192.168.1.168:8081/repository/npm-group/electron-to-chromium/-/electron-to-chromium-1.4.756.tgz failed, reason: connect ETIMEDOUT 192.168.1.168:8081
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in: /Users/alexryltsov/.npm/_logs/2024-05-23T07_12_27_055Z-debug-0.log

Note http://192.168.1.168:8081/

2) Android Studio gradle.properties references local path Value 'C:/Program Files/Microsoft/jdk-17.0.11.9-hotspot' given for org.gradle.java.home Gradle property is invalid (Java home supplied is invalid) which causes an error when trying to build from Android Studio

After I have fixed the both things mentioned avove the problem is still not reproducible and everything works fine - see below

https://github.com/capacitor-community/file-opener/assets/3608222/5d9e306b-b1d4-44de-802c-1ce9c22f8f37

@cos-mh can you please make sure that you have the appropriate application installed on your Android 14 devices supporting the file that you save in your repo app.

Please let me know if the problem is resolved when you have the required app(s) installed on your Android 14. Thank you

cos-mh commented 5 months ago

I checked and yes my new Android 14 dev device has no app to open pictures. After installing Google Photos it works just fine.

@ryaa As a suggestion/question: would it be possible to catch that specific error somehow so I can prompt the user that he needs to install an app first?

Thanks for your help!

ryaa commented 5 months ago

@ryaa As a suggestion/question: would it be possible to catch that specific error somehow so I can prompt the user that he needs to install an app first?

I believe that the consuming/your app should catch and handle this error the way it needs (show some dialog saying that the required app is missing etc.).

ryaa commented 5 months ago

Closing as no actions are planned.