0

我知道我可以将 bt 扫描的结果抓取到如下代码的数组列表中:

// Create a BroadcastReceiver for ACTION_FOUND
private 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);
            // Add the name and address to an array adapter to show in a ListView
            mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
    }
};
// Register the BroadcastReceiver
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);

但我想稍后使用结果,比如将它们放在字符串数组或类似的东西上可以做到吗?

4

1 回答 1

0

是的,它可以,只需在某处创建一个静态数组/列表并填充它并在任何你想要的地方读取它。仅限制:在应用程序重新启动时不保存数据。为此,您应该检查数据库和/或 SharedPreferences

于 2013-03-23T20:30:45.090 回答