判断android设备wifi连接状态,判断android设备wifi,添加访问权限(Andro
添加访问权限(AndroidManifest.xml文件里) ```Java代码(MainActivity.java文件)```java package com.example.androidtest; import .ConnectivityManager; import workInfo.State; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.util.Log; import android.view.Menu; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); boolean bFlag = isWifiAvailable(this.getApplicationContext()); if (bFlag) { Log.i("Wifi state - ", "connected"); } else { Log.i("Wifi state - ", "not connected"); } } /** * 判断wifi连接状态 * * @param ctx * @return */ public boolean isWifiAvailable(Context ctx) { ConnectivityManager conMan = (ConnectivityManager) ctx .getSystemService(Context.CONNECTIVITY_SERVICE); State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI) .getState(); if (State.CONNECTED == wifi) { return true; } else { return false; } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } }
如果觉得《android进入wifi权限 判断android设备wifi连接状态 判断android设备wifi 添加访问权限(Andro...》对你有帮助,请点赞、收藏,并留下你的观点哦!