[英]how to pass bluetooth device name to another activity?
i am trying to pass Bluetooth device name and RSSI from one activity that contain the ListView to another activity,it works fine when the user choose one device but when the user choose another device the result will be the same for the first device. 我正在尝试将蓝牙设备名称和RSSI从包含ListView的一个活动传递到另一个活动,当用户选择一个设备时它工作正常,但是当用户选择另一个设备时,第一个设备的结果将是相同的。 is there away to pass the name and RSSI or a Bluetooth device ?? 是否可以传递名称和RSSI或蓝牙设备?
newDevicesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mBtAdapter.cancelDiscovery();
Intent intent = new Intent(DevicesList.this, FindIT.class);
intent.putExtra("name", NAME);
intent.putExtra("rssi", RSSI);
startActivity(intent);
}
});
here is the code i use to send the intent 这是我用来发送意图的代码
Maybe you are looking for something like this: 也许您正在寻找这样的东西:
Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("BLUETOOTH_NAME", bluetoothName);
intent.putExtra("RSSI", rssi);
startActivity(intent);
In this case you save your data in the intent and pass it to the next activity every time you go from one activity to another. 在这种情况下,每次从一个活动转到另一个活动时,您都将数据保存在意图中,然后将其传递到下一个活动。 Then you can get your data in the new activity like this: 然后,您可以像这样在新活动中获取数据:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String bluetoothName = extras.getString("BLUETOOTH_NAME");
String rssi = extras.getString("RSSI");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.