diff --git a/src/Notes-master/src/net/micode/notes/sync/SyncWorker.java b/src/Notes-master/src/net/micode/notes/sync/SyncWorker.java index 6a3c398..ee63456 100644 --- a/src/Notes-master/src/net/micode/notes/sync/SyncWorker.java +++ b/src/Notes-master/src/net/micode/notes/sync/SyncWorker.java @@ -300,20 +300,40 @@ public class SyncWorker extends Worker { com.google.gson.JsonArray messages = msgListResp.body().getAsJsonArray("data"); String finalAnswer = null; - // 遍历寻找 role=assistant 且 type=answer 的内容 for (com.google.gson.JsonElement el : messages) { com.google.gson.JsonObject m = el.getAsJsonObject(); - if ("assistant".equals(m.get("role").getAsString()) && - "answer".equals(m.get("type").getAsString())) { + if ("assistant".equals(m.get("role").getAsString()) && "answer".equals(m.get("type").getAsString())) { finalAnswer = m.get("content").getAsString(); break; } } - if (finalAnswer != null && !finalAnswer.isEmpty()) { - // 插入本地数据库并弹通知 - saveChatMessageToLocal(finalAnswer); - AiNotificationHelper.sendAiNotification(getApplicationContext(), finalAnswer); + if (finalAnswer != null) { + // --- 核心手术点:解析 AI 的决策 JSON --- + try { + com.google.gson.JsonObject responseObj = com.google.gson.JsonParser.parseString(finalAnswer).getAsJsonObject(); + + // 只有当 action 为 reply 时才处理 + if (responseObj.has("action") && "reply".equals(responseObj.get("action").getAsString())) { + String assistantMsg = responseObj.get("content").getAsString(); + + // 1. 存入本地数据库 (以便用户进入聊天界面能看到) + saveChatMessageToLocal(assistantMsg); + + // 2. [关键] 调用通知辅助类,弹出手机顶部通知 + // 使用 getApplicationContext() 确保后台上下文安全 + net.micode.notes.tool.AiNotificationHelper.sendAiNotification( + getApplicationContext(), + assistantMsg + ); + + android.util.Log.d("MiChatSync", "AI 决定主动关怀,已发送通知栏提醒"); + } + } catch (Exception e) { + // 兜底逻辑:如果 AI 返回的不是 JSON (可能是纯文本),默认入库并通知 + saveChatMessageToLocal(finalAnswer); + net.micode.notes.tool.AiNotificationHelper.sendAiNotification(getApplicationContext(), finalAnswer); + } } } } diff --git a/src/Notes-master/src/net/micode/notes/tool/ai/CozeClient.java b/src/Notes-master/src/net/micode/notes/tool/ai/CozeClient.java index 12ab6be..b6eebb0 100644 --- a/src/Notes-master/src/net/micode/notes/tool/ai/CozeClient.java +++ b/src/Notes-master/src/net/micode/notes/tool/ai/CozeClient.java @@ -12,7 +12,7 @@ public class CozeClient { private static final String API_TOKEN = "Bearer pat_U2WS2ta9XWxz08ePQNloPw3mHxhmIGDf22ezG5JgyVC3CGrggE4SITQC4jZuIWE8"; // TODO: 填入你的智能体 ID (Bot ID) - public static final String BOT_ID = "7600011117091864585"; + public static final String BOT_ID = "7601104751551660047"; private static CozeApiService apiService; diff --git a/src/Notes-master/src/net/micode/notes/ui/NotesListActivity.java b/src/Notes-master/src/net/micode/notes/ui/NotesListActivity.java index 7de394c..69ffb35 100644 --- a/src/Notes-master/src/net/micode/notes/ui/NotesListActivity.java +++ b/src/Notes-master/src/net/micode/notes/ui/NotesListActivity.java @@ -166,6 +166,15 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe setAppInfoFromRawRes(); AiCareScheduler.scheduleDailyCare(this); + + // [新增] 处理来自 AI 通知栏的跳转请求 + if (getIntent() != null && getIntent().getBooleanExtra("open_nav_ai", false)) { + // 1. 强制选中底部的 AI 助理 Tab + com.google.android.material.bottomnavigation.BottomNavigationView nav = findViewById(R.id.bottom_navigation); + if (nav != null) { + nav.setSelectedItemId(R.id.nav_ai); // 这会自动触发 setupBottomNavigation 里的切换逻辑 + } + } } @Override @@ -975,7 +984,13 @@ public class NotesListActivity extends AppCompatActivity implements OnClickListe @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); - setIntent(intent); + setIntent(intent); // 必加,更新 Intent + + if (intent.getBooleanExtra("open_nav_ai", false)) { + com.google.android.material.bottomnavigation.BottomNavigationView nav = findViewById(R.id.bottom_navigation); + if (nav != null) nav.setSelectedItemId(R.id.nav_ai); + } + startAsyncNotesListQuery(); }