如何使用蓝牙在范围内找到设备? [英] How to find the devices in the range by using bluetooth?

查看:182
本文介绍了如何使用蓝牙在范围内找到设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android的新手.我想开发一个应用程序,以编程方式使用蓝牙来查找该范围内的设备.如果有人有想法,请给我一些示例代码.

I am new to android.I want to develop an application to find the devices in the range by using Bluetooth programmatically.If any one has idea please give some sample code to me.

推荐答案

Find The Devices in the Range by using Bluetooth programmatically.

是的,您可以使用 BroadcastReceiver 进行此操作,请查看以下代码,它将对您有所帮助

Yes you can do this using BroadcastReceiver, check out below code, it will help you.

开始搜索

mBluetoothAdapter.startDiscovery(); 
mReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();

查找设备

    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());
    }
  }
};

IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND); 
registerReceiver(mReceiver, filter);

这篇关于如何使用蓝牙在范围内找到设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