問題描述
如果從 Google Play 商店下載 apk 和 obb,則無法在 android 10 設備上訪問 obb 擴展文件 (Cannot reach obb expansion file on android 10 device if apk and obb is downloaded from Google Play store)
我從很多地方尋找解決方案(以編程方式測試是否在 Android 10+ 中禁用了舊版外部存儲訪問,https://developer.android.com/google/play/expansion‑files.html#Downloading 等),但不知道錯誤的確切原因。如果僅在 android 10 設備的情況下從 Google Play 下載應用程序,則會出現此錯誤:
Caused by: java.lang.IllegalArgumentException: Couldn't get OBB info for /storage/emulated/0/Android/obb/packageName/main.package_version.packageName.obb
程序可以找到 obb 文件(即使在 android 10 設備上)
File mainFile = new File(Environment.getExternalStorageDirectory() + "/Android/obb/" + packageName + "/" + "main." + packageVersion + "." + packageName + ".obb")
mainFile.getAbsolutpath()
也獲取文件路徑。然而,當存儲管理器用於從 Google Play 商店下載的應用程序時
sm.mountObb(mainFile.getAbsolutePath(), null, mainObbStateChangeListener );
無法訪問 obb 擴展文件並終止應用程序並出現上述錯誤。
可以從 Google Play 下載應用程序,但僅適用於 android 9 或以下設備。如果我創建 apk 並將其安裝在 android 10 設備上,該應用程序可以毫無問題地訪問 obb 文件。從 Google Play 商店下載的應用程序能夠在 android 10 設備上運行時,我錯過了什麼?幫助將不勝感激。
更新:
我在 Android 10 設備上找到了錯誤的原因,但我仍然不知道答案:
如果 apk 版本代碼(app gradle 中的版本代碼)與 obb 文件名中的版本代碼匹配(如果我理解良好的話應該是(. More details of this method can be found here.