Androidで周囲のAPをスキャンして表示するプログラムを作っています。
取得したものをデータベースに保存して残すようにしたいのです。
http://www.ipentec.com/document/document.aspx?page=android-sqlite-save-database-file
上記のサイトを見ましたが、これをどのように応用すればいいのか分かりませんでした。
どうかよろしくお願いします。
public class WifiManager04 extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
setListAdapter(adapter);
final WifiManager manager = (WifiManager) getSystemService(WIFI_SERVICE); final Handler handler = new Handler(); final TimerTask timerTask = new TimerTask(){ @Override public void run() { if (manager.getWifiState() == WifiManager.WIFI_STATE_ENABLED) { // APをスキャン manager.startScan(); // スキャン結果を取得 List<ScanResult> apList = manager.getScanResults(); final String[] aps = new String[apList.size()]; for (int i = 0; i < apList.size(); i++) { aps[i] = "SSID:" + apList.get(i).SSID + "\n" + apList.get(i).frequency + "MHz " + apList.get(i).level + "dBm"; } handler.post(new Runnable() { @Override public void run() { adapter.clear(); adapter.addAll(aps); adapter.notifyDataSetChanged(); } }); } } }; new Thread(new Runnable() { @Override public void run() { new Timer(true).schedule(timerTask, 0, 1000); } }).start(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_wifi_manager04, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); }
}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/10/20 10:22