溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Android 8.0版本更新無法自動安裝怎么辦

發布時間:2021-06-28 15:11:15 來源:億速云 閱讀:140 作者:小新 欄目:移動開發

這篇文章給大家分享的是有關Android 8.0版本更新無法自動安裝怎么辦的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

前言

前幾天APP上線了個新版本,有部分用戶反應在下載完安裝包以后點擊安裝無反應。查了下這部分用戶手機的系統的版本都是8.0+版本。因為太久沒關注新版本特性,所以導致了這個問題的發生。

Android 8.0 (Android O)為了針對一些流氓軟件引導用戶安裝其他無關應用。在應用權限設置的“特殊訪問權限”中,加入了“安裝其他應用”的設置。

實現

1.清單文件權限聲明

<uses-permissionandroid:name="android.permission.REQUEST_INSTALL_PACKAGES"/>

2.點擊安裝判斷是否有權限

 if (Build.VERSION.SDK_INT >= 26) { 
    //來判斷應用是否有權限安裝apk
    boolean installAllowed= getPackageManager().canRequestPackageInstalls(); 
    //有權限
    if (installAllowed) { 
      //安裝apk
      install(apkPath);
    } else { 
      //無權限 申請權限
      ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.REQUEST_INSTALL_PACKAGES}, INSTALL_APK_REQUESTCODE); 
    } 
  } else { 
    install(apkPath); 
}

權限申請回調

@Override 
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 
  super.onRequestPermissionsResult(requestCode, permissions, grantResults); 
  switch (requestCode) { 
    case INSTALL_APK_REQUESTCODE: 
      //有注冊權限且用戶允許安裝
      if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 
        install(apkPath); 
      } else { 
        //將用戶引導至安裝未知應用界面。
        Intent intent = new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES); 
        startActivityForResult(intent, GET_UNKNOWN_APP_SOURCES); 
      } 
      break; 

  } 
}

安裝APK

private void install(String apkPath) {
    //7.0以上通過FileProvider
    if (Environment.SYSTEM_VERSION_CODE >= 24) {
      Uri uri = FileProvider.getUriForFile(context, Environment.FILE_PROVIDER_AUTHORITY, new File(apkPath));
      Intent intent = new Intent(Intent.ACTION_VIEW).setDataAndType(uri, "application/vnd.android.package-archive");
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
      context.startActivity(intent);
    } else {
      Intent intent = new Intent(Intent.ACTION_VIEW);
      intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intent.setDataAndType(Uri.parse("file://" + apkPath), "application/vnd.android.package-archive");
      context.startActivity(intent);
    }
}

更新圖示

Android 8.0版本更新無法自動安裝怎么辦

感謝各位的閱讀!關于“Android 8.0版本更新無法自動安裝怎么辦”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女