Execute code when user changes to silent mode in Android

后端 未结 3 1214
离开以前
离开以前 2021-01-29 03:15

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 exe

相关标签:
3条回答
  • 2021-01-29 03:36

    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

    0 讨论(0)
  • 2021-01-29 03:42

    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.

    0 讨论(0)
  • 2021-01-29 03:48

    You can register to listen to the BroadcastAudioManager.RINGER_MODE_CHANGED_ACTION.

    0 讨论(0)
提交回复
热议问题