2013-03-23 28 views
0

我知道我可以抓住BT扫描的结果,以这样代码的ArrayList:如何将蓝牙扫描结果保存在字符串数组中?

// 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); 

,但我想以后使用的结果,就像把他们一个字符串数组或类似这样的 东西上能不能做到?

回答

0

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

+0

我试着像做一个for循环,每次将结果放入一个数组[],但应用程序将卡住。你能告诉我一个例子吗? – user2141340 2013-03-23 20:59:26

+0

您如何向我展示您的阵列尝试? – WarrenFaith 2013-03-24 14:06:36