本文整理汇总了Java中android.net.wifi.WifiManager.WIFI_STATE_UNKNOWN属性的典型用法代码示例。如果您正苦于以下问题:Java WifiManager.WIFI_STATE_UNKNOWN属性的具体用法?Java WifiManager.WIFI_STATE_UNKNOWN怎么用?Java WifiManager.WIFI_STATE_UNKNOWN使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.net.wifi.WifiManager
的用法示例。
在下文中一共展示了WifiManager.WIFI_STATE_UNKNOWN属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onHandleIntent
@Override
protected void onHandleIntent(Intent intent) {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LOWEST);
if (intent == null) {
Utils.debugLog(TAG, "received null Intent, ignoring");
return;
}
Utils.debugLog(TAG, "WiFi change service started, clearing info about wifi state until we have figured it out again.");
NetworkInfo ni = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
wifiManager = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
int wifiState = wifiManager.getWifiState();
if (ni == null || ni.isConnected()) {
Utils.debugLog(TAG, "ni == " + ni + " wifiState == " + printWifiState(wifiState));
if (wifiState == WifiManager.WIFI_STATE_ENABLED
|| wifiState == WifiManager.WIFI_STATE_DISABLING // might be switching to hotspot
|| wifiState == WifiManager.WIFI_STATE_DISABLED // might be hotspot
|| wifiState == WifiManager.WIFI_STATE_UNKNOWN) { // might be hotspot
if (wifiInfoThread != null) {
wifiInfoThread.interrupt();
}
wifiInfoThread = new WifiInfoThread();
wifiInfoThread.start();
}
}
}
示例2: onReceive
@Override
public void onReceive(Context c, Intent intent) {
Bundle bundle = intent.getExtras();
int statusInt = bundle.getInt("wifi_state");
switch (statusInt) {
case WifiManager.WIFI_STATE_UNKNOWN:
break;
case WifiManager.WIFI_STATE_ENABLING:
break;
case WifiManager.WIFI_STATE_ENABLED:
LogUtil.e(TAG, "wifi enable");
startThread();
break;
case WifiManager.WIFI_STATE_DISABLING:
break;
case WifiManager.WIFI_STATE_DISABLED:
LogUtil.e(TAG, "wifi disabled");
break;
default:
break;
}
}
示例3: printWifiState
private String printWifiState(int wifiState) {
switch (wifiState) {
case WifiManager.WIFI_STATE_DISABLED:
return "WIFI_STATE_DISABLED";
case WifiManager.WIFI_STATE_DISABLING:
return "WIFI_STATE_DISABLING";
case WifiManager.WIFI_STATE_ENABLING:
return "WIFI_STATE_ENABLING";
case WifiManager.WIFI_STATE_ENABLED:
return "WIFI_STATE_ENABLED";
case WifiManager.WIFI_STATE_UNKNOWN:
return "WIFI_STATE_UNKNOWN";
}
return null;
}
示例4: onReceive
@Override
public void onReceive(Context context, Intent intent) {
// 这个监听wifi的打开与关闭,与wifi的连接无关
if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {
int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
Log.e(TAG, "wifiState" + wifiState);
switch (wifiState) {
case WifiManager.WIFI_STATE_DISABLED:
Log.d(TAG, "onReceive: WIFI_STATE_DISABLED");
break;
case WifiManager.WIFI_STATE_DISABLING:
break;
case WifiManager.WIFI_STATE_ENABLING:
break;
case WifiManager.WIFI_STATE_ENABLED:
Log.d(TAG, "onReceive: WIFI_STATE_ENABLED");
break;
case WifiManager.WIFI_STATE_UNKNOWN:
break;
default:
break;
}
}
// 这个监听wifi的连接状态即是否连上了一个有效无线路由,当上边广播的状态是WifiManager
// .WIFI_STATE_DISABLING,和WIFI_STATE_DISABLED的时候,根本不会接到这个广播。
// 在上边广播接到广播是WifiManager.WIFI_STATE_ENABLED状态的同时也会接到这个广播,
// 当然刚打开wifi肯定还没有连接到有效的无线
if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(intent.getAction())) {
Parcelable parcelableExtra = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (null != parcelableExtra) {
NetworkInfo networkInfo = (NetworkInfo) parcelableExtra;
NetworkInfo.State state = networkInfo.getState();
boolean isConnected = state == State.CONNECTED;// 当然,这边可以更精确的确定状态
Log.e(TAG, "isConnected" + isConnected);
if (isConnected) {
} else {
}
}
}
// 这个监听网络连接的设置,包括wifi和移动数据的打开和关闭。.
// 最好用的还是这个监听。wifi如果打开,关闭,以及连接上可用的连接都会接到监听。见log
// 这个广播的最大弊端是比上边两个广播的反应要慢,如果只是要监听wifi,我觉得还是用上边两个配合比较合适
if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
ConnectivityManager manager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
Log.i(TAG, "CONNECTIVITY_ACTION");
NetworkInfo activeNetwork = manager.getActiveNetworkInfo();
if (activeNetwork != null) { // connected to the internet
if (activeNetwork.isConnected()) {
if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) {
// connected to wifi
Log.e(TAG, "当前WiFi连接可用 ");
} else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) {
// connected to the mobile provider's data plan
Log.e(TAG, "当前移动网络连接可用 ");
}
} else {
Log.e(TAG, "当前没有网络连接,请确保你已经打开网络 ");
}
Log.e(TAG, "info.getTypeName()" + activeNetwork.getTypeName());
Log.e(TAG, "getSubtypeName()" + activeNetwork.getSubtypeName());
Log.e(TAG, "getState()" + activeNetwork.getState());
Log.e(TAG, "getDetailedState()"+ activeNetwork.getDetailedState().name());
Log.e(TAG, "getDetailedState()" + activeNetwork.getExtraInfo());
Log.e(TAG, "getType()" + activeNetwork.getType());
} else { // not connected to the internet
Log.e(TAG, "当前没有网络连接,请确保你已经打开网络 ");
}
}
}
示例5: wifiStateChangedAction
/**
*
* @param context
* @param intent
* @param action
*/
public static void wifiStateChangedAction(Context context, Intent intent, String action)
{
if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action))
{
// 在此监听wifi有无
int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
switch (wifiState)
{
case WifiManager.WIFI_STATE_DISABLED:
{
Toast.makeText(context, "WIFI_STATE_DISABLED", Toast.LENGTH_LONG).show();
break;
}
case WifiManager.WIFI_STATE_DISABLING:
{
Toast.makeText(context, "WIFI_STATE_DISABLING", Toast.LENGTH_LONG).show();
break;
}
case WifiManager.WIFI_STATE_ENABLED:
{
Toast.makeText(context, "WIFI_STATE_ENABLED", Toast.LENGTH_LONG).show();
break;
}
case WifiManager.WIFI_STATE_ENABLING:
{
Toast.makeText(context, "WIFI_STATE_ENABLING", Toast.LENGTH_LONG).show();
break;
}
case WifiManager.WIFI_STATE_UNKNOWN:
{
Toast.makeText(context, "WIFI_STATE_UNKNOWN", Toast.LENGTH_LONG).show();
break;
}
}
}
}
示例6: onReceive
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
//获取当前的wifi状态int类型数据
int mWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
switch (mWifiState) {
case WifiManager.WIFI_STATE_ENABLED:
//已打开
getWifiList();
break;
case WifiManager.WIFI_STATE_ENABLING:
//打开中
break;
case WifiManager.WIFI_STATE_DISABLED:
//已关闭
break;
case WifiManager.WIFI_STATE_DISABLING:
//关闭中
break;
case WifiManager.WIFI_STATE_UNKNOWN:
//未知
break;
}
} else if (action.equals(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION)) {
int linkWifiResult = intent.getIntExtra(WifiManager.EXTRA_SUPPLICANT_ERROR, 123);
Log.d("XLight", "Get WiFi Result:" + linkWifiResult);
if (linkWifiResult == WifiManager.ERROR_AUTHENTICATING) {
ToastUtil.showToast(getApplicationContext(), "密码错误");
}
} else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {//wifi连接上与否
Log.d("XLight", "网络状态改变");
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
Log.d("XLight", "wifi网络连接断开");
} else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
android.net.wifi.WifiInfo wifiInfo = wifiManager.getConnectionInfo();
//获取当前wifi名称
Log.d("XLight", "连接到网络 " + wifiInfo.getSSID());
}
}
}
示例7: onReceive
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) {
//获取当前的wifi状态int类型数据
int mWifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
switch (mWifiState) {
case WifiManager.WIFI_STATE_ENABLED:
//已打开
getWifiList();
break;
case WifiManager.WIFI_STATE_ENABLING:
//打开中
break;
case WifiManager.WIFI_STATE_DISABLED:
//已关闭
break;
case WifiManager.WIFI_STATE_DISABLING:
//关闭中
break;
case WifiManager.WIFI_STATE_UNKNOWN:
//未知
break;
}
} else if (intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) {//wifi连接上与否
Log.d("XLight", "网络状态改变");
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
Log.d("XLight", "wifi网络连接断开");
} else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
android.net.wifi.WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID();
//获取当前wifi名称
Log.d("XLight", "连接到网络 " + ssid + ssid.contains("Photon-") + ssid.length());
if (ssid.contains("Photon-") && ssid.length() >= 11) {
//连接成功,跳到下一个页面
Intent intent1 = new Intent(getApplicationContext(), BindDeviceWiFiActivity.class);
intent1.putExtra("type", type);
startActivity(intent1);
finish();
}
}
}
}