cordova-plugin-document-scanner icon indicating copy to clipboard operation
cordova-plugin-document-scanner copied to clipboard

Ionic Capacitor - Android 10 - FileNotFoundException

Open gregor-srdic opened this issue 3 years ago • 14 comments

Describe the bug I am trying to use this plugin with ionic capacitor and on Android 10 it never shows the image crop screen, caused by the following exception: 2020-08-03 13:26:05.320 27707-27707/si.test.app D/ViewRootImpl@9f2e8cd[ScanActivity]: Relayout returned: old=(0,0,1080,2280) new=(0,0,1080,2280) req=(1080,2280)4 dur=8 res=0x1 s={false 0} ch=false 2020-08-03 13:26:05.321 27707-27707/si.test.app D/ViewRootImpl@9f2e8cd[ScanActivity]: stopped(false) old=true 2020-08-03 13:26:05.328 27707-27707/si.test.app W/System.err: java.io.FileNotFoundException: open failed: ENOENT (No such file or directory) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:315) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:220) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1505) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1427) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at com.scanlibrary.PickImageFragment.getBitmap(PickImageFragment.java:388) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at com.scanlibrary.PickImageFragment.onActivityResult(PickImageFragment.java:315) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.app.Activity.dispatchActivityResult(Activity.java:8321) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.app.ActivityThread.deliverResults(ActivityThread.java:5230) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.app.ActivityThread.handleSendResult(ActivityThread.java:5278) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2220) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.os.Handler.dispatchMessage(Handler.java:107) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.os.Looper.loop(Looper.java:237) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at android.app.ActivityThread.main(ActivityThread.java:8016) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at java.lang.reflect.Method.invoke(Native Method) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 2020-08-03 13:26:05.329 27707-27707/si.test.app W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076) 2020-08-03 13:26:05.330 27707-27707/si.test.app D/ViewRootImpl@9f2e8cd[ScanActivity]: stopped(false) old=false 2020-08-03 13:26:05.339 27707-27707/si.test.app D/ViewRootImpl@9f2e8cd[ScanActivity]: Relayout returned: old=(0,0,1080,2280) new=(0,0,1080,2280) req=(1080,2280)0 dur=8 res=0x7 s={true 502479515648} ch=true 2020-08-03 13:26:05.339 27707-27948/si.test.app D/OpenGLRenderer: createReliableSurface : 0x75f8c71ac0(0x74fe1cf000) 2020-08-03 13:26:05.339 27707-27948/si.test.app I/mali_winsys: new_window_surface() [1080x2280] return: 0x3000 2020-08-03 13:26:05.342 27707-27948/si.test.app D/OpenGLRenderer: makeCurrent EglSurface : 0x0 -> 0x756a168200 2020-08-03 13:26:05.345 27707-27707/si.test.app D/ViewRootImpl@9f2e8cd[ScanActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1 2020-08-03 13:26:05.346 27707-27707/si.test.app D/InputMethodManager: prepareNavigationBarInfo() DecorView@d4f4b1e[ScanActivity] 2020-08-03 13:26:05.346 27707-27707/si.test.app D/InputMethodManager: getNavigationBarColor() -855310 2020-08-03 13:26:05.347 27707-27707/si.test.app D/InputMethodManager: prepareNavigationBarInfo() DecorView@d4f4b1e[ScanActivity] 2020-08-03 13:26:05.347 27707-27707/si.test.app D/InputMethodManager: getNavigationBarColor() -855310 2020-08-03 13:26:05.347 27707-27707/si.test.app V/InputMethodManager: Starting input: tba=si.test.app ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false 2020-08-03 13:26:05.347 27707-27707/si.test.app D/InputMethodManager: startInputInner - Id : 0 2020-08-03 13:26:05.347 27707-27707/si.test.app I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus To Reproduce Steps to reproduce the behavior:

  1. Create an app with Ionic Cli
  2. Add capacitor android platform
  3. Install plugin
  4. Try to scan a document

Expected behavior Document content returned to the app.

Smartphone (please complete the following information):

  • Device: Samsung Galaxy S10e
  • OS: Android 10
  • @capacitor/core : 2.3.0
  • @capacitor/android: 2.3.0
  • cordova-plugin-document-scanner: 4.2.5

gregor-srdic avatar Aug 03 '20 11:08 gregor-srdic

This could also be related:

2020-08-03 13:42:50.749 1278-1278/? E/Util: writeImageDataToRequestedUri : failed to make directory or the directory already existed. 2020-08-03 13:42:50.760 1278-1278/? E/Util: writeImageDataToRequestedUri : Returned because outputStream IOException.

gregor-srdic avatar Aug 03 '20 11:08 gregor-srdic

Me too. Android 10 it never shows the image crop screen.

niruttomtom avatar Aug 20 '20 09:08 niruttomtom

I solved the problem with the solution provided on this issue : https://github.com/apache/cordova-plugin-file/issues/408

By adding android:requestLegacyExternalStorage="true" to the application tag directly in the AndroidManifest.xml file generated by Cordova. It's seems to be a problem with API 29...

AJRdev avatar Sep 12 '20 17:09 AJRdev

Hey sorry I have been inactive for a while. I tested this with an Android 10 phone but I could not replicate it. I double checked if it was compiling with api level 29 as well. Could this be a device specific issue? or an ionic specific issue ? I tested with vanilla cordova.

Do let me know if you guys have any info, work on this plugin is going to become a huge focus now so I will be dedicating a considerable amount of time to fixing any issues that are cropping up.

Cheers and have a nice day :) Chris Neutrinos

