利用可能なBluetoothデバイスをスキャンしてリストに表示したいと思います。私はandriod開発の初心者です。私はArrayAdapterにいくつか問題があると思いますが、正確な問題を把握することはできません。EclipseでAndroid対応のBluetoothデバイスをスキャンする
プログラムを実行すると、例外The application stops unexpectedly
が発生します。あなたはこれを解決するのを手伝ってくれますか?
button2.setOnClickListener(new View.OnClickListener()
{
@SuppressWarnings("null")
public void onClick(View v)
{
ListView lv1 = (ListView) findViewById(R.id.myListView1);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
// TODO Auto-generated method stub
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
// If there are paired devices
if (pairedDevices.size() > 0)
{
// Loop through paired devices
for (BluetoothDevice device : pairedDevices)
{
ArrayAdapter<String> mArrayAdapter = null;
// Add the name and address to an array adapter to show in a ListView
mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
/*final ArrayList<String> btDevices = new ArrayList<String>();
ArrayAdapter<String> aa = new ArrayAdapter<String>(CalcActivity.this,
android.R.layout.simple_list_item_1,
btDevices);
*/
lv1.setAdapter(mArrayAdapter);
}
}
}
});
私はmArrayAdapter.add(device.getName() + "\n" + device.getAddress());
編集時に例外を取得しています: は私のコードを控えたが、それでも私はこの問題を把握することはできませんよ。
Discovering available bluetooth devices in android
LogCat出力を投稿してください。 – Reno