【问题标题】:Incoming call in Android with Qpython使用 Qpython 在 Android 中来电
【发布时间】:2015-02-24 14:56:47
【问题描述】:

我正在尝试在 android 4.4.3 上使用 qpython 获取来电号码

已经尝试过:

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)

我总是得到 NullPointer 异常

我读到这个: python function call syntax ... result = foo() ['abc'] 但根本不起作用,因为: 这不起作用:

import android
droid = android.Android()

当我尝试这个时:

outerDict = droid.readPhoneState()
innerDict = outerDict['result']
number = innerDict['incomingNumber']

错误,因为需要是整数或类似的东西。

【问题讨论】:

  • 回溯会有很大帮助。
  • java.lang.NullPointerexception 无

标签: android python call qpython


【解决方案1】:

QPython 不包含 READ_PHONE_STATE 权限,请改用 QPython3。

【讨论】:

    【解决方案2】:

    我认为我面临着类似的行为,只运行 QPython 应用程序附带的测试脚本(使用 QPython3)。输出是:

    Running test_phone_state... java.lang.NullPointerException PASS
    

    试图用 python except 块捕获异常,但它只是直接进入 finally 子句,所以我无法得到回溯。我认为“java.lang.NullPointerException”打印输出来自较低的java门面级别,并且无法在python层访问错误回溯。

    但是测试代码使用 sl4a 导入而不是 androidhelper。我不确定那里有什么区别。调用 startTrackingPhoneState 时会打印空指针异常。 我想知道这是否与旧的 Android 版本(使用 4.4.2)或旧的 Android Facade 版本有关,或者如何使用 startTrackingPhoneState 的文档和测试脚本是旧的。最坏的情况是 Android Facade 层的某个地方存在错误。

    这不完全是问题的答案,但我无权编写 cmets。以上是我对这个问题的看法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-24
      相关资源
      最近更新 更多