About Android 8.0 adaptation in-app upgrade adaptation

Recently, 8.0 adaptation has been made to allow installation of applications from unknown sources. As of now, after 8.0, there is no switch in the Settings that allows installation from unknown sources, because Google doesn’t want a lifetime license, which is a security optimization for some malware that lets users know. After 8.0, in-app upgrades must be enabled to install apps from unknown sources before they can be installed.

Gets whether the application allows installation from unknown sources

The application for permission to install applications from unknown sources is different from our usual application for special permission. To apply for permission, you need to go to the corresponding permission page to apply for permission. Otherwise, the application cannot be installed and can only be upgraded in the official app Store.

haveInstallPermission = getPackageManager().canRequestPackageInstalls();
Copy the code

Request to allow the installation of an application from an unknown source

 @RequiresApi(api = Build.VERSION_CODES.O)
    private void startInstallPermissionSettingActivity() {
        Uri packageURI = Uri.parse("package:"+this.getPackageName());
        Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES,packageURI);
        startActivityForResult(intent, REQUEST_UPDATE_PERMISSION_CODE);
    }
Copy the code

You must add packageURI, otherwise you’ll just jump to the permission management list, which won’t handle callbacks.

Finally, we will do the processing of whether to allow the result or not in the onActivityResult () method.


  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (REQUEST_UPDATE_PERMISSION_CODE == requestCode) {
                boolean haveInstallPermission = false;
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                    haveInstallPermission = getPackageManager().canRequestPackageInstalls();
                    if(mUpdate ! = null && haveInstallPermission) { AppUpgradeMannager.getInstance(AboutUsBeaconActivity.this).startDown(mUpdate); }else if(! haveInstallPermission) { showToast("Unknown source permissions are required to install the app. Please go to Settings to enable permissions.");
                    }
                }
            }
        }

    }
Copy the code

Well, part of the 8.0 adaptation has been done, with this adaptation document, no longer worry about the application on the 8.0 system will not be installed hahaha 😂