在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(); } }
}
我正在尝试使用此站点的一些代码:
http://zornsoftware.talsit.info/blog/pairing-spp-bluetooth-devices-with-android-phones.html
克服了android跳过类0x00蓝牙设备的事实。 但是当我这样做时:_adapter.getRemoteDevice(deviceAddress);
我从来没有得到回应
我意识到失败的原因是由于现在在清单文件中拥有正确的权限。
- 具有自定义背景颜色的Android AlertDialog setMultiChoiceItems
- 无论日期如何,确定时间是否介于两次之间
- 以编程方式检查节电模式
- 从Activity上下文外部调用startActivity()需要FLAG_ACTIVITY_NEW_TASK标志。 这真的是你想要的吗?
- Android Listview删除项目之间的任何空格
- 在动态创建的片段之间进行通信,从而产生空指针exception
- 无法从包含DEX和Java字节码内容的archive \ app \ libs \ appodeal-2.1.11.jar’创建Android应用程序
- 设置MP3 ID3v2标签中的歌词
- 未找到启动器活动