Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
Created June 8, 2016 19:19
Show Gist options
  • Save talhahasanzia/e80840f739ade867792729078ca664a9 to your computer and use it in GitHub Desktop.
Save talhahasanzia/e80840f739ade867792729078ca664a9 to your computer and use it in GitHub Desktop.
Change volume of the phone when connected to a specific wifi
public class WifiTest
{
// ringerMode = AudioManager.RINGER_MODE_SILENT;
// ringerMode = AudioManager.RINGER_MODE_VIBRATE;
// ringerMode = AudioManager.RINGER_MODE_NORMAL;
// WifiName="Home-Wifi";
public static boolean setVolumeWhenThisWifiConnects(String WifiName,int ringerMode)
{
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
if (connectionInfo != null && !StringUtil.isBlank(connectionInfo.getSSID())) {
if(connectionInfo.getSSID()==WifiName)
{
AudioManager myAudioManager;
myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
// set silent mode
myAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment