Monday, April 29, 2013

Python script to get android phone vibrate while is being answered II

I happen to find that for GSM standard phone, call duration would be created into sql database only if the outgoing call is being answered, or after hanging up if it is not being answered.

So i guess this method is meant for CDMA android phone only. cause we could not detect if outgoing call is offhook by the callee via tasker or sl4a.

Java code would be the solution i think, by monitoring the phone state.


in my earlier entry, i have mentioned the method about how to get it done by python script.

however it doesn't work on android phone but android pad.

i guess the reason is the contacts dabase is encrypted by default, most likely not encrypted in android pad, since it doesn't actually have mobile communication modules built-in.

well, i have been thinking if there is another way to solve this still via python script?

after some testings, problem finally solved.

if you are interested, please read on.



#### script content ###############


import android
droid = android.Android()
import time
time.sleep(3)
a = droid.queryContent('content://call_log/calls',['duration'],'type <= 2',None,None).result  ## returns a list of dictionary
while a is not None:
  b =a[-1]  
  c = b.get('duration')
  d = int(c)      
  if d == 1 or d == 2:
    break
droid.vibrate(200)


No comments:

Post a Comment