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()
Sunday, April 28, 2013
Saturday, April 27, 2013
Popup SMS notifier made via SL4A python script launched by tasker
Popup SMS notifier made via SL4A python script launched by tasker
i didn't play popup sms before, cause i thought it is a waste of battery. but i have changed my mind right after i saw some introductions about sms popup notifier apps.
i guess it would be much helpful and funny anyway. also it could save a little bit time since i don't have to get into message inbox to read it.
however it seems there is some kind of conflict or bugs maybe for those sms popup notifier apps. everything runs fine until i tap "mark as read" button, it would just crash and FC. i have already tested quite some different kind of simliar apps. same error occurs if i try to mark the message as read.
that makes me thinking of programming or scripting one myself. that is the starting of all of it.
firstly i tried to use tasker scene, or tasker popup alert. however, soon i realized neither of it is working. the reason is either tasker scene or tasker popup alert, they are actually just a scene. popup alert has a displaying timeout limit, if you set it up to forever, it could display right on the screen and never disappear. also the task action would get stuck right there until you stop it manually in the tasker task.
scene has a similar problem too, a scene would not disappear until it got destroyed by tasker.
so either popup alert or scene could not perform if there is more than 1 sms message incoming. it could not display more than 1 popup window.
so i have to figure another way out of it.and sl4a pythong script becomes my testing project.
via this script, i am able to see as many popup sms notifier windows as the sms messages i receive. i may simply tap on the reply button to open up another new window to input the reply message then send it out. also i may tap on mark as read button to mark this current sms message as read.
btw, if you click reply button, it could also mark this current sms message as read too. so i think it could be much more convenient for daily life.
and most funny part is you are able to check your sent message in the default android sms message outbox.
PS. i am still trying to improve this script, to see if i could add contact photo accordingly to the sender phone number. and hopefully i may change the
inputing reply message layout to be fullscreen. i guess that is everybody wants. there is still a long way for me to walk through, wish my poor brain could
still handle it.
========================= script content ===============
# coding=utf-8
import android
droid = android.Android()
import time
Date = droid.getIntent().result[u'extras'][u'%SMSRD']
Time = droid.getIntent().result[u'extras'][u'%SMSRT']
Name = droid.getIntent().result[u'extras'][u'%SMSRN']
.encode('utf-8')
Number = droid.getIntent().result[u'extras'][u'%SMSRF']
.encode('utf-8')
Body = droid.getIntent().result[u'extras'][u'%SMSRB'].encode('utf-8')
count = droid.smsGetMessageCount(True).result
droid.ttsSpeak("you have a new message from" + Name)
droid.dialogCreateAlert(Date +", "+ Time + "unread: "+ str(count), "From: " +Name + "\n" + "Tel: " +Number +"\n" + Body)
droid.dialogSetPositiveButtonText("Reply")
droid.dialogSetNegativeButtonText("Close")
droid.dialogSetNeutralButtonText("Mark as read")
droid.dialogShow()
response = droid.dialogGetResponse()
droid.dialogDismiss()
if response.result["which"] == "neutral" or response.result["which"] == "positive":
msgIDs = droid.smsGetMessageIds(True, 'inbox').result
if msgIDs > 0:
for msgID in msgIDs:
if (droid.smsGetMessageById(msgID).result['body'].encode('utf-8')).find(Body) >= 0:
msgRead=[0]
msgRead[0]=msgID
droid.smsMarkMessageRead(msgRead,1)
if response.result["which"] == "positive":
droid.dialogCreateInput(Date +", "+ Time + "unread: "+ str(count), "From: " +Name + "\n" + "Tel: " +Number)
droid.dialogSetPositiveButtonText("Send")
droid.dialogSetNegativeButtonText("Close")
droid.dialogShow()
response = droid.dialogGetResponse()
droid.dialogDismiss()
if response.result["which"] == "positive":
class Task():
SET_VARIABLE = 547
def new_task(self):
self.action_cnt = 0
self.extras = {'version_number': '1.0', 'task_name': 'task' + str(time.time()), 'task_priority': 9 }
def set_var(self, varname, value):
self.action_cnt += 1
self.extras['action' + str(self.action_cnt)] = {'action': self.SET_VARIABLE, 'arg:1': varname, 'arg:2': value, 'arg:3': False, 'arg:4': False,
'arg:5': False}
def run_task(self):
taskIntent = droid.makeIntent('net.dinglisch.android.tasker.ACTION_TASK', None, None, self.extras).result
droid.sendBroadcastIntent(taskIntent)
def set_var_now(self, varname, value):
self.new_task()
self.set_var(varname, value)
self.run_task()
t = Task()
t.set_var_now("%REPLY_ID", Number)
t.set_var_now("%REPLY_BODY", response.result["value"])
droid.makeToast("message sent!")
============== please name the above python script as "popup sms notifier" or any others you like.==========
======================= tasker profile part ==============
profile 1: (popup sms notifier)
content: event-receive text
task:
action 1: variable-variable clear, name: %REPLY_BODY
action 2: script-run sl4a script, name: popup sms notifier pass variable: %SMSRD,%SMSRT, %SMSRN, %SMSRF, %SMSRB
Hit Done!
profile 2: (popup sms reply)
context: state-variable value, name: %REPLY_BODY, OP: is set
task:
action 1: phone-send sms, number: %REPLY_ID, message: REPLY_BODY, Store in messaging app Checked
action 2: variable-variable clear, name: %REPLY_BODY
Hit Done!
Thursday, April 25, 2013
Tasker to detect and vibrate once the ougoing call is being answered
Tasker to detect and vibrate once the ougoing call is being answered
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.
If you are interested, please follow my profile instruction below and run some test, please further advise me if it is working or any issues. many thanks!
NB.: to run sqlite 3 command, you must make sure your phone has installed the proper sqlite3 file and you must root your phone first to run sqlite3 command.
Tips:
download the sqlite3 file via the links below and renane it as "sqlite3" if it is not, then put it under the phone root directory /system/bin folder, and don't forget to modify the permission for the sqlite3 file to be
rwxr-xr-x
android 4.0 or earlier: http://bit.ly/sqlite3
android 4.1+: http://bit.ly/sqlite3-for-jb
profile:
context: state-phone-call, type:outgoing
task:
action 1: script-run shell,
command: sqlite3 /data/data/com.android. providers.contacts/databases/ contacts2.db "select duration from calls where type <= 2 order by date desc limit 1;"
use root checked, store result in %VIBRATING
action 2: alert-vibrate, 200ms, if %VIBRATING ~ 1
action 3: task-goto, action number 2, if %VIBRATING !~ 1
Action 4: task-stop, if %VIBRATING ~ 1
Wednesday, April 17, 2013
Tasker to auto record incoming or outgoing call
Tasker to auto record incoming or outgoing call
most of time, i was thinking of tasker can do the job like callrecorder? if yes, how to do?
well, after done some homework, i have figured out the method below to share with you guys. via this method, tasker is able to auto record incoming
call and outgoing call, unwanted callee and unreached call will be excluded from recording.
before everything, you should create 1 folder named with english characters, eg. Voice, then create 3 separate folders inside this folder, named it as "Incoming", "Outgoing" and "Temp".
NB. if you are currently using some kind of caller location app, please make sure if it would change the call logs combined phone number and location info with symbol like angle brackets? if yes, tasker would fail to create the new file for outgoing call recording.
Profile 1: (incoming call)
Context 1: Event- Phone- Offhook
Context 2: State: Incoming Call
Task:
Action 1: variable-Variable Set [ Name:%Oncall To:0]
Action 2: media-Record Audio [ File: Voice/Incoming/%CNAME_%CDATE_%CTIME Source: incoming Call/Mic, Code: arm narrowband, format: raw_arm ]
Action 3: alert-Notify [Title:Recording Call Icon:(any icon)]
PS. you may put action 2 and 3 together as a separate task, then make it as a pop up alert positive button right after action 1, asking if you wanna
record.
Profile 2: (outgoing Temp)
Context: State: outgoing Call
Task:
Action 1: task-If, %CONUM !~ XXXXX # XXXX stands for the phone number which you don't wish to record
Action 2: variable-Variable Set [ Name:%Oncall To:1]
Action 3: media-Record Audio [ File: Voice/Temp/ Source:ouggoing Call/Mic Code: arm narrowband, format: raw_arm ]
Action 4: alert-Notify [Title:Recording Call Icon:(any icon)]
PS. you may put action 2 and 3 together as a separate task, then make it as a pop up alert positive button right after action 1, asking if you wanna
record.
Profile 3: (stop recording)
Context: Event-phone-Phone Idle
Task:
Action 1: media-Record Audio Stop
Action 2: alert-Notify Cancel, title: Recording Call
Action 3: task-If %Oncall ~ 1
Action 4: script-run shell, command: sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db "select duration from calls where type
<= 2 order by date desc limit 1;" use root checked, store result in %COUNT
# this step is very important, cause we may know, tasker even sl4a script could not detect if the callee has picked up the phone. if duration is 0, i guess you don't wish to waste storage to record the ringtone, right? this shell command would extract the value of duration for the last phone call
you have made.
Action 5: File--Move [ From: Voice/Temp/.amr To: Voice/Outgoing/%CONAME_%CODATE_%COTIME.amr If, %COUNT > 0 ] # Based on action 4 run result,
tasker may detect and exclude the unreached outgoing phone call. so it would not waste storage space at all. cause the recording would just start
right from the moment while dialing.
Action 6: task-end if
Action 7: variable-variable clear, name: %Oncall
## duration counting via sqlit 3 command
if we look into the calllogs within android default call database, we will see some significant columns, which are very useful for us to get this job done.
type: (numberic)
3: incoming missed call, 2: outgoing call(reached or unreached) 1: incoming call(offhook)
duration: (seconds)
order by date desc limit 1: this is to identify and select the last one in record.
Tasker to stop Poweramp
control for the headset while there is an incoming SMS
If you usually
like to use Poweramp or any other media player to enjoy the music with headset
plugged, once you check the option “respond to headset button”, Poweramp will
take care of your headset line controller instead, and if you are in the middle
of playing a song while there is a sms message incoming? You are not able to
press the button to listen to the sms message body, cause it would just pause/resume
the song instead.
So what is the
workaround?
Anyway, there is
always another way out, right? Please proceed.
am force-stop
packagename this linux command could
force stop all process from this package
PM List Packages -------This Linux command will display all
the apps installed on your phone
PM disable
com.maxmpz.audioplayer -------this
Linux command would disable the application including all process and service. We
may call it like frozen. Your device would not recognize this app like it has
not been installed.
PM enable
com.maxmpz.audioplayer ------this Linux
command would enable the application to make the device recognizes this app has
well installed.
Simply use tasker
run shell with root for this command or you may use locale excute plugin for
tasker if you prefer.
By the way, there
is a better tool for you, it is secure settings for tasker. After installed,
you will find the option of package state(package manager for some other
devices), open this option, select the app of Poweramp, then you will see 3
options below for you to pick. On, Off, Toggle. I guess it might be much more
convenient anyway.
Well, once the app
has got frozen, it will not be able to control the headset button anymore. At
that time, you may press the headset button to listen to the incoming sms
message body.
Profile 1:
Context 1:
state-hardware-media button, button: next, Grab checked ------for android 2.2+, this option is available to grab the
control priority for headset button if any other media player installed. PS. You
better not pick “play” button, cause if you accidently click twice, it would
fire to call back for your last phone call.
Context 2: state-app-unread
text ----------this context is used to avoid the
normal situation while there is no incoming sms, so tasker would not bother
other media player to control the headset button.
Action:
variable-variable set, name: %MEDIABUTTON, to On
Profile 2:
Context 1: event-phone-text
received, type: sms ------- I have tested
if using unread text as context, if you didn’t read the previous sms, and later
there is another new message incoming, it would not fire.
Context 2:
state-hardware, headset plugged
Action 1:
plugin-secure settings, package state, poweramp set disable -----------in some othe android device, it
could be package manager instead.
Action 2: task-wait
5 seconds -----------this action is to give secure
settings enough time to carry on its job, since to do this would require root
access.
Action 3: misc-say,
text: you have got a new message from %SMSRN, press next button to listen,
engine: default (if
China
user, please pick another TTS which supports Chinese.), stream:
media
Action 4: task-wait
30 seconds until %MEDIABUTTON ~ On -------this step is to
give you enough time to press the play button, if you didn’t, it will go
activate poweramp on instead of saying the message body.
Action 5: task-If
%MEDIABUTTON ~ On
Action 6: misc-say,
text: %SMSRB, engine: default (if China
user, please pick another TTS which supports Chinese.), stream:
media
Action 7:
variable-variable clear, name: %MEDIABUTTON
-------this is to clear the variable value
after done saying the message.
PS. You may add one more action here running
sl4a script to mark current sms as read. So you don’t have to go back to the
message inbox to clear wipe it off.
Action 8:
task-goto, action number 10 -------this step is to pass through to activate poweramp
after done saying the message
Action 9: task-else ---------if you didn’t press the play button in 30 seconds,
this action would fire.
Action 10:
plugin-secure settings, package state, poweramp set enable
Action 11:
task-wait, 6 seconds
Action 12: plugin-autoshortcut,
activity, select: com.maxmpz.audioplayer.StartupActivity -------I did try to
use tasker load app, but it doesn’t work very well most of time.
PS. You may use wait 5 seconds, then Go home
right there after action 8, optional for you.
Action 13:
task-end If
Tasker to answer incoming call by pressing power button
nowadays, the smartphone is getting bigger in size, eg. samsung galaxy note and note 2, sorta big in size, which you will have to use a leather protective case to cover it up.
if so, there will come up with one problem, while there is an incoming call, you would get pretty dizzy to pick up the call.
if you wish there is a way to make this easier, here we go~
this profile will be very helpful for your problem.
simply press the power button, tasker will help you pick up the call immediately. you may just go ahead to talk on the phone.
profile:
context1: state-incoming call
context2: state-Display Off
action1:input-Button, call
action2:task-Stop # this tasks will be stopped right there after picked up the call.
Tasker to proximity screen on
in my previous entry, i posed an idea how to use the built-in proximity sensor to turn the screen off and locked. hereinafter i will show you how to use it vice versa.
Profile: (proximiy screen on)
context1:state-sensor-not proximity sensor,
context 2:state-display-display off
action: (Android 4.0+) display-turn on, if available (Android 2.3-)plugin-secure settings,configuration -wake device
if you want your phone keyguard off while the screen turns on, use display, keyguard off action, please.
NB. please make sure in tasker preference interface, you have set the proximity sensor option to "Yes", so that, the proximity sensor would stay active after the screen turns off by default.
Subscribe to:
Posts (Atom)
.jpg)
.jpg)