I have a Broadcast Receiver that listens to Ringer mode change action as follows:
public class RingerModeStateChangeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("RECEIVER", "Ringer Change detected.");
}
}
The manifest declaration is as follows:
<receiver android:name=".receivers.RingerModeStateChangeReceiver" >
<intent-filter>
<action android:name="android.media.RINGER_MODE_CHANGED" />
</intent-filter>
</receiver>
My app changes the Ringer mode by making use of Audio Manager as shown below:
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if(someCondition) {
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
} else {
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
}
Is there a way to detect the ringer change to be coming from Audio Manager(may be by adding some extra content to the audio manager object) in my broadcast receiver?
UPDATE:
I have solved this problem by making use of 2 boolean variables, one representing the updates made to RINGER by some external force and the other representing the updates made by my code. The former is true by default and the later false. The later becomes true only when the update to Ringer is about to be made by my code.
This allows the broadcast receiver to differentiate between external and internal changes made to the RINGER.
Although, this still is a workaround and I am still nowhere close to finding a solution internal to the android system (if at all one does exist).