2

i have a list off wifi i want when i conected to specific wifi my phone volume auto down how to do this i am new in android

private class WifiScanReceiver extends BroadcastReceiver{
    public void onReceive(Context c, Intent intent) {
        List<ScanResult> wifiScanList = wifi.getScanResults();
        wifis = new String[wifiScanList.size()];

        for(int i = 0; i < wifiScanList.size(); i++){
            wifis[i] = ((wifiScanList.get(i)).toString());
        }
        lv.setAdapter(new ArrayAdapter<String>(getApplicationContext(),android.R.layout.simple_list_item_1,wifis));
    }
}

here is the code of wifi which show me on list i want when specific wifi is connected my phone auto profile change to silent . thanks in advance

faisal iqbal
  • 724
  • 1
  • 8
  • 20

1 Answers1

0

To check if wifi is connected:

 WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
 WifiInfo connectionInfo = wifiManager.getConnectionInfo();


    if (connectionInfo != null && !StringUtil.isBlank(connectionInfo.getSSID())) {

        if(connectionInfo.getSSID()=="MyWifiName")
        {
            AudioManager myAudioManager;
            myAudioManager =  (AudioManager)getSystemService(Context.AUDIO_SERVICE);
            // set silent mode 
            myAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);       

        }
    }

You will need to add Wifi Access State permission in manifest file.

Talha
  • 903
  • 8
  • 31
  • like i want only my home wifi is connected volume auto increase and when iam out of home volume auto decrease – faisal iqbal Jun 08 '16 at 07:19
  • only i can use my wifi name just? – faisal iqbal Jun 08 '16 at 07:25
  • Dude, you can specify any wifi name, just set that YourWifiName string value to your desired name. – Talha Jun 08 '16 at 07:31
  • See updated answer, it has fixed wifi connection check code and also setting silent mode code, accept as answer if this solved your problem. – Talha Jun 08 '16 at 19:04
  • Try to google out "how can we get string from edittext?" , you will get your answers immediately for these simple questions. [Hint: EditText has getText() and setText() methods] :) – Talha Jun 09 '16 at 04:52