【发布时间】:2017-04-26 08:04:24
【问题描述】:
我正在尝试使用 kivy 的适用于 android 的 python 为 android 编写一个 python 蓝牙库。我使用来自 jnius 模块的 autoclass 导入 java 类。到目前为止,它运行良好,但是,当我调用函数 fetchUuidsWithSdp() 并检查获取的 uuid 的 ACTION_UUID 意图时,我得到了一个错误的对象。我使用的代码是:
elif action == ACTION_UUID:
print("....... ACTION_UUID .......")
extras = intent.getExtras()
fetchedUUIDs = extras.get(EXTRA_UUID)
# fetchedUUIDs = intent.getParcelableArrayExtra(EXTRA_UUID)
print("fetchedUUIDs object type is: ..............")
print (fetchedUUIDs)
for u in fetchedUUIDs:
print u.toString()
所以我在 adb 控制台中得到以下打印输出:
I/python (30971): ....... ACTION_UUID .......
I/python (30971): fetchedUUIDs object type is: ..............
I/python (30971): [<android.os.Parcelable at 0x7c1f2600 jclass=android/os/Parcelable jself=<LocalRef obj=0x20f00dfa at 0x79f7bab0>>, <android.os.Parcelable at 0x7c1
显示“fetchedUUIDs”的对象类型是“android.os.Parcelable”列表而不是“ParcelUuid”列表。当我调用 toString() 时,我得到以下跟踪:
I/python (30971): Traceback (most recent call last):
I/python (30971): File "jnius/jnius_proxy.pxi", line 47, in jnius.jnius.PythonJavaClass.invoke (jnius/jnius.c:24931)
I/python (30971): File "jnius/jnius_proxy.pxi", line 73, in jnius.jnius.PythonJavaClass._invoke (jnius/jnius.c:25609)
I/python (30971): File "/home/tito/code/python-for-android/build/python-install/lib/python2.7/site-packages/android/broadcast.py", line 18, in onReceive
I/python (30971): File "main.py", line 235, in on_broadcast
I/python (30971): print u.toString()
I/python (30971): AttributeError: 'android.os.Parcelable' object has no attribute 'toString'
我的代码有什么问题吗?非常感谢任何帮助。
【问题讨论】: