今天看啥
热点:

Android 8.0安装apk的实例代码,androidapk


android 8.0安装apk需要请求未知来源权限

//xml配置
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
/**
 * 检测版本8.0
 */
public void checkOreo() {
  if (SdkVersionUtils.hasOreo()) {//8.0
    //判断是否可以直接安装
    boolean canInstall = getPackageManager().canRequestPackageInstalls();
    if (canInstall) {
      //rxpermissions请求权限
      mRxPermissions
          .request(Manifest.permission.REQUEST_INSTALL_PACKAGES)
          .subscribe(granted -> {
            if (granted) {
              //安装apk
              installApk();
            } else if (shouldShowRequestPermissionRationale(Manifest.permission.REQUEST_INSTALL_PACKAGES)) {
               //引导用户去打开权限
              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 {
      //安装apk
      installApk();
    }
  } else {
    //安装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;
  }
}

总结

以上所述是小编给大家介绍的Android 8.0安装apk的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对帮客之家网站的支持!

www.513bk.comtruehttp://www.513bk.com/androidjc/1314354.htmlTechArticleAndroid 8.0安装apk的实例代码,androidapk android 8.0安装apk需要请求未知来源权限 //xml配置uses-permission android:name="android.permission.REQUEST_INSTALL_PACK...

相关文章

相关搜索: android apk

帮客评论

视觉看点