Listener For Media Button (headset-hook) Using Service Without Activity
How can I make service listen for media button (headset-hook) in android device . I try to do that using this code but did not work. Can you help me. Service code: public class RLs
Solution 1:
Your service is expecting an Intent
with the ACTION_MEDIA_BUTTON
Intent
action. You are not starting the service using such an Intent
.
Change:
Intent i=newIntent(RLservice.class.getName());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
arg0.startService(i);
to:
arg1.setClass(this, RLservice.class);
arg0.startService(arg1);
This will effectively "redirect" the broadcast as a command to your service, with the action and extras intact.
Also:
Get rid of
android:process=":remote"
, as it is not necessary here and is user-hostileGet rid of your
<intent-filter>
in your<service>
, unless you intend for a million other apps to be calling this service
Post a Comment for "Listener For Media Button (headset-hook) Using Service Without Activity"