|
|
@@ -232,12 +232,30 @@ public class AppUpdatePlugin extends Plugin {
|
|
|
* 失败时只记日志 —— 此时用户可能已经切走了,弹错误没意义,
|
|
|
* 通知栏本身还有系统下载完成提示可以点。
|
|
|
*/
|
|
|
+ /**
|
|
|
+ * 轻提示(2026-11-29)
|
|
|
+ *
|
|
|
+ * 安装链路之前完全静默:失败只写 logcat,用户手机上什么也看不到,
|
|
|
+ * 只能反馈「没反应」,排查全靠猜。现在关键失败点都弹一句,
|
|
|
+ * 用户直接截图就能告诉我们卡在哪一步。
|
|
|
+ */
|
|
|
+ private void toast(final String msg) {
|
|
|
+ try {
|
|
|
+ new android.os.Handler(android.os.Looper.getMainLooper()).post(() ->
|
|
|
+ android.widget.Toast.makeText(getContext(), msg, android.widget.Toast.LENGTH_LONG).show()
|
|
|
+ );
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ /* toast 本身失败不影响主流程 */
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void launchInstallById(long id) {
|
|
|
try {
|
|
|
DownloadManager manager =
|
|
|
(DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE);
|
|
|
if (manager == null) {
|
|
|
Log.w(TAG, "install abort: DownloadManager null");
|
|
|
+ toast("安装失败:下载服务不可用");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -259,6 +277,7 @@ public class AppUpdatePlugin extends Plugin {
|
|
|
Uri apkUri = manager.getUriForDownloadedFile(id);
|
|
|
if (apkUri == null) {
|
|
|
Log.w(TAG, "install abort: no uri for downloaded file");
|
|
|
+ toast("安装失败:找不到安装包文件");
|
|
|
return;
|
|
|
}
|
|
|
Log.i(TAG, "install id=" + id + " uri=" + apkUri);
|
|
|
@@ -271,6 +290,7 @@ public class AppUpdatePlugin extends Plugin {
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
|
|
|
&& !getContext().getPackageManager().canRequestPackageInstalls()) {
|
|
|
Log.w(TAG, "install blocked: REQUEST_INSTALL_PACKAGES not granted");
|
|
|
+ toast("请先允许安装未知应用");
|
|
|
Intent perm = new Intent(android.provider.Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES);
|
|
|
perm.setData(Uri.parse("package:" + getContext().getPackageName()));
|
|
|
perm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
@@ -286,6 +306,7 @@ public class AppUpdatePlugin extends Plugin {
|
|
|
Log.i(TAG, "install launched");
|
|
|
} catch (Exception e) {
|
|
|
Log.w(TAG, "install failed", e);
|
|
|
+ toast("安装失败:" + e.getClass().getSimpleName());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -454,15 +475,26 @@ public class AppUpdatePlugin extends Plugin {
|
|
|
* 先校验下载状态,确认真的成功了再拉起安装器,避免半截包报错。
|
|
|
*/
|
|
|
int status = downloadStatus(id);
|
|
|
+ /*
|
|
|
+ * 双保险:两条路都走(2026-11-29)
|
|
|
+ *
|
|
|
+ * 复盘:1.0.2 只有 notifyListeners 一条路(前端收到再调 install),
|
|
|
+ * 那时自动弹安装是好的。后来我改成「原生直接安装」,
|
|
|
+ * 把成功分支的 notifyListeners 去掉了 —— 只剩原生一条路。
|
|
|
+ * 原生那条在部分机型拿不到文件或权限被拦,就彻底没反应,
|
|
|
+ * 前端也不知道,连提示都给不了。
|
|
|
+ *
|
|
|
+ * 现在:成功先由原生拉起安装器,同时把事件也发给前端;
|
|
|
+ * 失败只发事件。两条路任一条通,用户就能看到安装界面。
|
|
|
+ * (原生已拉起安装器时,前端再调一次会被系统忽略,无害。)
|
|
|
+ */
|
|
|
if (status == DownloadManager.STATUS_SUCCESSFUL) {
|
|
|
launchInstallById(id);
|
|
|
- } else {
|
|
|
- /* 失败也让前端知道,好给用户提示 */
|
|
|
- JSObject data = new JSObject();
|
|
|
- data.put("id", id);
|
|
|
- data.put("status", status);
|
|
|
- notifyListeners("downloadComplete", data);
|
|
|
}
|
|
|
+ JSObject data = new JSObject();
|
|
|
+ data.put("id", id);
|
|
|
+ data.put("status", status);
|
|
|
+ notifyListeners("downloadComplete", data);
|
|
|
}
|
|
|
};
|
|
|
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
|