获取连接设备的SSID和IP地址(在连接需要获得权限之前)到Android热点(Wifi-tethering)

时间:2012-03-30 06:10:50

标签: android

我想获取试图连接热点的设备的SSID和IP地址。有什么方法可以检查它们并给予许可。

1 个答案:

答案 0 :(得分:-1)

是的,你应该在这样的活动中注册你的广播接收器

BroadcastReceiver receiver = new BroadcastReceiver() {
 @Override
public void onReceive(Context c, Intent intent) {


@Override
  public void onReceive(Context c, Intent intent) {
    List<ScanResult> results = wifiDemo.wifi.getScanResults();
    ScanResult bestSignal = null;
 final String action = intent.getAction();
    if (action.equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)) {
    System.out.println("booladsssssssssssssssssssssssssssssss");
  }
    for (ScanResult result : results) {
      if (bestSignal == null
          || WifiManager.compareSignalLevel(bestSignal.level, result.level) < 0)
        bestSignal = result;
    }

    String message = String.format("%s networks found. %s is the strongest.",
        results.size(), bestSignal.SSID);
    Toast.makeText(wifiDemo, message, Toast.LENGTH_LONG).show();

    Log.d(TAG, "onReceive() message: " + message);
  }

并且您应该将所有这些权限放到您的清单文件中。

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
 <uses-permission android:name="android.permission.UPDATE_DEVICE_STATS"></uses-permission>
 <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"> </uses-permission>
 <uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>

它非常适合我。如果你有嫌疑,请发表评论..谢谢