質問

I'm having a serial Bluetooth device connected to my android app. It works well, but only when the device is on..

When my bluetooth device ("Gps_3.3v_4800") device is off my app crashes when it starts. Is there a way to see if its on? Or anyway to prevent my app from crashing.

for (BluetoothDevice device : pairedDevices) {
                btDevice[i] = device.getName();
                System.out.println(device.getName() + device.getAddress() + " \n");

                // Connect to my device
                if(device.getName().equalsIgnoreCase("Gps_3.3v_4800")) {
                        Thread ct = new ConnectThread(device, mBluetoothAdapter);
                        isct = new ConnectedThread(((ConnectThread) ct).getSocket());
                        ((ConnectedThread)isct).setJavascript(javascr);
                        ((ConnectedThread)isct).write("hallo");
                        isct.start();
                }
}

My error when device is not on:

Fatal signal 11 (SIGSEGV) at 0x00000008 (code=1), thread 3928 (Thread-4174)

Update Now I'm getting a null pointer (java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hellobt/com.example.hellobt.MainActivity}: java.lang.NullPointerException) Trying to stop the thread when it wont connect..

役に立ちましたか?

解決

Solved the problem with checking:

if(mmSocket.isConnected())

I think there is only a problem when a phone is connected with another device. But for me that is ok.

Thank you all.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top