在Android 1.6上使用backport-android-bluetooth

时间:2010-03-24 08:50:54

标签: android bluetooth backport

我正在尝试在Android 1.6上使用蓝牙编写应用程序。由于它没有得到官方支持,我找到了android.bluetooth API(http://code.google.com/p/backport-android-bluetooth)的后端。但是当我部署示例聊天应用程序(为backport修改)时,LogCat会给出以下错误:

我的问题是,如何在1.6上使用backport-android-bluetooth,是否有任何工作样本?

谢谢!

    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/AndroidRuntime(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

4 个答案:

答案 0 :(得分:1)

我认为这种后端蓝牙不起作用,因为1.6屏蔽了使用过的api。这是Google对1.6所做的更新之一:阻止开发人员使用内部api,我猜BT就是其中之一...... :(。

答案 1 :(得分:0)

根据蓝牙后端跟踪器上的this issue,它应该可以在1.6上使用。引用:“我在HTC Magic(Android 1.6)上成功运行了后端”

答案 2 :(得分:0)

backport api适用于Android 1.6。按照项目主页上的说明进行操作。我尝试使用蓝牙聊天示例应用程序并且工作正常。

答案 3 :(得分:0)

我使用这个lib很长一段时间 - 它适用于某些手机,但不适用于其他手机。这真的取决于底层的Android Build ..