android蓝牙设备对

时间:2012-06-28 08:29:17

标签: android bluetooth

任何人都可以告诉我代码中的问题是什么吗?

startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE), DISCOVERY_REQUEST);

    @Override
    protected void onActivityResult(int requestCode,int resultCode, Intent data)
    { 
        if (requestCode == DISCOVERY_REQUEST) 
        {
            boolean isDiscoverable = resultCode > 0;
            int discoverableDuration = resultCode;
            if (isDiscoverable) 
            {
                UUID uuid = UUID.fromString("a60f35f0-b93a-11de-8a39-08002009c666");
                String name = "bluetoothserver";
                final BluetoothServerSocket btserver = bt.listenUsingRfcommWithServiceRecord(name, uuid);
                Thread acceptThread = new Thread(new Runnable() {
                public void run()
                {
                    try
                    {
                        BluetoothSocket serverSocket = btserver.accept();
                    }
                    catch (Exception e)
                    {
                        Log.d("BLUETOOTH", e.getMessage());
                    }
                }
                });
                acceptThread.start();
            }
        }
    }

在此代码中,它在 onActivityResult 上显示错误。

0 个答案:

没有答案