Android BroadCast receiver for vibration and silence

I need a wide implementation of the replica receiver, where the user can check whether the phone goes from Ringer mode to silence or quiet to vibrate and vice versa.

int volumeValue = (Integer)intent.getExtras().get("android.media.EXTRA_VOLUME_STREAM_VALUE"); 

I tried this code, but it will not help me, because it gives the same value from the call, so that it is silent and silent, to vibrate, and vice versa. I really want to catch the action when the phone goes from ringer mode to quiet and quiet to vibrate. Thanks in advance

+4
source share
1 answer

Enter this code in your recipient's onCreate () method:

  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 the mainfest file:

 <receiver android:name=".receivers.RingerModeStateChangeReceiver" > <intent-filter> <action android:name="android.media.RINGER_MODE_CHANGED" /> </intent-filter> </receiver> 
+9
source

Source: https://habr.com/ru/post/1435893/


All Articles