|
|
@@ -49,6 +49,8 @@ public class AppUpdatePlugin extends Plugin {
|
|
|
|
|
|
private static final String APK_MIME = "application/vnd.android.package-archive";
|
|
|
private static final String DOWNLOAD_DIR = "fmode-update";
|
|
|
+ /** 下载落盘的固定文件名(与 download() 里 setDestinationInExternalFilesDir 一致) */
|
|
|
+ private static final String DOWNLOAD_FILE = "fmode-update.apk";
|
|
|
/** 日志标签:自动安装失败时不打扰用户,只记 logcat */
|
|
|
private static final String TAG = "FmodeUpdate";
|
|
|
|
|
|
@@ -229,7 +231,7 @@ public class AppUpdatePlugin extends Plugin {
|
|
|
* 失败时只记日志 —— 此时用户可能已经切走了,弹错误没意义,
|
|
|
* 通知栏本身还有系统下载完成提示可以点。
|
|
|
*/
|
|
|
- private void launchInstall(long id) {
|
|
|
+ private void launchInstallById(long id) {
|
|
|
try {
|
|
|
DownloadManager manager =
|
|
|
(DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);
|
|
|
@@ -263,6 +265,32 @@ public class AppUpdatePlugin extends Plugin {
|
|
|
|
|
|
@PluginMethod
|
|
|
public void install(PluginCall call) {
|
|
|
+ /*
|
|
|
+ * 安装方式(2026-11-28 修「下载完不弹安装」)
|
|
|
+ *
|
|
|
+ * 原来的实现用 URL 末段拼文件名去下载目录里找:
|
|
|
+ * String fileName = Uri.parse(url).getLastPathSegment();
|
|
|
+ * File apk = new File(downloadDir(), fileName);
|
|
|
+ *
|
|
|
+ * 但 download() 是把文件存成固定名 DOWNLOAD_FILE 的,
|
|
|
+ * 两者永远对不上 → apk.exists() == false → 静默 reject,
|
|
|
+ * 用户端表现就是「下载完了什么也没发生」。
|
|
|
+ *
|
|
|
+ * 正确做法:按 downloadId 向 DownloadManager 查真实落盘路径。
|
|
|
+ * 调用方没给 id 时,才退回按文件名找(保持向后兼容)。
|
|
|
+ */
|
|
|
+ Long id = call.getLong("id");
|
|
|
+ if (id != null && id > 0) {
|
|
|
+ int status = downloadStatus(id);
|
|
|
+ if (status != DownloadManager.STATUS_SUCCESSFUL) {
|
|
|
+ call.reject("下载尚未完成");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ launchInstallById(id);
|
|
|
+ call.resolve();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
String url = call.getString("url");
|
|
|
if (url == null || url.isEmpty()) {
|
|
|
call.reject("缺少安装包地址");
|
|
|
@@ -273,14 +301,20 @@ public class AppUpdatePlugin extends Plugin {
|
|
|
String fileName = Uri.parse(url).getLastPathSegment();
|
|
|
if (fileName == null) {
|
|
|
//noinspection SpellCheckingInspection
|
|
|
- fileName = "fmode-update.apk";
|
|
|
+ fileName = DOWNLOAD_FILE;
|
|
|
}
|
|
|
|
|
|
File dir = downloadDir();
|
|
|
File apk = new File(dir, fileName);
|
|
|
if (!apk.exists()) {
|
|
|
- call.reject("安装包不存在,请重新下载");
|
|
|
- return;
|
|
|
+ /* 兜底:按固定名再找一次 —— 下载时用的就是这个名字 */
|
|
|
+ File fallback = new File(dir, DOWNLOAD_FILE);
|
|
|
+ if (fallback.exists()) {
|
|
|
+ apk = fallback;
|
|
|
+ } else {
|
|
|
+ call.reject("安装包不存在,请重新下载");
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -384,7 +418,7 @@ public class AppUpdatePlugin extends Plugin {
|
|
|
*/
|
|
|
int status = downloadStatus(id);
|
|
|
if (status == DownloadManager.STATUS_SUCCESSFUL) {
|
|
|
- launchInstall(id);
|
|
|
+ launchInstallById(id);
|
|
|
} else {
|
|
|
/* 失败也让前端知道,好给用户提示 */
|
|
|
JSObject data = new JSObject();
|