Android的 - 语音控制 - 媒体意图意图、语音、媒体、Android

2023-09-04 06:15:08 作者:艳遇

我刚开始看Android开发,我创建一个小应用程序,它会映射听的意图,以媒体播放器功放(最近发布的API)。 这个程序有没有GUI是mearly语音控制与功放之间的胶水。

I've just started looking at Android development and I'm creating a little application which will map the "Listen to" intent to the media player power amp (recently released api). This app has no gui it is mearly a glue between Voice control and power amp.

我能赶上的意图android.media.action.MEDIA_PLAY_FROM_SEARCH和控制功放,但我的问题是,为了捕捉android.media.action.MEDIA_PLAY_FROM_SEARCH我必须声明我的应用程序作为一个活动,所以当我用语音控制发送屏幕上的意图我的应用程序的负荷。我试图宣布该应用程序为接收器\服务,但我不能让他们捕捉到的意图。

I can catch the intent android.media.action.MEDIA_PLAY_FROM_SEARCH and control power amp but my issue is that in order to capture android.media.action.MEDIA_PLAY_FROM_SEARCH I must declare my app as an activity and so when I use Voice Control to send the intent my app loads on the screen. I have tried to declare the app as a receiver\service but I wasn't able to get them to capture the intent.

如何隐藏在应用程序运行,但仍然抓住这个意图是什么?

How can the app run hidden but still capture this intent?

谢谢,芨芨草。

推荐答案

如果我正确理解你的需求,你不真正需要在您的应用程序的任何活动。只是一类扩展的BroadcastReceiver,并实现了onRecieve(上下文,意图)的方法就可以了。

If I understand your needs correctly, you dont actually need any Activity in your app. Just a class that extends BroadcastReceiver and implements the onRecieve(Context, Intent) method of it.

然后在你的清单,你可以绑定的接收器,你想监听的具体意图。您的应用程序将不与该入口点是需要实现的BroadcastReceiver类的UI启动。

And then in your manifest you can bind that receiver to specific intents you want to listen for. You app will be started without a UI with the entry point being the BroadcastReceiver class you implement.

该清单条目看起来是这样的:

The manifest entries will look something like:

<receiver android:name=".MyBroadcastReceiver">
            <intent-filter>
                <action android:name="com.android.music.metachanged" />
                <action android:name="com.amazon.mp3.metachanged" />
                <!-- <action android:name="com.amazon.mp3.playstatechanged" /> -->
                <!-- <action android:name="com.android.music.playbackcomplete" />-->
                <action android:name="com.android.music.playstatechanged" />
                <action android:name="com.htc.music.metachanged" />
                <!--  <action android:name="com.htc.music.playbackcomplete" />-->
                <!--  <action android:name="com.htc.music.playstatechanged" /> -->
                <action android:name="com.sec.android.app.music.metachanged" /> 
                <action android:name="com.nullsoft.winamp.metachanged" />
                <action android:name="com.nullsoft.winamp.playstatechanged" />  
            </intent-filter>
    </receiver>