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
67 stars 13 forks source link

Can't open PDF file on Android when opening with Samsung PDF Reader #49

Closed sbakic closed 1 year ago

sbakic commented 1 year ago

Describe the bug Every time we call FileOpener.open() from our Ionic client for some Android devices, it won't open a file. It works for iOS.

To Reproduce Steps to reproduce the behavior:

As you can see, I am clicking on the link that is just calling FileOpener.open() with the required parameters (check below logs).

https://github.com/capacitor-community/file-opener/assets/6079897/315446f9-f062-46ce-8b0e-8485f9d61cb9

Expected behavior Should open the file in the device's default app for the specific file type. I have tried PDF and DOCX files, same issue. I am using the default Samsung PDF viewer which should be 'Samsung Notes' (or so calledSamsung PDF Reader). When I change the configuration to choose from which app to open the file (via openWithDefault: false) it works with Google Drive.

NOTE: It works for Samsung Galaxy A53, Android 13, One UI 5.1.

Screenshots Client code that is calling FileOpener.open(). As you can see we should catch an exception if it happens, but no exception was caught. Screenshot from 2023-10-20 19-10-36

Desktop (please complete the following information): We are not using this plugin for desktop.

Smartphone (please complete the following information):

Additional context Line in the plugin where I can't track it anymore. It doesn't catch any exceptions in this method.

Screenshot from 2023-10-20 19-24-11

Log from Logcat, after FileOpener.open() is called:

2023-10-20 19:02:25.381 27996-27996 Capacitor/Plugin        com.APP_NAME.frontend             V  To native (Capacitor plugin): callbackId: 78640634, pluginId: Filesystem, methodName: getUri
2023-10-20 19:02:25.381 27996-27996 Capacitor               com.APP_NAME.frontend             V  callback: 78640634, pluginId: Filesystem, methodName: getUri, methodData: {"path":"APP_NAME\/downloads\/6532af563f67f0e04f57b106","directory":"DATA"}
2023-10-20 19:02:25.406 27996-27996 Capacitor/Plugin        com.APP_NAME.frontend             V  To native (Capacitor plugin): callbackId: 78640635, pluginId: FileOpener, methodName: open
2023-10-20 19:02:25.406 27996-27996 Capacitor               com.APP_NAME.frontend             V  callback: 78640635, pluginId: FileOpener, methodName: open, methodData: {"filePath":"file:\/\/\/data\/user\/0\/com.APP_NAME.frontend\/files\/APP_NAME\/downloads\/6532af563f67f0e04f57b106","contentType":"application\/pdf"}
2023-10-20 19:03:40.293 27996-27996 Capacitor/AppPlugin     com.APP_NAME.frontend             V  Notifying listeners for event pause
2023-10-20 19:03:40.293 27996-27996 Capacitor/AppPlugin     com.APP_NAME.frontend             D  No listeners found for event pause
2023-10-20 19:03:40.296 27996-27996 Capacitor               com.APP_NAME.frontend             D  App paused
2023-10-20 19:03:40.316 27996-27996 Capacitor/Console       com.APP_NAME.frontend             I  File: http://localhost/ - Line 228 - Msg: undefined
2023-10-20 19:03:40.353 27996-27996 ViewRootIm...nActivity] com.APP_NAME.frontend             I  MSG_WINDOW_FOCUS_CHANGED 0 0
2023-10-20 19:03:40.473 27996-27996 ViewRootIm...nActivity] com.APP_NAME.frontend             I  stopped(false) old = false
2023-10-20 19:03:40.474 27996-27996 Capacitor/AppPlugin     com.APP_NAME.frontend             D  Firing change: true
2023-10-20 19:03:40.475 27996-27996 Capacitor/AppPlugin     com.APP_NAME.frontend             V  Notifying listeners for event appStateChange
2023-10-20 19:03:40.483 27996-27996 Capacitor/AppPlugin     com.APP_NAME.frontend             V  Notifying listeners for event resume
2023-10-20 19:03:40.484 27996-27996 Capacitor/AppPlugin     com.APP_NAME.frontend             D  No listeners found for event resume
2023-10-20 19:03:40.491 27996-27996 Capacitor/BrowserPlugin com.APP_NAME.frontend             E  Error binding to custom tabs service
2023-10-20 19:03:40.492 27996-27996 Capacitor               com.APP_NAME.frontend             D  App resumed
2023-10-20 19:03:40.500 27996-27996 DecorView               com.APP_NAME.frontend             I  notifyKeepScreenOnChanged: keepScreenOn=true
2023-10-20 19:03:40.501 27996-27996 MSHandlerLifeCycle      com.APP_NAME.frontend             I  removeMultiSplitHandler: no exist. decor=DecorView@6aa1172[MainActivity]
2023-10-20 19:03:40.527 27996-27996 ViewRootIm...nActivity] com.APP_NAME.frontend             I  performTraversals params={(0,0)(fillxfill) sim={adjust=resize forwardNavigation} layoutInDisplayCutoutMode=shortEdges ty=BASE_APPLICATION wanim=0x1030309
                                                                                                      fl=81810180
                                                                                                      pfl=12020040
                                                                                                      bhv=DEFAULT
                                                                                                      fitSides= naviIconColor=0
                                                                                                      sfl=100000}
