Tag Archives: Ionic3 update open apk android 8.0 error

Ionic3 update open apk android 8.0 error FileUriExposedException

Android compulsory update in the project, when the file is downloaded. The apk package cannot be opened in android 8.0.

Introduce the plug-in to report the error

import { FileOpener } from '@ionic-native/file-opener';

constructor(private fileOpener: FileOpener) { }

...

this.fileOpener.open('path/to/file.pdf', 'application/pdf')
  .then(() => console.log('File is opened'))
  . catch (e => console.log('Error opening file', e));

 

FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

========================================

According to cordova’s official website, android 8.0 needs to add a configuration file.

Android APK installation restrictions
When opening the APK file for installation, the following restrictions apply:

In Android 8 + on, your application must have ACTION_INSTALL_PACKAGE permission. You can add it by adding it to your application config.xml file:
     <platform name= " android " >
        <config-file parent="/manifest" target="AndroidManifest.xml" xmlns:android="http://schemas.android.com/apk/res/android">
            <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
        </config-file>
    </platform> 
Before Android 7, you could only install APKs from the "external" partition. For example, you can install cordova.file.externalDataDirectory from it, but not cordova.file.dataDirectory from it. Android 7 + does not have this limitation.

After adding the above content, it still reports an error.

 

Solution:

The above is the answer of the great god. Finally modify in AndroidManifest.xml

1
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />

 The default configuration of ionic3 is 16-26. After many trials, only the direct sdk version of 16-23 is supported. The higher the version, the above error will be reported.

Solve the problem of packaging again! ! !