請查看代碼如何檢測的WiFi連接到設備
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
receiverWifi = new WifiReceiver();
mIntentFilter = new IntentFilter();
final IntentFilter mIFNetwork = new IntentFilter();
mIFNetwork.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION); //"android.net.conn.CONNECTIVITY_CHANGE"
registerReceiver(receiverWifi, mIFNetwork);
// mainWifi.startScan();
haveNetworkConnection() ;
}// end of the function
和
class WifiReceiver extends BroadcastReceiver {
public void onReceive(Context c, Intent intent) {
// Toast.makeText(SecondActivity.this, "Message is show", Toast.LENGTH_LONG).show();
// haveNetworkConnection() ;
boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if (noConnectivity) {
ImageButton b=(ImageButton)findViewById(R.id.button4);
b.setBackgroundResource(R.drawable.lightedbutton_off);
} else {
ImageButton b=(ImageButton)findViewById(R.id.button4);
b.setBackgroundResource(R.drawable.lightedbutton_on);
}
}//
}
我想就當只有設備與無線網絡連接的按鈕,但使用上面的代碼條件成爲真,如果設備也連接邊緣/ gprs 請問我該怎麼做
可能重複的[如何查看是否無線網絡連接在機器人(http://stackoverflow.com/questions/3841317/how-to-see-if-wifi-is-connected-in -android) – 2011-12-16 12:00:36