私はAndroid開発を学び始めたばかりです。私は使用可能なBluetoothデバイスをスキャンしてログファイルにリストするためのAndroidプログラムを作成しています。私がAndroidに慣れていないので、私は以下のコードスニペットで何が間違っているのか理解できません。
button2.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
ListView lv1 = (ListView) findViewById(R.id.myListView1);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
final BroadcastReceiver mReceiver = new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
//When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action))
{
//Get the BluetoothDevice object from the Intent
BluetoothDevice device = intent.getParcelableExtra(
BluetoothDevice.EXTRA_DEVICE);
Log.v("BlueTooth Testing",device.getName() + "\n"
+ device.getAddress());
}
}
};
String aDiscoverable = BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE;
startActivityForResult(new Intent(aDiscoverable),DISCOVERY_REQUEST);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
registerReceiver(mReceiver, filter);
mBluetoothAdapter.startDiscovery();
}
});
デバッグモードを試すと、コントロールは " BroadcastReceiver()
"をスキップします。ログにエントリが見つかりませんでした。問題の内容や使用可能なBluetoothデバイスのリストをどのように表示するかを教えてください。
[編集]
アプリケーションが予期せず停止したというエラーが表示されます。
Logcat Errors:
10-28 20:08:24.201: ERROR/UpdateReceiver(914): ACTION_PACKAGE_REMOVED
10-28 20:08:28.415: ERROR/RequestPermissionActivity(431): Timeout = 120
10-28 20:08:44.291: ERROR/DTUN_HCID4(521): === dtunops_stop_discovery() ===