Android 8.0 Installation of apk Installation Code
- 2021-08-28 21:12:37
- OfStack
android 8.0 Installing apk requires requesting unknown source permissions
//xml Configure
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
/**
* Detected version 8.0
*/
public void checkOreo() {
if (SdkVersionUtils.hasOreo()) {//8.0
// Determine whether it can be installed directly
boolean canInstall = getPackageManager().canRequestPackageInstalls();
if (canInstall) {
//rxpermissions Request permission
mRxPermissions
.request(Manifest.permission.REQUEST_INSTALL_PACKAGES)
.subscribe(granted -> {
if (granted) {
// Installation apk
installApk();
} else if (shouldShowRequestPermissionRationale(Manifest.permission.REQUEST_INSTALL_PACKAGES)) {
// Guide users to open permissions
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
startActivityForResult(intent, GET_UNKNOWN_APP_SOURCES);
} else {
Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
startActivityForResult(intent, GET_UNKNOWN_APP_SOURCES);
}
});
} else {
// Installation apk
installApk();
}
} else {
// Installation apk
installApk()
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case GET_UNKNOWN_APP_SOURCES:
checkOreo();
break;
}
}
Summarize