I have to load a PDF i saved to my filesystem.
I save the PDF using Capacitor Filesystem plugin:
Filesystem.writeFile({
path: 'text.pdf',
data: res.FileDataBase64,
directory: Directory.ExternalStorage,
});
In a button i try to open PDF in a webview using Cordova InAppBrowser or Capacitor Browser plugins:
const uri = await Filesystem.getUri({
path: 'text.pdf',
directory: Directory.ExternalStorage,
});
this.url = uri.uri;
this.iab.create(Capacitor.convertFileSrc(this.url) , '_blank', 'location=yes,hidden=no,');
await Browser.open({ url: Capacitor.convertFileSrc(this.url) });
I tried to use
this.url
or
Capacitor.convertFileSrc(this.url)
but doesn’t work, i got net::ERR_CONNECTION_REFUSED in Android device. I tried every possible solutions I know, but nothings.
This is my AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.xxx">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:name="com.tmedapp.tmw.MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBarLaunch"
android:launchMode="singleTask"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
</application>
<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
And this my capacitor.config file:
import { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
appId: 'com.xxx.xxx',
appName: 'xxxxx',
webDir: 'www',
bundledWebRuntime: false,
server:{
cleartext: true,
allowNavigation : [
'*'
],
},
cordova: {
accessOrigins: [
'*'
]
}
};
export default config;
How can i solve it?
If I use an external link, the webview ask me to download it. Why?