在Android的蓝牙连接问题SPP? [英] Problems with connecting bluetooth SPP in android?
本文介绍了在Android的蓝牙连接问题SPP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class TestConnection extends Activity {
/** Called when the activity is first created. */
public static final UUID BluetoothSerialUuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
private BluetoothAdapter _adapter;
BluetoothSocket socket=null;
@Override
protected void onPause() {
try {
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView text = (TextView) findViewById(R.id.mainText);
text.setText("This is a test");
String deviceAddress = "05:03:e8:c0:bf:c0";
_adapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = _adapter.getRemoteDevice(deviceAddress);
try {
socket = device.createRfcommSocketToServiceRecord(BluetoothSerialUuid);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
socket.connect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我试图用一些code从该网站:
I am trying to use some code from this site:
的http://zornsoftware.talsit.info/blog/pairing-spp-bluetooth-devices-with-android-phones.html
要克服的事实的Android逃课为0x00蓝牙设备。然而,当我这样做:
_adapter.getRemoteDevice(deviceAddress);
to overcome the fact android skips class 0x00 Bluetooth devices. However when I do this: _adapter.getRemoteDevice(deviceAddress);
我从来没有得到回应
推荐答案
我明白了为什么这是失败的原因是如今在清单文件中的正确批准的理由。
I realized the reason why this was failing was due to now having the correct permission in the manifest file.
这篇关于在Android的蓝牙连接问题SPP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文