可以参考SDK/SAMPLES里的BluetoothChat,这是一个蓝牙聊天室

解决方案 »

  1.   


    我看了,没有配对,我想把ANDROID系统里的Setting 的蓝牙设置移植,没移填成功..
      

  2.   

    我查了一下API 没有这样的方法
      

  3.   

    这个和蓝牙的firmware有关系,我们的板子蓝牙配对一直有问题,后来换了新的firmware就好了。
      

  4.   


    请教怎样移植?
    用一些android sdk2.1做一些应用开发, 并没有自己烧系统那种,怎样移植?有资料吗?
      

  5.   

    我在源码里都看到这些接口,
    在API里面居然没有,也不能使用..    /**
         * Start the bonding (pairing) process with the remote device.
         * <p>This is an asynchronous call, it will return immediately. Register
         * for {@link #ACTION_BOND_STATE_CHANGED} intents to be notified when
         * the bonding process completes, and its result.
         * <p>Android system services will handle the necessary user interactions
         * to confirm and complete the bonding process.
         * <p>Requires {@link android.Manifest.permission#BLUETOOTH_ADMIN}.
         *
         * @return false on immediate error, true if bonding will begin
         * @hide
         */
        public boolean createBond() {
            try {
                return sService.createBond(mAddress);
            } catch (RemoteException e) {Log.e(TAG, "", e);}
            return false;
        }
      

  6.   

    这个配对过程不用自己编码吧...我是这样做的,先搜索附近蓝牙设备,然后生成列表显示出来,点击后直接connect该设备
      

  7.   


    哦,忘了说,其他设备是建立了一个服务监听器,并在开启服务前设置设备可被搜索(Enabling discoverability),其他设备搜索到此设备后,直接以client的方式connect到此设备
      

  8.   

    并在开启服务前设置设备可被搜索(Enabling discoverability)这个是在系统里设置还是在用代码写呢?
      

  9.   


    不会啊,我用sdk 2.1下的BluetoothChat安装到真机上可以用啊(模拟器上模拟不了蓝牙,需要真机才能用)
      

  10.   

    如果搜索了附近设备,再选择其中一个点击,连接。这样没有经过配对连接时不会成功的,因为查看API源码,你回发现connect函数中会检查是否与远程蓝牙设备配对,如果没有,connect直接返回。所以此法不可行。。