我想檢查它是否連接到WiFi。如果連接,手機保持沉默。當程序運行的應用程序停止工作如何檢查android wifi連接?
ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (mWifi.isConnected()) {
final AudioManager audioManager=
(AudioManager)getSystemService(getApplicationContext().AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
}
else
{
final AudioManager audioManager=
(AudioManager)getSystemService(getApplicationContext().AUDIO_SERVICE);
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}
錯誤帖子堆棧跟蹤 – Rahul
你的問題是什麼? – firegloves
添加錯誤日誌 –