android 2.2中的蓝牙连接

android 2.2中的蓝牙连接,android,bluetooth,Android,Bluetooth,我使用的是安卓2.2,我尝试了以下代码在安卓中发送数据 BluetoothDevice device=BluetoothAdapter.getDefaultAdapter().getRemoteDevice(MACID); Method m=device.getClass.getMethod("createRFcommSocket",new Class[]{int.class}; BluetoothSocket socket=(BluetoothSocket)m.invock(device,1)

我使用的是安卓2.2,我尝试了以下代码在安卓中发送数据

BluetoothDevice device=BluetoothAdapter.getDefaultAdapter().getRemoteDevice(MACID);
Method m=device.getClass.getMethod("createRFcommSocket",new Class[]{int.class};
BluetoothSocket socket=(BluetoothSocket)m.invock(device,1);
socket.connect();
OutputStream os;
os=socket.getOutputStream();
os.write("hai".getBytes());
os.flush();
os.close();
socket.close();
查找以下错误:

ERROR : java.io.IOException:Connection refused
请在这方面帮助我……

您添加了这些吗

<uses-permission android:name="android.permission.BLUETOOTH" />

<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />


是的,我还加了一句,它还在继续。谢谢,我需要配对设备吗。你对此有什么想法吗。Intent=newintent(“android.bluetooth.device.PAIRING_REQUEST”);intent.putExtra(“安卓.蓝牙.设备.额外.设备”,设备);int bluepin=1234;intent.putExtra(“android.bluetooth.device.extra.PAIRING_VARIANT”,bluepin);发送广播(意图);错误:java.lang.securityException:权限拒绝:不允许发送广播android.bluetooth.device.action.PAIRING_请求我设置了上述两个权限,但仍然抛出错误。我有没有为这个添加任何其他永久任务。我正在尝试android“三星galaxy y”。当设备已配对时,我能够发送数据。但对于新手机,它显示了这个错误。。。任何人都不知道这件事。请帮忙。