本文整理匯總了Java中android.net.wifi.WifiManager.WIFI_STATE_ENABLED屬性的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager.WIFI_STATE_ENABLED屬性的具體用法?Java WifiManager.WIFI_STATE_ENABLED怎麽用?Java WifiManager.WIFI_STATE_ENABLED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.net.wifi.WifiManager
的用法示例。
在下文中一共展示了WifiManager.WIFI_STATE_ENABLED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onReceive
@Override
public void onReceive(Context context, @NonNull Intent intent)
{
int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
switch (wifiState)
{
case WifiManager.WIFI_STATE_ENABLED:
wifiStateCallback.onWifiEnabled();
break;
case WifiManager.WIFI_STATE_ENABLING:
break;
case WifiManager.WIFI_STATE_DISABLING:
break;
case WifiManager.WIFI_STATE_DISABLED:
break;
}
}
示例2: isWifiEnabled
public static boolean isWifiEnabled() {
Context myContext = Globals.getContext();
if (myContext == null) {
throw new NullPointerException("Global context is null");
}
WifiManager wifiMgr = (WifiManager) myContext.getSystemService(Context.WIFI_SERVICE);
if (wifiMgr.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
ConnectivityManager connManager = (ConnectivityManager) myContext
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifiInfo = connManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return wifiInfo.isConnected();
} else {
return false;
}
}
示例3: 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();
}
}
}
示例4: handleMessage
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case WifiManager.WIFI_STATE_ENABLED:
LogUtils.d("savor:網絡變為可用");
// 為了解決多次重複發送請求利用延時發送方式
getSmallPlatformUrl();
isWifi = true;
break;
case WifiManager.WIFI_STATE_DISABLED:
wifi.setVisibility(View.INVISIBLE);
isWifi = false;
break;
}
}
示例5: wifiEnable
@Rpc(description = "Turns on Wi-Fi with a 30s timeout.")
public void wifiEnable() throws InterruptedException, WifiManagerSnippetException {
if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED) {
return;
}
// If Wi-Fi is trying to turn off, wait for that to complete before continuing.
if (mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLING) {
if (!Utils.waitUntil(
() -> mWifiManager.getWifiState() == WifiManager.WIFI_STATE_DISABLED,
TIMEOUT_TOGGLE_STATE)) {
Log.e(String.format("Wi-Fi failed to stabilize after %ss.", TIMEOUT_TOGGLE_STATE));
}
}
if (!mWifiManager.setWifiEnabled(true)) {
throw new WifiManagerSnippetException("Failed to initiate enabling Wi-Fi.");
}
if (!Utils.waitUntil(
() -> mWifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED,
TIMEOUT_TOGGLE_STATE)) {
throw new WifiManagerSnippetException(
String.format(
"Failed to enable Wi-Fi after %ss, timeout!", TIMEOUT_TOGGLE_STATE));
}
}
示例6: 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;
}
}
示例7: 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;
}
示例8: handleMessage
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case SENSOR_SHAKE:
exitGameDelayed();
playHammerAnimation();
break;
case EXIT_PRO:
finish();
break;
case WifiManager.WIFI_STATE_ENABLED:
break;
case WifiManager.WIFI_STATE_DISABLED:
mNetWorkSettingsDialog = new CommonDialog(GameActivity.this,"請連接包間wifi","連接後可查看當前酒樓是否有優惠活動"
, new CommonDialog.OnConfirmListener() {
@Override
public void onConfirm() {
Intent intent = new Intent();
intent.setAction("android.net.wifi.PICK_WIFI_NETWORK");
startActivity(intent);
finish();
}
}, new CommonDialog.OnCancelListener() {
@Override
public void onCancel() {
finish();
}
},"去連接");
mNetWorkSettingsDialog.show();
break;
}
}
示例9: isWifiOpen
public static boolean isWifiOpen(Context context) {
WifiManager wifiManager = (WifiManager) context
.getSystemService(Context.WIFI_SERVICE);
int state = wifiManager.getWifiState();
boolean flag = false;
if (state == WifiManager.WIFI_STATE_ENABLED
|| state == WifiManager.WIFI_STATE_ENABLING) {
flag = true;
}
return flag;
}
示例10: updateWiFiState
private void updateWiFiState(int wifiState) {
int state;
int actionState;
switch (wifiState) {
case WifiManager.WIFI_STATE_DISABLING:
state = R.string.txt_status_turning_off;
actionState = STATE_INPROCESS;
break;
case WifiManager.WIFI_STATE_DISABLED:
state = R.string.txt_status_turned_off;
actionState = STATE_DONE;
break;
case WifiManager.WIFI_STATE_ENABLING:
state = R.string.txt_status_turning_on;
actionState = STATE_INPROCESS;
break;
case WifiManager.WIFI_STATE_ENABLED:
state = R.string.txt_status_turned_on;
actionState = STATE_DONE;
break;
default:
state = R.string.txt_status_unknown;
actionState = STATE_DONE;
break;
}
String stateText = mActivity.getString(state);
setActionState(actionState);
// update description
Setting setting = mSetting;
setting.descr = stateText;
setting.checked = wifiState == WifiManager.WIFI_STATE_ENABLED || wifiState == WifiManager.WIFI_STATE_DISABLING;
setting.updateView();
}
示例11: 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, "當前沒有網絡連接,請確保你已經打開網絡 ");
}
}
}
示例12: 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;
}
}
}
}
示例13: onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the stored sort order
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
int sortOrderOrdinal = prefs.getInt(PREF_WIFI_SORT_ORDER, SortOrder
.NONE.ordinal());
if (sortOrderOrdinal >= 0 && sortOrderOrdinal < SortOrder.values()
.length) {
sortOrder = SortOrder.values()[sortOrderOrdinal];
}
// Make a BroadcastReceiver to get the scan results
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
final WifiManager wifi = (WifiManager) getSystemService
(Context.WIFI_SERVICE);
int state = wifi.getWifiState();
if (state != WifiManager.WIFI_STATE_ENABLED) {
Utils.errMsg(WifiActivity.this, "WiFi is not enabled");
return;
}
List<ScanResult> scanResults = wifi.getScanResults();
// Make the ArrayList
mNetworks = new ArrayList<WifiNetwork>(scanResults.size());
for (ScanResult scanResult : scanResults) {
mNetworks.add(new WifiNetwork(scanResult));
}
// Sort the arrays list
Collections.sort(mNetworks);
// Set the adapter
mNetworkListdapter = new NetworkListAdapter();
setListAdapter(mNetworkListdapter);
}
};
registerReceiver(mReceiver, new IntentFilter(
WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
// Call refresh to set the contents
refresh();
}
示例14: checkWifiState
public static boolean checkWifiState(Context context) {
WifiManager wifiManger = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
return wifiManger.getWifiState()==WifiManager.WIFI_STATE_ENABLED;
}
示例15: handleMessage
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case CLOSE_SSDP_SERVICE:
LogUtils.d("savor:ssdp 搜索10秒,關閉ssdp服務");
Intent ssdpIntent = new Intent(mContext, SSDPService.class);
mContext.stopService(ssdpIntent);
break;
case SAVE_BOX_INFO:
Object obj = msg.obj;
if(obj instanceof TvBoxInfo) {
TvBoxInfo tvBoxInfo = (TvBoxInfo) obj;
mSession.setTvBoxUrl(tvBoxInfo);
mBindTvView.initBindcodeResult();
}
break;
case SCAN_QR:
LogUtils.d("二維碼結果:" + msg.obj);
if (TextUtils.isEmpty(msg.obj + "")) {
mViewCallBack.showToast("無效的數字");
return;
}
// 綁定tv
mSession.setTVBoxUrl(msg.obj + "");
mBindTvView.initBindcodeResult();
break;
case START_LINKTV:
if(mBindTvView!=null) {
mBindTvView.closeQrcodeDialog();
String topNameActivity = getTopActivityName(mContext);
if(!topNameActivity.equals(LinkTvActivity.class.getClass().getName())){
mBindTvView.startLinkTv();
}
}
case CLOSE_DIALOG:
if(mBindTvView!=null)
mBindTvView.closeQrcodeDialog();
break;
case CALL_QRCODE:
break;
case CALL_CODE_ERRO:
mViewCallBack.showToast("呼出二維碼網絡超時");
break;
case WifiManager.WIFI_STATE_ENABLED:
LogUtils.d("savor:網絡變為可用");
// 為了解決多次重複發送請求利用延時發送方式
getSmallPlatformUrl(true);
break;
case WifiManager.WIFI_STATE_DISABLED:
LogUtils.d("savor:hotel 網絡不可用重置酒店id為0");
mSession.resetPlatform();
mSession.setHotelid(0);
mSenseView.hideProjection();
stopProAndLink();
break;
case CHECK_PLATFORM:
getSmallPlatformUrl(false);
break;
case GET_SMALL_FLATFORM:
getSmallPlatformUrl(false);
break;
case REMOVE_QRCODE:
mSession.setQrcode(null);
break;
case REMOVE_BOX_INFO:
mSession.setTvBoxUrl(null);
break;
}
}