Why did I use the new installation method or not install when parsing the soft armour package
very simple code:
1. This is the logic of the installation. Because I ran directly on the Android simulator. So I didn"t make the judgment of the version number.
File apkFile = new File(Environment.getExternalStorageDirectory() + File.separator + "apkFile", "aaa.apk");
if (apkFile.exists()) {
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri apkFileUri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".fileprovider", apkFile);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(apkFileUri, "application/vnd.android.package-archive");
startActivity(intent);
}
II. This is the configuration of Provider
.
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.along.installtest.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_path">
</meta-data>
</provider>
III, this is the configuration of permissions:
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<permission android:name="android.permission.INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
4. This is the shared directory configuration in the xml file:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-path
name="apkFile"
path="apkFile" />
</paths>
then I raise the VersionCode
of this project, package it, put it in the corresponding apkFile
file, then lower the VersionCode
package, and then run to show the parsing package error. This question has been adjusted for a long time. Ask the god for help. Give me a minute. Thieves are annoying.