ChrisTomAlx avatar Nov 09 '20 11:11 ChrisTomAlx

Released a new beta version of the plugin.

To test it :-

  1. Make sure to remove the old version using cordova plugin rm cordova-plugin-document-scanner
  2. To test it add the following to your project
    • cordova plugin add [email protected]
    • cordova plugin add cordova plugin add cordova-plugin-androidx
    • cordova plugin add cordova-plugin-androidx-adapter

If you guys could help by testing this beta version and let me know if it solved your issue, I can release the 5.0.0 version. Latest plugin also solves this issue

Cheers and have a nice day :) Chris Neutrinos

ChrisTomAlx avatar Nov 10 '20 12:11 ChrisTomAlx

Hi @ChrisTomAlx ,

Thanks for the update, I will give a try without adding android:requestLegacyExternalStorage="true" property to the manifest.

And it's weird that you don't had the issue on your device, I was personally running the application on a Honor 10 view. My ionic info ouput if it helps :

Ionic:

   Ionic CLI          : 5.4.16 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.10

Cordova:

   Cordova CLI       : 8.1.2 ([email protected])
   Cordova Platforms : android 9.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 1.2.1, (and 10 other plugins)

Utility:

   cordova-res : 0.15.1
   native-run  : 1.0.0

System:

   Android SDK Tools : 26.1.1 (/home/ajrdev/Android/Sdk)
   NodeJS            : v10.0.0 (/usr/local/bin/node)
   npm               : 5.6.0
   OS                : Linux 5.4

I'll keep you posted, have a nice day as well :)

AJRdev avatar Nov 10 '20 16:11 AJRdev

Thanks @AJRdev I am using cordova cli 10.0.0 with cordova-android 9.0.0. But as per android docs you are on the right tracks. Its really strange that I am unable to reproduce it.

Also the android:requestLegacyExternalStorage="true" solution will stop working on API 30, so I would like to implement a permanent fix for this issue.

Cheers, Chris Neutrinos

ChrisTomAlx avatar Nov 11 '20 06:11 ChrisTomAlx

Hello,

Does it possible to add requestLegacyExternalStorage into config.xml cordova file? Can you post here an example ?

Thank you

scramatte avatar Nov 16 '20 12:11 scramatte

I've just rebuild the project with the requestLegacyExternalStorage attribute but still doesn't works. I use SDK r29. A separate native camera window is opened when I try to scan as I report in #86 issue.

scramatte avatar Nov 16 '20 13:11 scramatte

With cordova cli 10 it looks that doesn't exists "cordova-plugin-androidx" plugin.

scramatte avatar Nov 16 '20 13:11 scramatte

@scramatte if you are using version 5.0.0-beta.0 of the plugin, please refer to this comment

Cheers and have a nice day :) Chris Neutrinos

ChrisTomAlx avatar Nov 16 '20 14:11 ChrisTomAlx

@ChrisTomAlx I've done what you explained in the comment but still have the issue. since cordova-android@9 , cordova-plugin-androidx" have been deprecated.

scramatte avatar Nov 16 '20 19:11 scramatte

@scramatte even after adding android:requestLegacyExternalStorage="true" ?

Cheers and have a nice day :) Chris Neutrinos

ChrisTomAlx avatar Nov 17 '20 12:11 ChrisTomAlx

@scramatte you might be interested in this discussion

Cheers and have a nice day :) Chris Neutrinos

ChrisTomAlx avatar Nov 17 '20 12:11 ChrisTomAlx