简体   繁体   中英

Problems with connecting bluetooth SPP in android?

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();
    }

}

}

I am trying to use some code from this site:

http://zornsoftware.talsit.info/blog/pairing-spp-bluetooth-devices-with-android-phones.html

to overcome the fact android skips class 0x00 Bluetooth devices. However when I do this: _adapter.getRemoteDevice(deviceAddress);

I never get a response

我意识到失败的原因是由于清单文件中现在具有正确的权限。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM