简体   繁体   English

如何将蓝牙设备名称传递给另一个活动?

[英]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.

相关问题 Android:如何将蓝牙连接传递给另一个活动? - Android: How to pass a Bluetooth connection to another Activity? 如何将消息从另一个活动传递到Bluetooth活动 - How to pass message to Bluetooth Activity from another activity 如何使用应用程序接口将蓝牙套接字传递给另一个活动 - How to pass a Bluetooth Socket to another Activity using Application interface 如何将另一个活动的名称作为参数传递给另一个活动中的方法 - How to pass name of another activity as a parameter to a method in another activity 从Android中的一项活动转移到另一项活动后,如何保持蓝牙低功耗设备的连接状态? - How to persist the Bluetooth Low Energy Device connection state after passing from one activity to another in Android? 如何将复选框中选中的名称传递给另一个活动 - How to pass the name checked from checkbox to another activity 如何将活动名称传递给函数并在另一个文件中定义函数 - How to pass activity name into to a function and define function in another file 如何获取蓝牙设备型号名称? - How to get the Bluetooth device model name? 如何刷新蓝牙设备名称【扫描缓存】? - How to refresh Bluetooth device name [Scan Cache]? 如何获取蓝牙配对设备的设备名称? - How get the device name of bluetooth paired devices?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM