feat(voice): 完善语音交互服务并添加会话启动与辅助数据处理

This commit is contained in:
TongTongStudio
2026-07-28 22:34:10 +08:00
parent e8be46f1a3
commit 3d7452b20f
4 changed files with 111 additions and 9 deletions

View File

@@ -1,15 +1,61 @@
package com.ttstd.dialer.service;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.service.voice.VoiceInteractionService;
import android.service.voice.VoiceInteractionSession;
import com.ttstd.dialer.utils.Logger;
/**
* 语音交互服务类,作为语音助手的入口。
*/
public class MyVoiceInteractionService extends VoiceInteractionService {
private static final String TAG = "MyVoiceInteractionService";
/**
* 自定义 Action用于从外部启动语音交互会话
*/
public static final String ACTION_SHOW_SESSION = "com.ttstd.dialer.ACTION_SHOW_SESSION";
@Override
public void onCreate() {
super.onCreate();
Logger.d(TAG, "onCreate");
}
@Override
public void onReady() {
super.onReady();
Logger.d(TAG, "onReady");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Logger.d(TAG, "onStartCommand: " + intent);
if (intent != null) {
String action = intent.getAction();
if (ACTION_SHOW_SESSION.equals(action)) {
// 确保服务是当前活跃的语音交互服务
if (isActiveService(this, new ComponentName(this, MyVoiceInteractionService.class))) {
Logger.d(TAG, "Showing session with assist and screenshot flags");
// 核心:调用 showSession 并请求辅助数据AssistStructure和截图
Bundle args = new Bundle();
showSession(args,
VoiceInteractionSession.SHOW_WITH_ASSIST |
VoiceInteractionSession.SHOW_WITH_SCREENSHOT);
} else {
Logger.w(TAG, "Service is not the active voice interaction service");
}
}
}
return START_STICKY;
}
@Override
public void onShutdown() {
super.onShutdown();
Logger.d(TAG, "onShutdown");
}
}