-
wifi 신호세기 확인안드로이드(이클립스)/막 써 2016. 1. 1. 19:58반응형
package com.example.testandroid;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class MainActivity extends Activity {
private static final String LOG_TAG = "LOG";
private TextView tvRssi;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// wifi신호강도(세기)(RSSI(received signal strength indication)) 측정
tvRssi = (TextView) findViewById(R.id.tvRssi);
registerReceiver(rssiReceiver, new IntentFilter(WifiManager.RSSI_CHANGED_ACTION));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
// wifi RSSI Receiver
private BroadcastReceiver rssiReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.e(LOG_TAG, "Time rssiReceiver");
WifiManager wman = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo info = wman.getConnectionInfo();
int _rssi = info.getRssi();
tvRssi.setText(_rssi + "");
Log.e(LOG_TAG, "_rssi ==> " + _rssi);
}
};
}
메니페스트에 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 추가
반응형'안드로이드(이클립스) > 막 써' 카테고리의 다른 글
서비스 실행 여부 확인 (0) 2016.03.24 화면 비율 (0) 2016.03.21 findViewById 여러개 한번에 하기 (0) 2015.12.24 로그 한번에 끄기 켜기 (0) 2015.12.23 replace와 replaceAll (0) 2015.11.27