相关疑难解决方法(0)

在.connect()之后如何防止Android蓝牙RFCOMM连接立即死亡?

这个问题已经解决了!非常感谢布拉德,丹尼斯和瘾君子!你是英雄!:)

这是工作代码.它连接到Zeemote并从中读取数据.

=====代码=====

public class ZeeTest extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        try {
            for (int i = 0; i < 3; i++) {
                test();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private boolean connected = false;
    private BluetoothSocket sock;
    private InputStream in;
    public void test() throws Exception {
        if (connected) {
            return;
        }
        BluetoothDevice zee = BluetoothAdapter.getDefaultAdapter().
            getRemoteDevice("00:1C:4D:02:A6:55");
        Method m = zee.getClass().getMethod("createRfcommSocket",
            new Class[] { int.class });
        sock = (BluetoothSocket)m.invoke(zee, Integer.valueOf(1));
        Log.d("ZeeTest", …

android bluetooth motorola rfcomm

48
推荐指数
3
解决办法
6万
查看次数

标签 统计

android ×1

bluetooth ×1

motorola ×1

rfcomm ×1