Using backport-android-bluetooth on Android 1.6
I'm trying to write an application using Bluetooth on Android 1.6. Since it's not officially supported, I found the backport of android.bluetooth API ( http://code.google.com/p/backport-android-bluetooth ). But when I deploy the sample chat application (modified for backport) LogCat gives me the error below:
My question is, how I can use backport-android-bluetooth on 1.6 and is there any working samples?
Thanks!
11-30 14:03:19.890: ERROR/AndroidRuntime(1927): Uncaught handler: thread main exiting due to uncaught exception
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): java.lang.ExceptionInInitializerError
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at backport.android.bluetooth.BluetoothSocket.<init>(BluetoothSocket.java:69)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at backport.android.bluetooth.BluetoothServerSocket.<init>(BluetoothServerSocket.java:16)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at backport.android.bluetooth.BluetoothAdapter.listenUsingRfcommWithServiceRecord(BluetoothAdapter.java:513)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at com.example.bluetooth.BluetoothChatService$AcceptThread.<init>(BluetoothChatService.java:237)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at com.example.bluetooth.BluetoothChatService.start(BluetoothChatService.java:109)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at com.example.bluetooth.BluetoothChat.onResume(BluetoothChat.java:138)
11-30 14:03:19.906: ERROR/Android开发者_StackOverflowRuntime(1927): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1225)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.app.Activity.performResume(Activity.java:3559)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2838)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2866)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2420)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.app.ActivityThread.access$2100(ActivityThread.java:116)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.os.Handler.dispatchMessage(Handler.java:99)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.os.Looper.loop(Looper.java:123)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.app.ActivityThread.main(ActivityThread.java:4203)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at java.lang.reflect.Method.invokeNative(Native Method)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at java.lang.reflect.Method.invoke(Method.java:521)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at dalvik.system.NativeStart.main(Native Method)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): Caused by: java.lang.UnsatisfiedLinkError: classInitNative
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.bluetooth.RfcommSocket.classInitNative(Native Method)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): at android.bluetooth.RfcommSocket.<clinit>(RfcommSocket.java:152)
11-30 14:03:19.906: ERROR/AndroidRuntime(1927): ... 21 more
I think this backport bluetooth doesn't work, because 1.6 shields off the used api's. It's one of the updates Google did to 1.6: prevent developers to use internal api's and I guess BT is one of them... :(.
According to this issue on the bluetooth backport tracker it should be possible to it on 1.6. Quote: "I run the backport successfully on a HTC Magic (Android 1.6)"
The backport api works on android 1.6. Follow the instructions given on project home page. I tried with bluetooth chat sample app and works fine.
I am using this lib since a long time - It works on some phones, but not on others. It really depends on the underlying Android Build ..
精彩评论