0

I'm using a service. In that service my code should get executed when the user changes to silent mode, i.e. as soon as the user changes to silent mode, my code needs to get executed.

How can I do this?

slhck
  • 36,575
  • 28
  • 148
  • 201
jehan
  • 267
  • 1
  • 4
  • 10

3 Answers3

3

You don't want use a service. Instead you want to use a BroadcastReciever that filters for the android.media.RINGER_MODE_CHANGED Intent.

You might want to take a look at this project as it deals with the phone being silenced. It probably has some source code that will be useful to you.

Kurtis Nusbaum
  • 30,445
  • 13
  • 78
  • 102
  • thanks Kurits Nusbaum.is it possible to run a code as soon as the user turns on the silent mode – jehan Oct 20 '11 at 03:50
  • @jehan Welcome to StackOverflow. If you find a particular post useful or helpful. Please vote it up. If you think a particular answer is right, please accept it. It is indeed possible to run arbitrary code when the user goes into silent mode. You'd just check if the Intent you received in your BroadcastReciever tells you whether or not the volume is now set to muted. If so, run what ever code you want. – Kurtis Nusbaum Oct 20 '11 at 03:54
  • how to view code from apk file?? i installed the file,the what do I do ? – jehan Oct 20 '11 at 04:00
  • 1
    @jehan If you have other questions not related to the one you asked here, please start a new question. – Kurtis Nusbaum Oct 20 '11 at 04:02
2

You can register to listen to the BroadcastAudioManager.RINGER_MODE_CHANGED_ACTION.

Giohji
  • 714
  • 7
  • 12
0

In your manifest file you can register the intent like this

<intent-filter>

                <action android:name="android.media.RINGER_MODE_CHANGED"  />
                          </intent-filter>

And then recieve the intent at method

public void onReceive(Context context, Intent intent) 

of class that extends BroadcastReceiver class

vincent mathew
  • 4,278
  • 3
  • 27
  • 34