本文整理匯總了Java中android.net.wifi.WifiManager.getConnectionInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java WifiManager.getConnectionInfo方法的具體用法?Java WifiManager.getConnectionInfo怎麽用?Java WifiManager.getConnectionInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.net.wifi.WifiManager
的用法示例。
在下文中一共展示了WifiManager.getConnectionInfo方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: checkWifiLinked
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
* 檢查是否在同一wifi,如果三分鍾內連接到同一wifi提示連接成功
*/
protected void checkWifiLinked(TvBoxInfo tvBoxInfo) {
String ssid = tvBoxInfo.getSsid();
String localSSid = WifiUtil.getWifiName(this);
if(!TextUtils.isEmpty(ssid)) {
LogUtils.d(ConstantValues.LOG_CHECKWIFI_PREFIX+" 當前wifi"+localSSid+",需要連接wifi"+ssid);
WifiManager wifiManger = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManger.getConnectionInfo();
String localIp = intToIp(wifiInfo.getIpAddress());
String ipStr = tvBoxInfo.getBox_ip();
if(ssid.endsWith(localSSid)&&!TextUtils.isEmpty(localSSid)&&!localIp.substring(0,localIp.lastIndexOf(".")).equals(ipStr.substring(0, ipStr.lastIndexOf(".")))) {
LogUtils.d(ConstantValues.LOG_CHECKWIFI_PREFIX+" 連接到指定wifi,綁定成功取消檢測");
mSession.setWifiSsid(ssid);
mSession.setTvBoxUrl(tvBoxInfo);
initBindcodeResult();
mHandler.removeMessages(CANCEL_CHECK_WIFI);
mHandler.sendEmptyMessage(CANCEL_CHECK_WIFI);
}else {
LogUtils.d(ConstantValues.LOG_CHECKWIFI_PREFIX+" 當前未連接wifi,繼續檢測...");
startCheckWifiLinkedTimer();
}
}else {
// 每隔一秒檢測是否已連接同一wifi
startCheckWifiLinkedTimer();
}
}
示例2: getDeviceIpAddress
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
private InetAddress getDeviceIpAddress(WifiManager wifi) {
InetAddress result = null;
try {
// default to Android localhost
result = InetAddress.getByName("10.0.0.2");
// figure out our wifi address, otherwise bail
WifiInfo wifiinfo = wifi.getConnectionInfo();
int intaddr = wifiinfo.getIpAddress();
byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff), (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) };
result = InetAddress.getByAddress(byteaddr);
} catch (UnknownHostException e) {
e.printStackTrace();
Log.e(TAG, "getDeviceIpAddress Error: " + e.getMessage());
}
return result;
}
示例3: getSSID
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public String getSSID() {
WifiManager wifiManager = (WifiManager) getSystemService("wifi");
if (wifiManager == null) {
return null;
}
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
if (connectionInfo == null) {
return null;
}
String ssid = connectionInfo.getSSID();
if (ssid == null) {
ssid = null;
}
return ssid;
}
示例4: getWifiAddress
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static String getWifiAddress(Context context) {
WifiManager wifiMgr = (WifiManager) context.getApplicationContext().getSystemService(WIFI_SERVICE);
if(wifiMgr == null){
return null;
}
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
return Formatter.formatIpAddress(ip);
}
示例5: getLocalIpAddress
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
* 獲取本地Ip地址
*
* @param context
* @return
*/
public static String getLocalIpAddress(Context context) {
try {
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
int ipAddress = info.getIpAddress();
String Ipv4Address = InetAddress
.getByName(
String.format("%d.%d.%d.%d", (ipAddress & 0xff),
(ipAddress >> 8 & 0xff),
(ipAddress >> 16 & 0xff),
(ipAddress >> 24 & 0xff))).getHostAddress()
.toString();
return Ipv4Address;
} catch (Exception e) {
e.printStackTrace();
JLog.e(e.toString());
}
return null;
}
示例6: a
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static String a() {
try {
Context context = Global.getContext();
if (context == null) {
return "";
}
WifiManager wifiManager = (WifiManager) context.getSystemService("wifi");
if (wifiManager == null) {
return "";
}
WifiInfo connectionInfo = wifiManager.getConnectionInfo();
if (connectionInfo == null) {
return "";
}
return connectionInfo.getMacAddress();
} catch (Throwable e) {
f.b("MobileInfoUtil", "getLocalMacAddress>>>", e);
return "";
}
}
示例7: getConnectWifiSsid
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
* 獲取連接的wifi的名稱
*
* @param context
* @return
*/
public static String getConnectWifiSsid(Context context)
{
if (isWifiConnect(context))
{
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
if (wifiManager != null)
{
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo != null)
{
return wifiInfo.getSSID();
}
}
}
return "";
}
示例8: onReceive
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
WifiManager wifiManager = (WifiManager) context
.getSystemService(context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
if (wifiInfo.getBSSID() != null) {
// wifi信號強度
int signalLevel = WifiManager.calculateSignalLevel(
wifiInfo.getRssi(), 4);
if (signalLevel == 0) {
imgNetWorkState.setImageDrawable(context.getResources()
.getDrawable(R.drawable.wifi_1));
} else if (signalLevel == 1) {
imgNetWorkState.setImageDrawable(context.getResources()
.getDrawable(R.drawable.wifi_2));
} else if (signalLevel == 2) {
imgNetWorkState.setImageDrawable(context.getResources()
.getDrawable(R.drawable.wifi_3));
} else if (signalLevel == 3) {
imgNetWorkState.setImageDrawable(context.getResources()
.getDrawable(R.drawable.networkstate_on));
}
if (d)
Toast.makeText(context, "wifi level" + signalLevel,
Toast.LENGTH_SHORT).show();
}
}
示例9: getConnectWifiIp
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
* 獲取當前連接wifi的名稱
*
* @return
*/
public static String getConnectWifiIp(Context context) {
if (isWifiConnected(context)) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
if (ipAddress == 0) {
return null;
}
return ((ipAddress & 0xff) + "." + (ipAddress >> 8 & 0xff) + "."
+ (ipAddress >> 16 & 0xff) + "." + (ipAddress >> 24 & 0xff));
}
return null;
}
示例10: getConnectWifiSsid
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
* 獲取當前連接wifi的名稱
*
* @return
*/
public static String getConnectWifiSsid(Context context) {
if (isWifiConnected(context)) {
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
return wifiInfo.getSSID();
}
return null;
}
示例11: getMacAddress
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
* 獲取 MAC 地址
* <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
*/
public static String getMacAddress(Context context) {
//wifi mac地址
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
String mac = info.getMacAddress();
JLog.i(" MAC:" + mac);
return mac;
}
示例12: isWifiConnected
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
* Checks if WiFi is enabled and connected to a network.
* <b>Note</b>: This does not check access to the Internet.
*
* @param context Which context to use to check
* @return {@code True} if WiFi is enabled and connected to a network, {@code false} otherwise
*/
@RequiresPermission(Manifest.permission.ACCESS_WIFI_STATE)
public static boolean isWifiConnected(@NonNull final Context context) {
final WifiManager wiFiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
if (wiFiManager != null && wiFiManager.isWifiEnabled()) {
// Wi-Fi adapter is ON
final WifiInfo wifiInfo = wiFiManager.getConnectionInfo();
return wifiInfo != null && wifiInfo.getNetworkId() != -1;
} else {
// Wi-Fi adapter is OFF
return false;
}
}
示例13: getLocalMacAddress
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
/**
* 獲取Mac地址
*
* @param activity
* @return
*/
public static String getLocalMacAddress(Activity activity) {
WifiManager wifi = (WifiManager) activity.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wifi.getConnectionInfo();
String mac = info.getMacAddress();
return mac;
}
示例14: getIp
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static String getIp(Context context) {
int networkType = getNetworkType(context);
if (networkType == ConnectivityManager.TYPE_WIFI) {
WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
return (ipAddress & 0xFF) + "." +
((ipAddress >> 8) & 0xFF) + "." +
((ipAddress >> 16) & 0xFF) + "." +
(ipAddress >> 24 & 0xFF);
} else {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return null;
}
}
示例15: getIPAddress
import android.net.wifi.WifiManager; //導入方法依賴的package包/類
public static String getIPAddress(Context context) {
NetworkInfo info = ((ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info != null && info.isConnected()) {
if (info.getType() == ConnectivityManager.TYPE_MOBILE) {//當前使用2G/3G/4G網絡
try {
//Enumeration<NetworkInterface> en=NetworkInterface.getNetworkInterfaces();
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements(); ) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
return inetAddress.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
} else if (info.getType() == ConnectivityManager.TYPE_WIFI) {//當前使用無線網絡
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ipAddress = intIP2StringIP(wifiInfo.getIpAddress());//得到IPV4地址
return ipAddress;
}
} else {
//當前無網絡連接,請在設置中打開網絡
}
return null;
}