Search code examples
androidsl4aqpython3

Read call log from Android Python


I'm trying to compile Python code directly on my Android phone via QPython 3L and it's fine for some initial examples. Now I want to read the call log and here is my code.

from androidhelper import sl4a  
droid = sl4a.Android()

myconst = droid.getConstants("android.provider.CallLog$Calls").result
print(myconst['CONTENT_URI'])
calls=droid.queryContent(myconst['CONTENT_URI'],["number","duration","date","type"]).result

At the last line above it throws a NullPointerException and - after many trials&errors and searches on Google - I'm pretty sure that the root cause is a lack of authorization.

Can you confirm if this is the case (or you spot a bug, contrary to what I believe) and please point me to some documentation, for adding the authorization request, if that is appropriate to my specific code context?


Solution

  • Sometimes to solve programming issues like this, one needs luck, a lot of fantasy and an extreme willpower.

    The solution (once one really knows what to do and where to search) can be found on this github page. The FAQ reads:

    A: Why are there so many branches? Q: Because Google Play and some appstores have strict requirements for application permissions, they require different permissions, we use different branch codes, for example, 3 means it is QPython3, L means LIMITED, S means SENSITIVE permission is required.

    After a special (one-off) installation via download on Android, you have to manually add the Telephone permission to the application, using Android permission management. The downloaded app will replace the one installed via Google Play and you'll find your script already there, ready to be run, hopefully without the NPE.