13
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Wifi取得メモ①

Last updated at Posted at 2016-05-25

とりあえずWifi接続状況を取得したいんや!!

##初期設定
マネージャーの初期設定せんと!

WifiManager manager = (WifiManager)getSystemService(WIFI_SERVICE);
WifiInfo info = manager.getConnectionInfo();

パーミッションも変えな!

AndroidManifest.xml
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>

##データ取得

ようやく値の取得の時間や!

SSID

まずはSSIDの取得やで!

String ssid = String.format("SSID : %s", info.getSSID());

###IPアドレス
次はIPアドレスを取得やで!

int ipAdr = info.getIpAddress();
String ip = String.format("IP Adrress : %02d.%02d.%02d.%02d", (ipAdr>>0)&0xff, (ipAdr>>8)&0xff, (ipAdr>>16)&0xff, (ipAdr>>24)&0xff);

###MACアドレス
やったるで!MACアドレスを取得や!

String mac = String.format("MAC Address : %s", info.getMacAddress());

受信信号強度

最後に受信信号強度&信号レベルを取得やでえ!!

int rssi = info.getRssi();
int level = WifiManager.calculateSignalLevel(rssi, 5);
String rssi = String.format("RSSI : %d / Level : %d/4", rssi, level);

とりあえずこれで終わりや!あとはStringを煮るなり焼くなり好きにしてえや!

13
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?