diff --git a/powerbell/build.properties b/powerbell/build.properties index 74639e3..37aa41a 100644 --- a/powerbell/build.properties +++ b/powerbell/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Sat Dec 13 21:16:25 HKT 2025 +#Sat Dec 13 18:07:45 GMT 2025 stageCount=2 libraryProject= baseVersion=15.14 publishVersion=15.14.1 -buildCount=0 +buildCount=3 baseBetaVersion=15.14.2 diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/services/ControlCenterService.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/services/ControlCenterService.java index 3c27024..18ab00e 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/services/ControlCenterService.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/services/ControlCenterService.java @@ -262,7 +262,7 @@ public class ControlCenterService extends Service { } NotificationManagerUtils notificationManagerUtils = new NotificationManagerUtils(ControlCenterService.this); Intent intent = new Intent(ControlCenterService.this, MainActivity.class); - notificationManagerUtils.showTempAlertNotify(intent, getString(R.string.app_name), msg); + notificationManagerUtils.showTempAlertNotify(getString(R.string.app_name), msg); diff --git a/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/NotificationManagerUtils.java b/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/NotificationManagerUtils.java index 138c297..dee3f4f 100644 --- a/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/NotificationManagerUtils.java +++ b/powerbell/src/main/java/cc/winboll/studio/powerbell/utils/NotificationManagerUtils.java @@ -22,7 +22,7 @@ import cc.winboll.studio.powerbell.services.ControlCenterService; /** * @Author ZhanGSKen&豆包大模型 * @Date 2025/12/13 20:44 - * @Describe 全局通知管理工具类(整合所有通知能力,适配API29-30,兼容Java7) + * @Describe 全局通知管理工具类(整合所有通知能力,适配API29-30,兼容Java7,所有通知统一跳转MainActivity) */ public class NotificationManagerUtils { // ====================== 常量定义(统一管理,避免冲突,首屏可见)====================== @@ -50,7 +50,7 @@ public class NotificationManagerUtils { ? PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE : PendingIntent.FLAG_UPDATE_CURRENT; // API30安全标志 private static final long[] VIBRATE_PATTERN = new long[]{100, 200, 300, 400}; // 标准震动节奏 - private static final String DEFAULT_JUMP_PACKAGE = "cc.winboll.studio.powerbell"; // 默认跳转包名(API29+必填) + //private static final String DEFAULT_JUMP_PACKAGE = "cc.winboll.studio.powerbell"; // 默认跳转包名(API29+必填) // ====================== 成员变量(按场景分组,私有封装,避免外部篡改)====================== private final Context mContext; @@ -151,21 +151,16 @@ public class NotificationManagerUtils { } /** - * 构建通用跳转PendingIntent(适配API29-30安全规范,支持自定义跳转目标) - * @param targetIntent 自定义跳转意图(传null则默认跳MainActivity) - * @return 安全的PendingIntent,避免跳转失败/泄露 + * 构建固定跳转PendingIntent(所有通知统一跳转MainActivity,适配API29-30安全规范) + * @return 安全的PendingIntent,确保跳转稳定不泄露 */ - private PendingIntent buildPendingIntent(Intent targetIntent) { - Intent intent = targetIntent; - // 传null则默认跳MainActivity(兼容旧逻辑) - if (intent == null) { - intent = new Intent(mContext, MainActivity.class); - LogUtils.d(TAG, "【Intent构建】未传自定义Intent,默认跳转:MainActivity"); - } + private PendingIntent buildFixedPendingIntent() { + // 固定跳MainActivity,不支持自定义目标 + Intent intent = new Intent(mContext, MainActivity.class); // API29+ 强制要求:明确包名,避免跳转目标模糊 - intent.setPackage(DEFAULT_JUMP_PACKAGE); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 确保跳转生效 - LogUtils.d(TAG, "【Intent构建】跳转包名:" + DEFAULT_JUMP_PACKAGE + ",目标:" + intent.getComponent().getClassName()); + intent.setPackage(mContext.getPackageName()); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); // 跳转时清除栈顶,避免重复创建Activity + LogUtils.d(TAG, "【Intent构建】所有通知统一跳转:MainActivity,包名:" + mContext.getPackageName()); PendingIntent pendingIntent = PendingIntent.getActivity( mContext, @@ -200,8 +195,8 @@ public class NotificationManagerUtils { return; } - // 1. 构建跳转Intent - PendingIntent pendingIntent = buildPendingIntent(null); // 默认跳MainActivity + // 1. 构建固定跳转Intent(统一跳MainActivity) + PendingIntent pendingIntent = buildFixedPendingIntent(); // 2. 构建基础通知(兼容API26+渠道,低版本用Builder) Notification.Builder builder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -282,8 +277,8 @@ public class NotificationManagerUtils { LogUtils.e(TAG, "【电量提醒通知】初始化失败:Service/NotificationMessage为空"); return; } - // 1. 构建跳转Intent - PendingIntent pendingIntent = buildPendingIntent(null); + // 1. 构建固定跳转Intent(统一跳MainActivity) + PendingIntent pendingIntent = buildFixedPendingIntent(); // 2. 构建基础通知 Notification.Builder builder; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { @@ -337,19 +332,18 @@ public class NotificationManagerUtils { // ====================== 场景3:通用临时通知(简单文本,自动取消,无需自定义布局)====================== /** - * 显示通用临时通知(普通告警,仅震动,自动取消,支持自定义跳转目标) - * @param targetIntent 自定义跳转Intent(传null默认跳MainActivity) + * 显示通用临时通知(普通告警,仅震动,自动取消,统一跳转MainActivity) * @param title 通知标题 * @param content 通知内容 */ - public void showTempAlertNotify(Intent targetIntent, String title, String content) { + public void showTempAlertNotify(String title, String content) { LogUtils.d(TAG, "【通用临时通知】开始构建,标题:" + title + ",内容:" + content); if (title == null || content == null) { LogUtils.e(TAG, "【通用临时通知】构建失败:标题/内容为空"); return; } - // 1. 构建跳转Intent - PendingIntent pendingIntent = buildPendingIntent(targetIntent); + // 1. 构建固定跳转Intent(统一跳MainActivity) + PendingIntent pendingIntent = buildFixedPendingIntent(); // 2. 用NotificationCompat.Builder(兼容所有版本,简化逻辑) NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, CHANNEL_ID_TEMP_ALERT) .setSmallIcon(R.drawable.ic_launcher) @@ -369,19 +363,18 @@ public class NotificationManagerUtils { // ====================== 场景4:自定义布局通知(灵活扩展,支持复杂样式)====================== /** - * 显示自定义布局通知(支持普通布局+大布局,通用所有场景,可自定义跳转) - * @param targetIntent 自定义跳转Intent + * 显示自定义布局通知(支持普通布局+大布局,通用所有场景,统一跳转MainActivity) * @param contentView 普通自定义布局(必填) * @param bigContentView 下拉大布局(可选) */ - public void showCustomLayoutNotify(Intent targetIntent, RemoteViews contentView, RemoteViews bigContentView) { + public void showCustomLayoutNotify(RemoteViews contentView, RemoteViews bigContentView) { LogUtils.d(TAG, "【自定义布局通知】开始构建,布局ID:" + (contentView != null ? contentView.getLayoutId() : null)); if (contentView == null) { LogUtils.e(TAG, "【自定义布局通知】构建失败:普通布局contentView为空"); return; } - // 1. 构建跳转Intent - PendingIntent pendingIntent = buildPendingIntent(targetIntent); + // 1. 构建固定跳转Intent(统一跳MainActivity) + PendingIntent pendingIntent = buildFixedPendingIntent(); // 2. 构建自定义布局通知 NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext, CHANNEL_ID_TEMP_ALERT) .setSmallIcon(R.drawable.ic_launcher) // 必传,不可省略