android特定wifi连接音量下来

时间:2016-06-08 06:10:02

标签: android wifi

我有一个关闭wifi的列表我希望当我连接到特定的wifi我的手机音量自动关闭如何做到这一点我是新的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));
    }
}

这里是wifi的代码,它显示我在列表上我希望当特定的wifi连接时我的手机自动配置文件更改为静音。提前谢谢

1 个答案:

答案 0 :(得分:0)

检查wifi是否已连接:

 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);       

        }
    }

您需要在清单文件中添加Wifi访问状态权限。