小编Pau*_*usM的帖子

连接到远程设备时遇到困难.需要不止一次尝试

我正在处理一个项目,我需要将我的平板电脑(android 4.2.2)连接到蓝牙到UART转换器(通过微芯片的RN42).我正在使用BluetoothChat示例来管理蓝牙连接,但很难连接.有时程序在方法mmSocket.connect(); - 它抛出IOException.有时我需要三次或更多次尝试连接到我的远程设备.连接完成后,非常稳定.我试图改变UUID,试图改变rn42模块(我也尝试使用HC-05模块).我尝试了安全和不安全的rfcomm连接,仍然没有运气.这是我的代码:在MainActivity中:

  @Override
public void onButtonPressed(View view, Device device){
    switch (view.getId()){
    case R.id.buttonRedaguotiIrengini:
        // Edit button is pressed
        Intent i = new Intent(this, DeviceActivity.class);
        i.putExtra("device", device);
        i.putExtra("requestCode", REQUEST_EDIT_DEVICE);
        startActivityForResult(i, REQUEST_EDIT_DEVICE);
        break;
    case R.id.buttonPrisijungti:
        if (mBtService.getState()==BluetoothService.STATE_CONNECTED){
            mBtService.stop();
        } else {
            BluetoothDevice btDevice = mBluetoothAdapter.getRemoteDevice(device.getMac());
            mBtService.connect(btDevice, false);
        }
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

在BluetoothService类中:

   // Name for the SDP record when creating server socket
private static final String NAME_SECURE = "BluetoothChatSecure";
private static final String NAME_INSECURE = "BluetoothChatInsecure";

// Unique UUID for …
Run Code Online (Sandbox Code Playgroud)

android bluetooth android-bluetooth

5
推荐指数
1
解决办法
1459
查看次数

如何从字节数组构造颜色?

我正在努力完成非常简单的任务(好吧,我想是这样).我有byte[4]数组,表示颜色值等byte[0] = alpha, byte [1] = red等.如何将此字节数组转换为实际的颜色对象?谢谢你的回答.

java android

3
推荐指数
1
解决办法
5757
查看次数

标签 统计

android ×2

android-bluetooth ×1

bluetooth ×1

java ×1