Sunday, April 28, 2013

Python script to get android phone vibrate while the callee answers

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 posted an idea about to your android droid vibrate while the callee answers via sqlite3 command.

according to the feedback from a user, reporting a bug, which indicates the run shell action with root most likely would run kinda slow in some low RAM like 512M or 215M smartphone.

i guess the loop interval is also a problem, which make it worse in such a short while.

so i was thinking of finding another workaround.

after done some homework, i have tested working in my android tablet pad. running kinda fast, however, when i moved it to my HTC droid, it failed, error says "sqlite database disk image is malformed".

i got scared ATM, and quickly run some checks on my database file, whereas everything is fine, i opened it via RE and sqlite editor, both are fine. no corruption at all. when i switched back to the python script, it still ran end up with the same error.

well, i am not sure if there is some kind of secure system preventing me from accessing the database.

if you guys are interested, please run some testings for me, will be greatly appreciated.


First move, change the database file permission to be rw-rw-rw, or else, python could fail to access it.

and then you may run this script with tasker outgoing call context.


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


import android
droid = android.Android()
import sqlite3
import time

time.sleep(3)
con = sqlite3.connect("/data/data/com.android.providers.contacts/databases/contacts2.db")
con.isolation_level = None
while True:
  cur = con.cursor()
  cur.execute("SELECT duration FROM calls WHERE type <= 2 ORDER BY date DESC LIMIT 1")
  for i in cur:
    if i[0] == 1 or i[0] == 2:
      break
    print i[0]

droid.vibrate(200)
cur.close()
con.close()


10 comments:

  1. Well, MIUI ROM support this feature for a long time.

    Good job. I'm happy to see how it's realized with SL4A and Python.

    ReplyDelete
  2. Baccarat, Cards, and Poker | WURRI | Wolverione
    Play Baccarat at 인카지노 Wolverione Casino. Get up to £100 worrione in 카지노사이트 free play plus a 100% up to €300 casino bonus. Rating: 4.5 · ‎11 votes

    ReplyDelete