When a new test machine automatically downloads, upgrades and installs the newer version of the APP, it reports a "problem parsing the package" error. There are various reasons for this. After some searching, the following answers are more comprehensive:
1. Android 7 and below are generally not a problem
2. Android 7 and above need to use FileProvider
3. Android 7.1 needs to add REQUEST_INSTALL_PACKAGES permission to the manifest
4. Android 8 requires authorization to allow applications to install unknown applications, set in the application permissions. (this time the question)
1. Pay attention to check whether there is read and write permission of the external memory, if not, the program cannot be downloaded normally.
2. Whether the application permission is allowed to "install unknown applications" can be judged as follows: Pit: But the targetSdkVersion needs to be at least 26, otherwise the following method will always return false;
After the judgment, it can help the user to jump to the setting page to guide the user to set, or let the user manage the settings through the application rights set by the system.
Intent unknownAppSourceIntent = new Intent() .setAction(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES) .setData(Uri.parse(String.format("package:%s",MainOneActivity.this.getPackageName()))); startActivityForResult(unknownAppSourceIntent, UNKNOWN_APP_INSTALL);
Some custom android systems higher than Android 8 can be installed without step 4, while others cannot. Alas, the fragmentation of Android ~. . .