2023-10-20 19:03:40.546 27996-27996 ViewRootIm...nActivity] com.APP_NAME.frontend             I  performTraversals mFirst=false windowShouldResize=false viewVisibilityChanged=false mForceNextWindowRelayout=false params={(0,0)(fillxfill) sim={adjust=resize forwardNavigation} layoutInDisplayCutoutMode=shortEdges ty=BASE_APPLICATION wanim=0x1030309
                                                                                                      fl=81810180
                                                                                                      pfl=12020040
                                                                                                      bhv=DEFAULT
                                                                                                      fitSides= naviIconColor=0
                                                                                                      sfl=100000}
2023-10-20 19:03:40.561 27996-27996 ViewRootIm...nActivity] com.APP_NAME.frontend             I  updateBlastSurfaceIfNeeded mBlastBufferQueue=0xb400006ebc1fde50 isSameSurfaceControl=true
2023-10-20 19:03:40.562 27996-27996 BLASTBufferQueue        com.APP_NAME.frontend             I  update, w= 1080 h= 2400 mName = ViewRootImpl@b6b5b6b[MainActivity] mNativeObject= 0xb400006ebc1fde50 sc.mNativeObject= 0xb400006e4c22aef0 format= -1 caller= android.view.ViewRootImpl.updateBlastSurfaceIfNeeded:2898 android.view.ViewRootImpl.relayoutWindow:9847 android.view.ViewRootImpl.performTraversals:3884 android.view.ViewRootImpl.doTraversal:3116 android.view.ViewRootImpl$TraversalRunnable.run:10885 android.view.Choreographer$CallbackRecord.run:1301 
2023-10-20 19:03:40.563 27996-27996 ViewRootIm...nActivity] com.APP_NAME.frontend             I  Relayout returned: old=(0,0,1080,2400) new=(0,0,1080,2400) req=(1080,2400)0 dur=15 res=0x0 s={true 0xb400006f4c247f70} ch=false seqId=0
2023-10-20 19:03:40.564 27996-27996 ViewRootIm...nActivity] com.APP_NAME.frontend             I  MSG_WINDOW_FOCUS_CHANGED 1 0
2023-10-20 19:03:40.565 27996-27996 ViewRootIm...nActivity] com.APP_NAME.frontend             I  mThreadedRenderer.initializeIfNeeded()#2 mSurface={isValid=true 0xb400006f4c247f70}
2023-10-20 19:03:40.569 27996-27996 InputMethodManager      com.APP_NAME.frontend             D  startInputInner - Id : 0
2023-10-20 19:03:40.569 27996-27996 InputMethodManager      com.APP_NAME.frontend             I  startInputInner - mService.startInputOrWindowGainedFocus

I assume it has something to do with Samsung PDF Readerm, not with the plugin itself?

sbakic commented 1 year ago

I will close this issue because it has nothing to do with the plugin itself but with the app that opens PDF files.