Android O 8.0, version upgrade does not jump to the perfect solution of App installation page

Source: Internet
Author: User

Https://www.jianshu.com/p/af37c1c588c4

Recent development encountered a problem, when the app upgrade, other phones can be upgraded, download the installation package, skip to the installation page for the new version of the installation. However, there is a user response, Huawei P10 and Huawei Mate 9 upgrade, how can not jump to the installation page. At first I thought it was the problem of the Huawei mobile phone system (because the Huawei Test machine is normal), but also specifically compared to several configurations of Huawei mobile phones, and finally found that the Android 8.0 system version of the pot, not the problem of mobile phones.

August 22, 2017, Google released the official version of Android 8.0, the official name is: Android Oreo (Oreo), Android 8.0 enhanced rights Management, become more secure. Before Android 8.0, all the unknown source applications can be installed, or will pop the window to the user a hint, so the design is convenient, but if it is tempting to install malicious software, install "unknown source" application may pose a potential harm to the mobile phone system;

On Android 8.0, the switch to apply permissions from unknown sources has been removed and replaced by a management list of unknown source apps, and if you want to install an app from a developer you trust, you'll need to manually authorize the "Install unknown app" license every time. Settings page such as: (In Huawei Android 8.0, open the Settings page: Settings list, security and privacy, more security settings, install unknown apps)


, if an application chooses "Do not allow", then assume that the app manually upgrade, it will not be able to successfully jump to the installation page for the normal app upgrade process, it is necessary to manually authorize the line, but many users do not know the need to set this.
Nonsense said a lot, the solution is actually very simple.

1. In the Androidmanifest.xml file, add the Request_install_packages permission
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
2. Add the code that is compatible with Android 8.0 in the code that opens the installation package.

 /** * Open the installation package * *@param mcontext *@param Fileuri * *PublicvoidOpenapkfile(Activity Mcontext, String Fileuri) {dataembeddingutil.dataembeddingappupdate (Fileuri);The core is the following lines of codeif (Null! = Fileuri) {try {Intent Intent =New Intent (Intent.action_view); File Apkfile =New File (Fileuri);Compatible with 7.0if (Build.VERSION.SDK_INT >= build.version_codes. N) {intent.setflags (intent.flag_grant_read_uri_permission); Uri Contenturi = Fileprovider.geturiforfile (Mcontext, mcontext.getpackagename () +". Fileprovider", apkfile); Intent.setdataandtype (Contenturi,"Application/vnd.android.package-archive");Compatible with 8.0if (Build.VERSION.SDK_INT >= build.version_codes. O) {Boolean hasinstallpermission = Mcontext.getpackagemanager (). Canrequestpackageinstalls ();if (!hasinstallpermission) {Toastutil.maketext (Myapplication.getcontext (), Myapplication.getcontext (). GetString ( R.string.string_install_unknow_apk_note),FALSE); Startinstallpermissionsettingactivity ();Return } } }else {Intent.setdataandtype (Uri.fromfile (Apkfile),"Application/vnd.android.package-archive"); Intent.setflags (Intent.flag_activity_new_task); }if (Mcontext.getpackagemanager (). Queryintentactivities (Intent,0). Size () >0) {mcontext.startactivity (intent);}} catch (Throwable e) {e.printstacktrace (); Dataembeddingutil.dataembeddingappupdate (E.tostring ()); Commonutils.makeeventtoast (Myapplication.getcontext (), Myapplication.getcontext (). getString (R.string.download_ Hint), false); }}} /** * Jump to Settings-allow installation of unknown source-page * /@RequiresApi (API = Build.version_codes. O) private void startinstallpermissionsettingactivity() { //Note This is 8.0 new API Intent Intent  Intent (settings.action_manage_unknown_app_sources); Intent.addflags (Intent.flag_activity_new_task); Mcontext.startactivity (Intent); }


A code worm who knows music
Links: https://www.jianshu.com/p/af37c1c588c4
Source: Pinterest

Android O 8.0, version upgrade does not jump to the perfect solution of App installation page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.