public class VoiceInteractionService
extends Service
| java.lang.Object | ||||
| android.content.Context | ||||
| android.content.ContextWrapper | ||||
| android.app.Service | ||||
| android.service.voice.VoiceInteractionService | ||||
目前全球语音互动,这是提供hotwording支持的顶级服务,的后端 VoiceInteractor ,等等。当前VoiceInteractionService已经由用户选择保持总是由系统中运行,它允许做一些事情,比如倾听背景中的热词来鼓动语音交互。
由于此服务始终在运行,因此应尽可能保持轻量级。 当实际的语音交互发生时,应该在关联的VoiceInteractionSessionService实现重量级操作(包括显示UI),并且该服务应该在与此服务分开的过程中运行。
常量(Constants) |
|
|---|---|
String |
SERVICE_INTERFACE 必须声明为由服务处理的 |
String |
SERVICE_META_DATA VoiceInteractionService组件发布有关其自身的信息的名称。 |
Inherited constants |
|---|
android.app.Service
|
android.content.Context
|
android.content.ComponentCallbacks2
|
Public constructors |
|
|---|---|
VoiceInteractionService() |
|
公共方法(Public methods) |
|
|---|---|
final AlwaysOnHotwordDetector |
createAlwaysOnHotwordDetector(String keyphrase, Locale locale, AlwaysOnHotwordDetector.Callback callback) 为给定的关键短语和语言环境创建一个 |
int |
getDisabledShowContext() 返回由 |
static boolean |
isActiveService(Context context, ComponentName service) 检查给定的服务组件是否是当前活动的VoiceInteractionService。 |
IBinder |
onBind(Intent intent) 将通信信道返回给服务。 |
void |
onCreate() 服务第一次创建时由系统调用。 |
void |
onLaunchVoiceAssistFromKeyguard() 当用户启动键盘启动来自键盘的语音帮助时调用。 |
void |
onReady() 在服务初始化过程中调用,告诉您系统何时准备好接收来自它的交互。 |
void |
onShutdown() 在服务取消初始化过程中调用以告诉您系统何时关闭服务。 |
void |
setDisabledShowContext(int flags) 设置您始终希望在显示会话时禁用的上下文选项。 |
void |
showSession(Bundle args, int flags) 请求向用户显示关联的 |
Protected methods |
|
|---|---|
void |
dump(FileDescriptor fd, PrintWriter pw, String[] args) 将服务的状态打印到给定的流中。 |
继承方法(Inherited methods) |
|
|---|---|
android.app.Service
|
|
android.content.ContextWrapper
|
|
android.content.Context
|
|
java.lang.Object
|
|
android.content.ComponentCallbacks2
|
|
android.content.ComponentCallbacks
|
|
String SERVICE_INTERFACE
必须声明为由服务处理的Intent 。 为了得到支持,该服务还必须要求BIND_VOICE_INTERACTION权限,以便其他应用程序不能滥用它。
常量值:“android.service.voice.VoiceInteractionService”
String SERVICE_META_DATA
VoiceInteractionService组件发布有关其自身的信息的名称。 这个元数据应该引用包含<标签的XML资源。voice-interaction-service>
常量值:“android.voice_interaction”
AlwaysOnHotwordDetector createAlwaysOnHotwordDetector (String keyphrase, Locale locale, AlwaysOnHotwordDetector.Callback callback)
为给定的关键短语和语言环境创建一个AlwaysOnHotwordDetector 。 这个实例必须被客户保留和使用。 再次调用这个函数会使之前创建的不再用于管理识别的热门词典检测器失效。
| 参数(Parameters) | |
|---|---|
keyphrase |
String: The keyphrase that's being used, for example "Hello Android". |
locale |
Locale: The locale for which the enrollment needs to be performed. |
callback |
AlwaysOnHotwordDetector.Callback: The callback to notify of detection events. |
| 返回(Returns) | |
|---|---|
AlwaysOnHotwordDetector |
An always-on hotword detector for the given keyphrase and locale. |
int getDisabledShowContext ()
返回 setDisabledShowContext(int)设置的值。
| 返回(Returns) | |
|---|---|
int |
|
boolean isActiveService (Context context, ComponentName service)
检查给定的服务组件是否是当前活动的VoiceInteractionService。
| 参数(Parameters) | |
|---|---|
context |
Context
|
service |
ComponentName
|
| 返回(Returns) | |
|---|---|
boolean |
|
IBinder onBind (Intent intent)
将通信信道返回给服务。 如果客户端无法绑定到服务,可能会返回null。 返回IBinder通常是一个复杂的界面已经described using aidl 。
请注意,与其他应用程序组件不同,此处返回的IBinder接口调用可能不会发生在进程的主线程上 。 有关主线程的更多信息可以在Processes and Threads中找到。
| 参数(Parameters) | |
|---|---|
intent |
Intent: The Intent that was used to bind to this service, as given to Context.bindService. Note that any extras that were included with the Intent at that point will not be seen here. |
| 返回(Returns) | |
|---|---|
IBinder |
Return an IBinder through which clients can call on to the service. |
void onLaunchVoiceAssistFromKeyguard ()
当用户启动键盘启动来自键盘的语音帮助时调用。
只有在VoiceInteractionService设置了 supportsLaunchVoiceAssistFromKeyguard并显示键盘 supportsLaunchVoiceAssistFromKeyguard ,才会调用此方法。
有效的实施必须启动一个新的活动,该活动应使用 FLAG_SHOW_WHEN_LOCKED在锁定屏幕上显示。
void onReady ()
在服务初始化过程中调用,告诉您系统何时准备好接收来自它的交互。 通常你应该在这里进行初始化,而不是在onCreate() 。 诸如showSession(Bundle, int)和createAlwaysOnHotwordDetector(String, Locale, AlwaysOnHotwordDetector.Callback)方法在此之前不会运行。
void onShutdown ()
在服务取消初始化过程中调用以告诉您系统何时关闭服务。 此时此服务可能不再是活跃的VoiceInteractionService 。
void setDisabledShowContext (int flags)
设置您始终希望在显示会话时禁用的上下文选项。 这些标志可以是VoiceInteractionSession.SHOW_WITH_ASSIST和VoiceInteractionSession.SHOW_WITH_SCREENSHOT任意组合。
| 参数(Parameters) | |
|---|---|
flags |
int
|
void showSession (Bundle args, int flags)
请求向用户显示关联的 VoiceInteractionSession ,如有必要,启动它。
| 参数(Parameters) | |
|---|---|
args |
Bundle: Arbitrary arguments that will be propagated to the session. |
flags |
int: Indicates additional optional behavior that should be performed. May be any combination of VoiceInteractionSession.SHOW_WITH_ASSIST and VoiceInteractionSession.SHOW_WITH_SCREENSHOT to request that the system generate and deliver assist data on the current foreground app as part of showing the session UI. |
void dump (FileDescriptor fd, PrintWriter pw, String[] args)
将服务的状态打印到给定的流中。 如果您运行“adb shell dumpsys activity service <yourservicename>”(注意,要使此命令生效,服务必须正在运行,并且您必须指定完全限定的服务名称),则会调用此命令。 这与“dumpsys <servicename>”不同,后者仅适用于命名系统服务,并在使用ServiceManager注册的IBinder接口上调用dump(FileDescriptor, String[])方法。
| 参数(Parameters) | |
|---|---|
fd |
FileDescriptor: The raw file descriptor that the dump is being sent to. |
pw |
PrintWriter: The PrintWriter to which you should dump your state. This will be closed for you after you return. |
args |
String: additional arguments to the dump request. |