安卓手机获取当前连接的WIFI相关信息

package com.lenovo.xiaoshan.test;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.widget.TextView;

/**
 * 获取手机WIFI的MAC地址
 * @author 单红宇
 *
 */
public class GetmacipinfoActivity extends Activity {
	/** Called when the activity is first created. */
	private static final int REQUEST_ENABLE_BT = 3;
	private WifiManager mWifi;
	private BluetoothAdapter bAdapt;
	private String btMac;
	private String WifiMac;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		mWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);

		if (!mWifi.isWifiEnabled()) {
			mWifi.setWifiEnabled(true);
		}

		WifiInfo wifiInfo = mWifi.getConnectionInfo();

		bAdapt = BluetoothAdapter.getDefaultAdapter();

		if (bAdapt != null) {
			if (!bAdapt.isEnabled()) {
				Intent enBT = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
				startActivityForResult(enBT, REQUEST_ENABLE_BT);
			}

			btMac = bAdapt.getAddress();
		} else {
			btMac = "No Bluetooth Device!";
		}

		if ((WifiMac = wifiInfo.getMacAddress()) == null) {
			WifiMac = "No Wifi Device";
		}

		TextView mac = (TextView) findViewById(R.id.macView);
		mac.setTextSize(16);
		
//		查看已经连接上的WIFI信息,在Android的SDK中为我们提供了一个叫做WifiInfo的对象,这个对象可以通过WifiManager.getConnectionInfo()来获取。WifiInfo中包含了当前连接中的相关信息。
//		getBSSID()  获取BSSID属性
//		getDetailedStateOf()  获取客户端的连通性
//		getHiddenSSID()  获取SSID 是否被隐藏
//		getIpAddress()  获取IP 地址
//		getLinkSpeed()  获取连接的速度
//		getMacAddress()  获取Mac 地址
//		getRssi()  获取802.11n 网络的信号
//		getSSID()  获取SSID
//		getSupplicanState()  获取具体客户端状态的信息
		StringBuffer sb = new StringBuffer();
		sb.append("\n获取BSSID属性(所连接的WIFI设备的MAC地址):" + wifiInfo.getBSSID());
//		sb.append("getDetailedStateOf()  获取客户端的连通性:");
		sb.append("\n\n获取SSID 是否被隐藏:"+ wifiInfo.getHiddenSSID());
		sb.append("\n\n获取IP 地址:" + wifiInfo.getIpAddress());
		sb.append("\n\n获取连接的速度:" + wifiInfo.getLinkSpeed());
		sb.append("\n\n获取Mac 地址(手机本身网卡的MAC地址):" + WifiMac);
		sb.append("\n\n获取802.11n 网络的信号:" + wifiInfo.getRssi());
		sb.append("\n\n获取SSID(所连接的WIFI的网络名称):" + wifiInfo.getSSID());
		sb.append("\n\n获取具体客户端状态的信息:" + wifiInfo.getSupplicantState());
		mac.setText("WIFI网络信息:  " + sb.toString() + "\n\n蓝牙MAC:  " + btMac);
	}
}
引用自:http://blog.csdn.net/catoop/article/details/7445860

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值