[英]how to pass bluetooth device name to another activity?
我正在嘗試將藍牙設備名稱和RSSI從包含ListView的一個活動傳遞到另一個活動,當用戶選擇一個設備時它工作正常,但是當用戶選擇另一個設備時,第一個設備的結果將是相同的。 是否可以傳遞名稱和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);
}
});
這是我用來發送意圖的代碼
也許您正在尋找這樣的東西:
Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("BLUETOOTH_NAME", bluetoothName);
intent.putExtra("RSSI", rssi);
startActivity(intent);
在這種情況下,每次從一個活動轉到另一個活動時,您都將數據保存在意圖中,然后將其傳遞到下一個活動。 然后,您可以像這樣在新活動中獲取數據:
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.