I need a broad cast receiver implementation where a user can check whether a phone is going from Ringer mode to silent or silent to vibrate and vice versa.
int volumeValue = (Integer)intent.getExtras().get("android.media.EXTRA_VOLUME_STREAM_VALUE");
I tried this code but it won't me help much because it gives same value from ringer to silent and silent to vibrate and vice versa. I actually want to catch the action when phone go from ringer mode to silent and silent to vibrate Thanks in advance
Write this code in your onCreate() method of receiver:
BroadcastReceiver receiver=new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
//code...
}
};
IntentFilter filter=new IntentFilter(
AudioManager.RINGER_MODE_CHANGED_ACTION);
registerReceiver(receiver,filter);
Also add this to mainfest file:
<receiver android:name=".receivers.RingerModeStateChangeReceiver" >
<intent-filter>
<action android:name="android.media.RINGER_MODE_CHANGED" />
</intent-filter>
</receiver>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With