|
@@ -258,6 +258,7 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
|
private void showForceUpdateDialog(UpdateInfoResponse updateInfo) {
|
|
private void showForceUpdateDialog(UpdateInfoResponse updateInfo) {
|
|
|
|
|
+
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
LayoutInflater inflater = LayoutInflater.from(this);
|
|
LayoutInflater inflater = LayoutInflater.from(this);
|
|
|
View dialogView = inflater.inflate(R.layout.dialog_update, null);
|
|
View dialogView = inflater.inflate(R.layout.dialog_update, null);
|
|
@@ -533,12 +534,35 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
|
|
int statusIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
|
|
|
if (DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(statusIndex)) {
|
|
if (DownloadManager.STATUS_SUCCESSFUL == cursor.getInt(statusIndex)) {
|
|
|
- // 获取下载文件的URI
|
|
|
|
|
- int uriIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);
|
|
|
|
|
- String downloadedFileUriString = cursor.getString(uriIndex);
|
|
|
|
|
|
|
+ // 获取下载文件的URI - 尝试多种方式获取URI
|
|
|
|
|
+ Uri apkUri = null;
|
|
|
|
|
+
|
|
|
|
|
+ // 方法1: 使用DownloadManager.getUriForDownloadedFile (推荐)
|
|
|
|
|
+ apkUri = downloadManager.getUriForDownloadedFile(downloadId);
|
|
|
|
|
+
|
|
|
|
|
+ // 方法2: 如果方法1返回null,则尝试从COLUMN_LOCAL_URI获取
|
|
|
|
|
+ if (apkUri == null) {
|
|
|
|
|
+ int uriIndex = cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI);
|
|
|
|
|
+ String downloadedFileUriString = cursor.getString(uriIndex);
|
|
|
|
|
+ if (downloadedFileUriString != null) {
|
|
|
|
|
+ apkUri = Uri.parse(downloadedFileUriString);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (downloadedFileUriString != null) {
|
|
|
|
|
- Uri apkUri = Uri.parse(downloadedFileUriString);
|
|
|
|
|
|
|
+ // 方法3: 如果还是null,则尝试从COLUMN_URI获取
|
|
|
|
|
+ if (apkUri == null) {
|
|
|
|
|
+ int uriIndex = cursor.getColumnIndex(DownloadManager.COLUMN_URI);
|
|
|
|
|
+ String downloadedFileUriString = cursor.getString(uriIndex);
|
|
|
|
|
+ if (downloadedFileUriString != null) {
|
|
|
|
|
+ apkUri = Uri.parse(downloadedFileUriString);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (apkUri != null) {
|
|
|
|
|
+ Log.i(TAG, "原始APK URI: " + apkUri.toString());
|
|
|
|
|
+ Log.i(TAG, "URI Scheme: " + apkUri.getScheme());
|
|
|
|
|
+ Log.i(TAG, "URI Authority: " + apkUri.getAuthority());
|
|
|
|
|
+ Log.i(TAG, "URI Path: " + apkUri.getPath());
|
|
|
|
|
|
|
|
// Android 7.0及以上版本使用FileProvider处理file:// URI
|
|
// Android 7.0及以上版本使用FileProvider处理file:// URI
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && "file".equals(apkUri.getScheme())) {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && "file".equals(apkUri.getScheme())) {
|
|
@@ -550,6 +574,7 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
"com.paul.drone.fileprovider",
|
|
"com.paul.drone.fileprovider",
|
|
|
apkFile
|
|
apkFile
|
|
|
);
|
|
);
|
|
|
|
|
+ Log.i(TAG, "转换后的Content URI: " + contentUri.toString());
|
|
|
// 授予临时权限给包管理器
|
|
// 授予临时权限给包管理器
|
|
|
updateUtil.installApk(contentUri);
|
|
updateUtil.installApk(contentUri);
|
|
|
} else {
|
|
} else {
|
|
@@ -557,6 +582,7 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
// Android 7.0以下版本或已经是content:// URI,直接使用
|
|
// Android 7.0以下版本或已经是content:// URI,直接使用
|
|
|
|
|
+ Log.i(TAG, "直接使用URI进行安装");
|
|
|
updateUtil.installApk(apkUri);
|
|
updateUtil.installApk(apkUri);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -582,4 +608,5 @@ public class LoginActivity extends AppCompatActivity {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|