使用Qpython在Android中接听来电
我试图在安卓4.4.3上通过qpython获得incomingcall号码 已经尝试过以下方法:使用Qpython在Android中接听来电,android,python,call,qpython,Android,Python,Call,Qpython,我试图在安卓4.4.3上通过qpython获得incomingcall号码 已经尝试过以下方法: import androidhelper w=1 while (w == 1): droid = androidhelper.Android() droid.startTrackingPhoneState() phonest = droid.readPhoneState() number = phonest[2] # If i try to use ['incomin
import androidhelper
w=1
while (w == 1):
droid = androidhelper.Android()
droid.startTrackingPhoneState()
phonest = droid.readPhoneState()
number = phonest[2] # If i try to use ['incomingNumber'] not work
if number != None:
droid.makeToast('Call from '+number)
outerDict = droid.readPhoneState()
innerDict = outerDict['result']
number = innerDict['incomingNumber']
我总是得到空指针异常
我读到:
但根本不起作用,因为:
这不起作用:
import android
droid = android.Android()
当我尝试这个:
import androidhelper
w=1
while (w == 1):
droid = androidhelper.Android()
droid.startTrackingPhoneState()
phonest = droid.readPhoneState()
number = phonest[2] # If i try to use ['incomingNumber'] not work
if number != None:
droid.makeToast('Call from '+number)
outerDict = droid.readPhoneState()
innerDict = outerDict['result']
number = innerDict['incomingNumber']
错误,因为需要是整数或类似的值。QPython没有包含读取电话状态权限,请改用QPython3。我想我面临类似的行为,只是运行QPython应用程序附带的测试脚本(使用QPython3)。输出为:
Running test_phone_state... java.lang.NullPointerException PASS
试图用python except block捕获异常,但它直接转到finally子句,所以我无法得到回溯。我认为“java.lang.NullPointerException”打印输出来自较低的java facade级别,并且在python层中无法访问错误回溯
但是,测试代码使用sl4a导入而不是androidhelper。我不知道有什么区别。调用startTrackingPhoneState时,将打印空指针异常。
我想知道这是否与旧的Android版本(使用4.4.2)或旧的Android Facade版本有关,或者可能与如何使用startTrackingPhoneState的文档和测试脚本有关。最坏的情况是Android Facade层的某个地方出现了一个bug
这不完全是对这个问题的回答,但我没有写评论的权利。这些就是我对这个主题的观察。回溯会有很大帮助。java.lang.NullPointerexception None