4

I am new to android development. I am writing an app which receives string from the bluetooth terminal of laptop. while opening a connection i am getting an error Connection Refused when the below line gets executed.

socket.connect();

I tried to check what happens in connect method. Here I found Android Studio giving me issues like.

  1. Cannot access android.bluetooth.BluetoothSocket.SocketState.

  2. Cannot resolve method createSocketChannel.

  3. Cannot resolve Symbol IBluetooth.

Does my development environment have a problem? below is the exception.

02-15 23:19:54.112 18794-18794/poc.tusharimaging.com.bluetooth_poc W/BluetoothAdapter: getBluetoothService() called with no BluetoothManagerCallback
02-15 23:20:33.754 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1
02-15 23:20:33.773 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:684)
02-15 23:20:33.785 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at android.bluetooth.BluetoothSocket.waitSocketSignal(BluetoothSocket.java:643)
02-15 23:20:33.795 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:377)
02-15 23:20:33.806 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at poc.tusharimaging.com.bluetooth_poc.MainActivity.openBT(MainActivity.java:145)
02-15 23:20:33.815 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at poc.tusharimaging.com.bluetooth_poc.MainActivity$1.onClick(MainActivity.java:75)
02-15 23:20:33.823 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at android.view.View.performClick(View.java:5204)
02-15 23:20:33.830 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at android.view.View$PerformClick.run(View.java:21153)
02-15 23:20:33.837 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
02-15 23:20:33.843 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
02-15 23:20:33.850 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at android.os.Looper.loop(Looper.java:148)
02-15 23:20:33.857 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
02-15 23:20:33.863 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
02-15 23:20:33.871 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-15 23:20:33.878 18794-18794/poc.tusharimaging.com.bluetooth_poc W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
02-15 23:25:15.354 18794-18794/poc.tusharimaging.com.bluetooth_poc I/Choreographer: Skipped 18837 frames!  The application may be doing too much work on its main thread.
02-15 23:25:15.801 18794-18991/poc.tusharimaging.com.bluetooth_poc D/OpenGLRenderer: endAllStagingAnimators on 0x7f9ec3c000 (RippleDrawable) with handle 0x7f9dd29f60
02-15 23:25:16.532 18794-18794/poc.tusharimaging.com.bluetooth_poc I/Choreographer: Skipped 55 frames!  The application may be doing too much work on its main thread.
Tushar Banne
  • 1,587
  • 4
  • 20
  • 38
  • I'm confused. Can you compile and run your app or are you getting compiler errors? – Code-Apprentice Feb 17 '16 at 20:57
  • I am able to compile and run the app. On performing open operation this exception is thrown. – Tushar Banne Feb 18 '16 at 10:32
  • If Android Studio is showing warnings and errors but you can still compile and run the app, it means that AS doesn't have access to the libraries you are using. You will need to figure out the settings to change to get this to work correctly. However, your build tool (probably gradle) can find the libraries just fine. The exception error message from the exception is pretty clear about what went wrong and what you need to do to fix it. – Code-Apprentice Feb 18 '16 at 16:08

1 Answers1

-6

The run-time error explictly states the problem:

getBluetoothService() called with no BluetoothManagerCallback

So you need to provide a BluetoothManagerCallback

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Would help if you stated how this comes about. I get the same message and never make a call to getBluetoothService(). The underlying Android code may do that but I do not. – Brian Reinhold Jan 10 '18 at 16:47