diff --git a/app/build.gradle b/app/build.gradle index 640cfc2..f530f37 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -183,15 +183,12 @@ android { applicationVariants.all { variant -> variant.outputs.each { output -> def buildType = variant.buildType.name - def fileName = "" if (buildType.contains("debug")) { - fileName = "${appName()}_V${defaultConfig.versionName}_${releaseTime()}.apk" + output.outputFileName = "${appName()}_V${defaultConfig.versionName}_${releaseTime()}.apk" } else { - fileName = "${appName()}_${variant.versionCode}_V${variant.versionName}_${releaseTime()}_${buildType}.apk" + output.outputFileName = "${appName()}_${variant.versionCode}_V${variant.versionName}_${releaseTime()}_${buildType}.apk" } - - output.outputFileName = fileName } } } diff --git a/app/src/main/java/com/ttstd/dialer/service/MyVoiceInteractionService.java b/app/src/main/java/com/ttstd/dialer/service/MyVoiceInteractionService.java index e9930e9..4f1ce4d 100644 --- a/app/src/main/java/com/ttstd/dialer/service/MyVoiceInteractionService.java +++ b/app/src/main/java/com/ttstd/dialer/service/MyVoiceInteractionService.java @@ -29,11 +29,14 @@ public class MyVoiceInteractionService extends VoiceInteractionService { public void onReady() { super.onReady(); Logger.d(TAG, "onReady"); + // 服务准备就绪,通常在此之后可以开启 Session 获取界面信息 } @Override public int onStartCommand(Intent intent, int flags, int startId) { - Logger.d(TAG, "onStartCommand: " + intent); + Logger.d(TAG, "onStartCommand: action=" + (intent != null ? intent.getAction() : "null")); + // 如果需要主动触发获取界面信息,可以调用 showSession + // 这会触发 MyVoiceInteractionSessionService 创建 Session,并回调 onHandleAssist if (intent != null) { String action = intent.getAction(); if (ACTION_SHOW_SESSION.equals(action)) { @@ -44,7 +47,7 @@ public class MyVoiceInteractionService extends VoiceInteractionService { Bundle args = new Bundle(); showSession(args, VoiceInteractionSession.SHOW_WITH_ASSIST | - VoiceInteractionSession.SHOW_WITH_SCREENSHOT); + VoiceInteractionSession.SHOW_WITH_SCREENSHOT); } else { Logger.w(TAG, "Service is not the active voice interaction service"); } diff --git a/app/src/main/java/com/ttstd/dialer/service/MyVoiceInteractionSession.java b/app/src/main/java/com/ttstd/dialer/service/MyVoiceInteractionSession.java index 27a06d2..9c709c4 100644 --- a/app/src/main/java/com/ttstd/dialer/service/MyVoiceInteractionSession.java +++ b/app/src/main/java/com/ttstd/dialer/service/MyVoiceInteractionSession.java @@ -36,8 +36,13 @@ public class MyVoiceInteractionSession extends VoiceInteractionSession { @Override public void onHandleAssist(Bundle data, AssistStructure structure, AssistContent content) { super.onHandleAssist(data, structure, content); - Logger.d(TAG, "onHandleAssist: data=" + data); - processAssistStructure(structure); + // 这是核心方法,structure 包含了整个屏幕的 View 树 + Logger.d(TAG, "onHandleAssist"); + if (structure != null) { + processAssistStructure(structure); + } else { + Logger.w(TAG, "AssistStructure is null"); + } } // Android 12 (API 31) 及以上建议使用此方法 @@ -50,12 +55,6 @@ public class MyVoiceInteractionSession extends VoiceInteractionSession { } } - @Override - public void onHandleScreenshot(@Nullable Bitmap screenshot) { - super.onHandleScreenshot(screenshot); - Logger.d(TAG, "onHandleScreenshot: " + (screenshot != null ? "has screenshot" : "null")); - } - private void processAssistStructure(AssistStructure structure) { if (structure == null) { Logger.w(TAG, "AssistStructure is null"); @@ -76,10 +75,10 @@ public class MyVoiceInteractionSession extends VoiceInteractionSession { private void traverseNode(AssistStructure.ViewNode node, String prefix) { if (node == null) return; + Logger.d(TAG, prefix + "View: text=" + node.getText() + ", id=" + node.getIdEntry()); CharSequence text = node.getText(); String id = node.getIdEntry(); String className = node.getClassName(); - if (text != null || id != null) { Logger.d(TAG, prefix + "View: class=" + className + ", text=" + text + ", id=" + id); } @@ -91,7 +90,7 @@ public class MyVoiceInteractionSession extends VoiceInteractionSession { @Override public View onCreateContentView() { - // 返回一个空的 View,以确保 Session 能够正确显示 - return new View(getContext()); + // 可以返回一个自定义布局,用于在屏幕上显示助手界面 + return super.onCreateContentView(); } }