diff --git a/appbase/build.properties b/appbase/build.properties index 426c33b3..43b7b4d9 100644 --- a/appbase/build.properties +++ b/appbase/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Sun Nov 30 08:12:09 GMT 2025 +#Sun Nov 30 08:19:07 GMT 2025 stageCount=4 libraryProject=libappbase baseVersion=15.11 publishVersion=15.11.3 -buildCount=2 +buildCount=3 baseBetaVersion=15.11.4 diff --git a/libappbase/build.properties b/libappbase/build.properties index 426c33b3..43b7b4d9 100644 --- a/libappbase/build.properties +++ b/libappbase/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Sun Nov 30 08:12:09 GMT 2025 +#Sun Nov 30 08:19:07 GMT 2025 stageCount=4 libraryProject=libappbase baseVersion=15.11 publishVersion=15.11.3 -buildCount=2 +buildCount=3 baseBetaVersion=15.11.4 diff --git a/libappbase/src/main/java/cc/winboll/studio/libappbase/utils/CrashHandleNotifyUtils.java b/libappbase/src/main/java/cc/winboll/studio/libappbase/utils/CrashHandleNotifyUtils.java index ea98fab6..8faade8f 100644 --- a/libappbase/src/main/java/cc/winboll/studio/libappbase/utils/CrashHandleNotifyUtils.java +++ b/libappbase/src/main/java/cc/winboll/studio/libappbase/utils/CrashHandleNotifyUtils.java @@ -8,13 +8,14 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import cc.winboll.studio.libappbase.CrashHandler; +import cc.winboll.studio.libappbase.GlobalCrashActivity; import cc.winboll.studio.libappbase.LogUtils; /** * @Author ZhanGSKen&豆包大模型 * @Date 2025/11/29 21:12 * @Describe 应用崩溃处理通知实用工具集 - * 核心功能:应用崩溃时捕获错误日志,发送通知到系统通知栏(3行内容省略),点击通知跳转应用主界面 + * 核心功能:应用崩溃时捕获错误日志,发送通知到系统通知栏(3行内容省略),点击通知跳转 GlobalCrashActivity 并传递日志 */ public class CrashHandleNotifyUtils { @@ -53,7 +54,7 @@ public class CrashHandleNotifyUtils { return; } - // 3. 发送崩溃通知到通知栏(3行省略,无复制按钮) + // 3. 发送崩溃通知到通知栏(3行省略,点击跳转 GlobalCrashActivity) sendCrashNotification(app, appName, errorLog); } @@ -76,10 +77,10 @@ public class CrashHandleNotifyUtils { } /** - * 发送崩溃通知到系统通知栏(移除复制按钮,仅显示3行内容) + * 发送崩溃通知到系统通知栏(移除复制按钮,点击跳转 GlobalCrashActivity) * @param context 上下文(Application 实例,确保后台也能发送) * @param title 通知标题(应用名称) - * @param content 通知内容(崩溃日志) + * @param content 通知内容(崩溃日志,需传递给 GlobalCrashActivity) */ private static void sendCrashNotification(Context context, String title, String content) { // 1. 获取通知管理器(系统服务,用于发送/管理通知) @@ -94,15 +95,15 @@ public class CrashHandleNotifyUtils { createCrashNotifyChannel(notificationManager); } - // 3. 构建通知意图(仅保留:点击通知跳转主界面) - PendingIntent launchPendingIntent = getLaunchPendingIntent(context); // 主界面跳转意图 + // 3. 构建通知意图(核心修改:点击跳转 GlobalCrashActivity,传递崩溃日志) + PendingIntent jumpIntent = getGlobalCrashPendingIntent(context, content); // 跳转崩溃详情页意图 // 4. 构建通知实例(移除复制按钮,仅保留3行内容省略) - Notification notification = buildNotification(context, title, content, launchPendingIntent); + Notification notification = buildNotification(context, title, content, jumpIntent); // 5. 发送通知(指定通知ID,重复发送同ID会覆盖原通知) notificationManager.notify(CRASH_NOTIFY_ID, notification); - LogUtils.d(TAG, "崩溃通知发送成功:标题=" + title + ",内容长度=" + content.length() + "字符"); + LogUtils.d(TAG, "崩溃通知发送成功:标题=" + title + ",内容长度=" + content.length() + "字符(点击跳转崩溃详情页)"); } /** @@ -120,7 +121,7 @@ public class CrashHandleNotifyUtils { NotificationManager.IMPORTANCE_DEFAULT // 重要性:默认(不会弹窗,有声音提示) ); // 可选:设置渠道描述(用户在设置中可见) - channel.setDescription("用于显示应用崩溃信息"); + channel.setDescription("用于显示应用崩溃信息,点击查看详情"); // 注册通知渠道到系统 notificationManager.createNotificationChannel(channel); LogUtils.d(TAG, "崩溃通知渠道创建成功:" + CRASH_NOTIFY_CHANNEL_ID); @@ -128,19 +129,19 @@ public class CrashHandleNotifyUtils { } /** - * 构建通知点击跳转意图(跳转应用主界面) + * 核心修改:构建跳转 GlobalCrashActivity 的意图(传递崩溃日志) + * 与 GlobalCrashActivity 的日志接收键(EXTRA_CRASH_INFO)保持一致 * @param context 上下文 - * @return 主界面跳转 PendingIntent + * @param errorLog 崩溃日志(需传递给 GlobalCrashActivity) + * @return 跳转崩溃详情页的 PendingIntent */ - private static PendingIntent getLaunchPendingIntent(Context context) { - // 1. 获取应用主界面 Intent(从包名启动默认 launcher Activity) - Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage( - context.getPackageName() - ); - if (launchIntent == null) { - // 异常处理:若主界面 Intent 为空,创建空意图(避免崩溃) - launchIntent = new Intent(); - } + private static PendingIntent getGlobalCrashPendingIntent(Context context, String errorLog) { + // 1. 构建跳转 GlobalCrashActivity 的显式意图 + Intent crashIntent = new Intent(context, GlobalCrashActivity.class); + // 传递崩溃日志(键:EXTRA_CRASH_INFO,与 GlobalCrashActivity 一致) + crashIntent.putExtra(CrashHandler.EXTRA_CRASH_INFO, errorLog); + // 设置意图标志:确保 Activity 正常启动,避免重复创建 + crashIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); // 2. 构建 PendingIntent(延迟执行的意图) int flags = PendingIntent.FLAG_UPDATE_CURRENT; @@ -151,8 +152,8 @@ public class CrashHandleNotifyUtils { return PendingIntent.getActivity( context, - 0, // 请求码(可忽略) - launchIntent, + CRASH_NOTIFY_ID, // 用通知ID作为请求码,确保唯一(避免意图复用) + crashIntent, flags ); } @@ -162,10 +163,10 @@ public class CrashHandleNotifyUtils { * @param context 上下文 * @param title 通知标题(应用名称) * @param content 通知内容(崩溃日志) - * @param launchPendingIntent 通知点击跳转意图 + * @param jumpIntent 通知点击跳转意图(跳转 GlobalCrashActivity) * @return 构建完成的 Notification 对象 */ - private static Notification buildNotification(Context context, String title, String content, PendingIntent launchPendingIntent) { + private static Notification buildNotification(Context context, String title, String content, PendingIntent jumpIntent) { // 兼容 Android 8.0+:指定通知渠道ID Notification.Builder builder = new Notification.Builder(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -182,9 +183,9 @@ public class CrashHandleNotifyUtils { // 配置通知核心参数(移除复制按钮相关代码) builder .setSmallIcon(context.getApplicationInfo().icon) // 通知小图标(必需,否则通知不显示) - .setContentTitle(title) // 通知主标题(应用名称) + .setContentTitle(title + " 崩溃") // 优化标题:明确标识“崩溃” .setContentText(getShortContent(content)) // 核心:3行内缩略文本 - .setContentIntent(launchPendingIntent) // 通知主体点击跳转主界面 + .setContentIntent(jumpIntent) // 通知主体点击跳转 GlobalCrashActivity .setAutoCancel(true) // 点击通知后自动取消 .setWhen(System.currentTimeMillis()) // 通知创建时间 .setPriority(Notification.PRIORITY_DEFAULT); // 通知优先级