开发者

Android - Voice Control - Media Intent

开发者 https://www.devze.com 2023-02-23 19:50 出处:网络
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).

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.

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 开发者_如何学Goa 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?

Thanks, Ger.


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.

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消