pwlin / cordova-plugin-file-opener2

A File Opener Plugin for Cordova
MIT License
314 stars 587 forks source link

Unable to open files when targeting API 28 #268

Closed KleggerKoder closed 4 years ago

KleggerKoder commented 5 years ago

Expected Behaviour

Opens file

Actual Behaviour

java.lang.NullPointerException Error -- See log below

Reproduce Scenario (including but not limited to)

Build targeting Android SKD 28

Steps to Reproduce

Try to open files / nothing happens

Platform and Version (reproduced on Android 8 and 9)

Logs taken while reproducing problem From Android Studio

/PluginManager: Uncaught exception from plugin java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:604) at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:578) at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:416) at io.github.pwlin.cordova.plugins.fileopener2.FileOpener2._open(FileOpener2.java:124) at io.github.pwlin.cordova.plugins.fileopener2.FileOpener2.execute(FileOpener2.java:67) at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98) at org.apache.cordova.PluginManager.exec(PluginManager.java:132) at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57) at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:325) at android.os.Looper.loop(Looper.java:142) at android.os.HandlerThread.run(HandlerThread.java:65)

senjoeson commented 5 years ago

please check your "plugin.xml" whether the FileProvider is configured. the same as the following:

 <provider
            android:name="io.github.pwlin.cordova.plugins.fileopener2.FileProvider"
            android:authorities="${applicationId}.opener.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/opener_paths" />
        </provider>

And, if you have done, it still can not work, you may add a permission for adapt the high Sdk version.

<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
nip3o commented 5 years ago

@senjoeson the user does not really have any control over plugin.xml since it is located in the plugin source (that comes from this repository) and not in the user project?

The issue in my case was that the provider tag was not present in AndroidManifest.xml at all. Manually replacing ${applicationId} with my app id in the code above and inserting it into platforms⁩/android⁩/app⁩/src⁩/main⁩/AndroidManifest.xml solved the problem for me.

senjoeson commented 4 years ago

@nip3o please check your cordova version to adpat the place of code. each version is diffrent configuration in the file "plugin.xml". please check out https://cordova.apache.org/

Eugene2799 commented 4 years ago

@senjoeson Thanks for your comment