如果wifi网络在android中不可用,有人可以告诉我如何向用户发送通知吗?有人可以提供例子吗?

谢谢

最佳答案

Here is a tutorial to do this, it can do these things:


设备上是否可以使用WiFi
WiFi是否启用WiFi
连接到接入点


要点是:

private class ConnectionChangeReceiver extends BroadcastReceiver {
public void onReceive( Context context, Intent intent ) {
Log.d(tag, "Inside Broadcast Reciever");
CheckWifiStatus();
}
}

private void RegisterWifiWatcher()
{
    if(wifiWatcher == null)
    wifiWatcher = new ConnectionChangeReceiver();

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
    intentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
    intentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    intentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
    registerReceiver(wifiWatcher, intentFilter);
}

关于android - 如果wifi网络在Android中不可用,如何向用户发出通知,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7927315/

10-10 10:18