Wednesday, April 17, 2013

Through tasker to send google talk message command for remote control via SL4A script


Through tasker to send google talk message command for remote control via SL4A script

 

I previously posted an entry about how to remote control android devices even on PC. And now this entry would be around how to send google talk message on your android device by a tasker shortcut created on launcher desktop.

 

Of course, to do that, you firstly need to  install “Python for Android" and the tool “SL4A” in your android device.

 

 

Step 1, please create 3 variables, %IM_USER, %IM_PSWD and %IM_TO in Tasker Variable tab. Each variable denotes the specific meaning referred to the form below.

 

Parameter
Required?
Description
%IM_USER
Yes
Your gTalk user ID, including the @gmail.com part
%IM_PSWD
Yes
Your gTalk password
%IM_TO
Yes
The address to which to send the IM
%IM_TEXT
Yes
The IM text

 

 

Step 2, create a new notepad file in the folder of sdcard/sl4a/script, copy the script context below and paste it all, then rename the file into sendIMupdated.py with .py as postfix. Or you may open SL4A tool and then click Add a new script, then paste the content in it. You may refer to the original post on link as follows to get to know more about SL4A. http://tasker.wikidot.com/sendim

 

 

import sys,xmpp

import android

droid = android.Android()

 

_SERVER = 'talk.google.com', 5223

 

try:

  IM_user = droid.getIntent().result[u'extras'][u'%IM_USER']

except:

  droid.makeToast('IM_USER missing')

  sys.exit(1)

 

try:

  IM_pswd = droid.getIntent().result[u'extras'][u'%IM_PSWD']

except:

  droid.makeToast('IM_PSWD missing')

  sys.exit(1)

 

try:

  IM_to = droid.getIntent().result[u'extras'][u'%IM_TO']

except:

  droid.makeToast('IM_TO missing')

  sys.exit(1)

 

try:

  IM_text = droid.getIntent().result[u'extras'][u'%IM_TEXT']

except:

  droid.makeToast('IM_TEXT missing')

  sys.exit(1)

   

jid=xmpp.protocol.JID(IM_user)

cl=xmpp.Client(jid.getDomain(),debug=[])

 

con=cl.connect(server=_SERVER)

if not con:

  droid.makeToast('ERROR: could not connect')

  sys.exit()

 

auth=cl.auth(jid.getNode(), IM_pswd, resource=jid.getResource())

if not auth:

  droid.makeToast('ERROR: could not authenticate')

  sys.exit()

 

cl.sendInitPresence(requestRoster=0)

 

cl.send(xmpp.protocol.Message(IM_to,IM_text, typ='chat'))



 

 

Step 3, in Tasker, Tasks tab, create 1 or 2 more tasks depending on your needs of message command.

 

e.g.:

 

Task: (Shut Off)

 

Action1: Variable-Variable Set-Name: %IM_TEXT, To: shutoff (or any other specific message command you like, set the corresponding trigger action on the receiver end android device, please refer to my previous entry about remote control part)

 

Action2: Script-Run SL4A Script-[Name: sendIMupdated.py Terminal: Off (means don’t check this option) Pass Variables: %IM_USER, %IM_PSWD, %IM_TO, %IM_TEXT ]

 

 

Step 4, after done, go back to your launcher desktop, create a shortcut, point to tasker cut, then select the task “Shut Off” you just created, select an icon for this shortcut btw.

 

Finally, you may simply press the shortcut to send specific message command to remote control your android device easily.

Through Tasker to remote control multiple android device or PC via Google talk


Through Tasker to remote control multiple android device or PC via Google talk

 

I always thought about a method to remote control between my android HTC phone and Tablet Pad, or even control it on PC.

 

I firstly considered of Remotecontrol plugin for Tasker, the famous 3rd party plugin for Tasker. However there is a limitation for the Lite version, and it seems it is not that easy to buy the paid version in China since I don’t have a Credit card. Most importantly, Remotecontrol is using Google appost.com as its remote server. As we know, it is blocked access in our China. So, passed.

 

So I went on searching on the Tasker forum and happened to find a famous android software named AVX (Android Voice Xtreme). It has a Tasker plugin interface built-in. I ran through the Video Tutorials and an idea suddenly flashed across my mind.

 

Since AVX is communicating between android devices or PC via Google talk message command, that means I also may use this method as the way out.

 

Okay, let us get into the real matters.

 

Step 1, create 2 or more google mail accounts up to your needs of remote control device. I learned a famous website from the tutorials, it is www.jabber.org, which may be compatible in multiple IM software. That means you may use 1 account to log in multiple IM software to transmit your command.

 

Step 2, you may better open your google mail box and activate/enable the chat feature in settings something, if you just signed up google mail account. ------that is to make it possible to send command message in any browser of android device or even PC incase you don’t feel like install Google talk client.

 

Step 3, please add your google mail accounts along as friends each other in Chat.

 

Step 4, go back to implement the XML in Tasker. First, set up a simple profile, details as below.

 

Profile: (Gtalk Notify) ------you must name the profile, so as to move on to the next stag.

 

Context: Event-UI-Notification, Owner application: Talk

 

Action: Media-Play ringtone, alarm, source: (select an audio file as the notify alert)

 

Done!

 

Step 5, export the profile (Gtalk Notify) to your SD card. After done, you may delete the profile you just created. Then go to your SD card-Tasker-Profile, find the XML you just exported. Open it via ES text editor or other Text editor, modify the XML as below.  ------------in some other 3rd party ROM or android 4.0 above ROM, it might be a slight difference for Gtalk, please check the Correct name for Gtalk in /data/data/com.google.android.****(vary up to different ROM)

 

You will see:

<appClass>com.google.android.talk.SigningInActivity</appClass>
<appPkg>com.google.android.talk</appPkg>

 

Then, replaced "com.google.android.talk" with "com.google.android.gsf"

 

It changes to be:

 

<appClass>com.google.android.talk.SigningInActivity</appClass>
<appPkg>com.google.android.gsf</appPkg>

 

 

Step 6, go back to Tasker, on the profile tab, long press to import the modified XML from SD card. Then you may test it by sending a message from your another google mail account via Gtalk. You will hear the notify ringtone by then. If so, it proves it works. Of course, you should set up your Gtalk Notifications as “Notification status bar”.

 

 

Step 7, clone the profile (Gtalk Notify), then edit the Action part into any variable as you like. Each specific message command would trigger the specific action.

 

 

e.g. input message “p2p” to build WIFI P2P connection between android devices via Gtalk

 

Action1: task-If, %NTITLE ~ *******@gmail.com: p2p  -------enter control end Google mail account ID and remember there is a Space after :, p2p is the specific command I set up for opening WIFI P2P connection between android devices. Please note, %NTITLE includes google mail account ID and your message command.

 

Action2: net-mobile data, set off  -------you may set on, I just don’t wanna waste my mobile data stream. Cause if on, it would turn into wifi hotspot, sharing your 2G/3G mobile data stream with connected android device.

 

Action3: net-wifi techering, set on

 

Action4: Plugin-autoshortcut, configuration, select "Activity", then select "com.estrongs.android.pop/com.estrongs.android.pop.ftp.ESftpshortcut". -----This is to run ES FTP servcice so as to build FTP connection. You will need to install autoshortcut plugin and quickshortcutmaker to get this feature, of course you may just use “send intent” to get it done, but to do that, you need to know the exact specific shortcut package name like above listed.

 

Action5: task-else

 

Done!

 

What is more, since p2p command would automatically turn off WIFI, I create a corresponding exit profile to turn it on once I close ES file explorer.

 

Profile:

 

Context 1: Application: ES File Explorer

Context 2: State-Net-Mobile Network, 2G, 3G, check “invert”  -----That is to make sure in wifi Hotspot mode, it would not get triggered.

Context 3: State-Net-Wifi connected, connected to “********”, check “invert”  ------This is made to double ensure in normal mode, it would not get triggered.


Action 1: Net-WIFI, set on

Action 2: Plugin-Autoshortcut, select “one-key task killer” ------This action would simply kill all ongoing foreground applications, So you will have to set up some important apps in white list. After done, the ES FTP server would also get killed as well.

 

After done, long press on the task you just created, select “Move to exit” in the pop-up menu.

 

BTW, i also set up a profile to shut off P2P mode in your assosiated phone, cause we know, in p2p mode, wifi would turn off, and mobile data is off too, so Gtalk message doesn't work this way, i figured out an alternative, by using IPmsg (http://ipmsg.org/index.html.en), we are able to connect each other via p2p wifi connection and send IM message command through IPmsg.

how to make it? Similar just like the profile I implement above. Problem? PM me, please.

 

 

Conclusion, you now may remote control your android devices on any android device or even PC, by sending the specific message command to trigger the action you implemented.

 

 

Like, send location data, find my phone, forward SMS, etc. Anything you would just imagine, Tasker may probably help you make it done.

Tasker to auto detect cellphone signal


Tasker to auto detect cellphone signal

 

 

While you are in the elevator or ridding a bus running through a tunnel, were you ever worried if there is somebody calling you yet you got out of service?

 

It must be sorta inconvenient checking your cellphone again and again.

 

So how could we figure a ways to work this out?

 

Yes, tasker could aways be helpful for your life.

 

Please take some times to look into the profile to see how tasker is capable. Via this profile, tasker are able to auto detect if your cellphone is out of range and alert you shortly by sound, vibrating, notification alert. If wait some seconds, still no reception, tasker will turn airplane mode on and off to make sure your cellphone would re-search the nearby cell towers.

 

If this action fails to get the signal, will loop in 5 minutes until the signal back.

 

Attractive? Can’t wait to see the details?

 

 

Profile: (No signal alert)

 

Context: State -Variable-Variable Value, Name: %CELLSRV, Matches, Value : noservice (tested with Noservice and failed to work, anybody knows why?)

 

Hit Done- New Task (Call it whatever you like)

 

Action1: Task- Wait 15 seconds (give it 15 seconds or less depending on the signal search speed, while being switched from Airplane mode or rebooted)

 

Action2: Task- If, %CELLSRV ~ noservice (these 2 actions above are to detect and exclude the situation of being rebooted or being taggled from Airplane mode, if so, this profile would not move on)

 

Action3: Alert-Vibrate (for any amount of time. I use 600ms since it'll probably be in my bag when it happens, but I'd still like to get alerted just in case)

 

Action4: Alert-Notify LED, Title: No Service, Text: Ouf of range (To let you know what is going on)

 

Action5: Media- Play ringtone, Type: alarm, Sound: (select audio source you like)

 

Action6: File-Write File - File: Tasker/No Service Log.txt (or whatever file you want to log to), Text: %Date, %Time. Check 'Append' , Hit Done. (check 'Append', so that, each new recored would be texted as a new line as follow.)

 

Action7: Task-Wait, 15 seconds, If, %CELLSRV ~ noservice (Checks again if it is still no signal)

 

Action8: Net-Airplane mode, Set On, If, %CELLSRV ~ noservice

 

Action9: Task- Wait 3 seconds

 

Action10: Net-Airplane mode, Set Off

 

Action11: Task- Wait 5 minutes

 

Action12: Alert-Notify Cancel, Title: No Service, If, %CELLSRV !~ noservice

 

Action13: Task- Goto Action Number 8, If, %CELLSRV ~ noservice (Loop action to make sure the signal back if the previous action doesn’t help.)

Tasker to set smart auto airplane mode


Tasker to set smart auto airplane mode



We may already be familiar with quite some airplane mode software, and wondering why we still need tasker to do this job?


Let me tell the difference between tasker and the others airplane mode apk.


Most airplane applications just set up the timeline like what time to what time you want it be on and off.


Tasker is different, let us say powerful and brilliant. You may set up a time context, and once time is up, tasker would notify you and ask you if you wanna proceed or not. If you are still playing on the phone, I guess you don’t feel like to be cut off from the internet suddenly.


Well, if time is up and you didn’t play on the phone, after a pre-defined wait time, your phone will go into airplane mode, which would help you save battery and mobile data as well.


In some particular situations, like time is up and you tap on the button to go on playing, minutes later, you are done playing, if you click on the airplane mode widget provided by your system or any 3rd party toggle widget apps. The profile will turn inactive automatically. And if minutes later, you change your mind and turn off the airplane mode toggle widget, the profile will get activated immediately. So you don’t have to worry if you forget to turn the airplane mode on later after you are done playing.



Profile 1: (airplane mode)

 

Context-time-from 01:00 till 07:00

 

Task: (airplane set)

Action 1-task-if %SCREEN~Off

 

Action 2-task-wait 15 minutes


Action 3-net-airplane mode, set On, if %SCREEN~Off

 

Action 4-task-else

 

Action 5- alert-popup task buttons, text-Go sleeping? , Task1-play, Task2-sleep, if %SCREEN~On


Action 6- task-wait 1 hour, if %SCREEN~On  -------- if screen is on, will wait, if not, will not wait and move onto the next action.


Action 7- task-Goto, type-action number 1, if %AIR~Off   -----------with this if statement set, tasker could go on the loop until airplane mode is set on.


 

Exit task:

Net-airplane mode, set off   --------- with this exit task, when end time comes up, tasker would automatically turn off airplane mode for you.

 

In the tap of Tasks, create 2 separate tasks,

 

Button 1: (play) action-net-airplane mode, set off, icon

Button 2: (sleep) action-net-airplane mode, set on, icon

 

 

Profile 2: (airplane plus)

 

Context 1: state-net-airplane mode, invert checked

Context 2: state-tasker-profile active, matches "airplane mode"

Task:

Action 1: task-wait 15 minutes

Action 2: task-perform task, name: airplane set, if %AIR ~ Off

--------this second profile is very important, after set, if your phone has gone into airplane mode, the task of first profile would stop automatically, and if you manually turn airplane mode off after it is turned on, this second profile would get fired again automatically. so that you don't have to manually turn it on later after done playing a while.




 

Tasker to proximity screen off


Tasker to proximity screen off

 

If you are using proximity screen off pro or smart screen off, you may know how convenient it is to automate our lives via built-in proximity sensor.

 

Now I am going to show you how tasker done this job to replace proximity screen off pro.

 

Before all of it, just a reminder, you may go to tasker preference interface, and click on the tab of monitor, then pull down the screen, you will find the option for proximity sensor, “No” means proximity sensor will shut off when the screen turns off, back on when the screen turns on. I guess it might avoid any unnecessary loss for the sensor since you may prefer saving more battery.

 

Profile 1: (proximity screen off 1)

 

Context-state-sensor-proximity sensor

 

Action-variable-variable set-name %Proximity, to On

Exit action- variable-variable set-name %Proximity, to Off

 

 

Profile 2: (proximity screen off 2)

 

Context 1-state-sensor-proximity sensor

 

Context 2-state-display-display orientation, portrait  # if you are playing some game which requires full screen in landscape, this profile would not interrupt.

 

Context 3-state-phone-call, type-any, invert    # this action is to avoid the situation while incoming or outgoing call occurs.

 

Context 4-state-app-not camcorder, camera, flashlight   # for some specific apps, you might not want to be interrupted as well. Eg. Like you are using flashlight.

 

Action 1-task-wait 5 seconds       # give you 5 seconds to avoid some unexpected cases.

 

Action 2-display-system lock, if  %Proximity~On   # 5 seconds later if it is still being fired, then system lock the phone.

 

 

Tasker to mark unwanted or irrelevant unread sms as read and auto delete sms message via sqlite command

 

 

hi, I have been searching for a solution in the Internet regarding this issue. I believe sl4a script is able to work, however it is sort of difficult for me to study on it.

 

finally I found sqlite command is much better than that.

 

You see? simply use 'update' command, we may modify the SMS States as read in sms sqlite database.

 

-------First of all, you should root your phone first, or else, run shell action would not work properly.

 

 

Sqlite knowledge:

 

Okay, before we move onto tasker work, i wanna explain some specific knowledge regarding sqlite for you guys.

 

For sqlite command, “update” means edit and replace something with something. There is a fomular like below.

 

And for some fuzzy match keyword, you will have to use the command “like” and includes the wildcard “%” right after the keyword.

 

e.g.  update target catalog set column id=’new value’ where column id=’value’ and column id like ’keyward%’;

 

KKKKK denotes the particular keyward in the sms message body, remember there is ; in the end

 

And according to android sms sqlite database analysis, we will see “address” denotes incoming/outgoing phone number, and “read” denote the status of being read or unread. 0 means it is unread, 0 means it is already read. Body denotes to the sms message body.

 

So that is why we have to set the script like that. To change the read status from 0 into 1 within the sqlite database.

 

-------Most of stock ROM, the sms message database is located in data/dtata/com.android.providers.telephony/databases/mmssms.db

 

If you would not find the sms database in that folder, please search and modify the path accordingly.

 

 

------There is a thing, this action only affect the android sms database, but it doesn’t affect the ongoing notification, so after action took effect, the unread sms notification alert would not dismiss from the status bar. When you tap into the sms builtin apps, you will the sms has already been marked as read.




Okay, now let us get into the real matter on tasker.

 

 

*Auto mark unread specific sms as read*

 

Step 1: you should make sure sqlite3 system file is installed in your phone system, or else, the script would not work. You may go search in the play store to find a software named sqlite installer root (required root access), which would help you get the proper sqlite file installed in your system.

 

------(Tips: if you run the sqlite script and get the error code like “sqlite file not found” or “bad command” something, that means your phone system lib doesn’t have the proper sqlite 3 file.)

Android 4.0 earlier,  hit this link: http://bit.ly/sqlite3

Android 4.1+, please hit this link:http://bit.ly/sqlite3-for-jb

 

Step 2: create a foler named “sql” , and then create a txt file in that foler. Afterwards, copy the script below paste in the txt file. After done, rename the txt file into unreadsms.sql, which is with .sql as the postfix.

 

update sms set read='1' where address='XXXXXXX' and body like 'YYYYYYY%';

 

------XXXXXX denotes the receiver phone number which you would like to mark it as read, YYYYY is the particular keyword which to identify the specific SMS you would like to make it as read.

 

Step 3: Well, now you may just set up the action part like below in tasker or test it via Gscript to see if it works. (you may search and find out Gscript in play store. A very useful software to run shell command.)

 

Action: script-run shell-command: sqlite3 /data/data/com.android.providers.telephony/databases/mmssms.db < /sdcard/sql/unreadsms.sql

Check “Use Root” 

 

 

 

*Auto delete unwanted specific sms *

 

Step 1: make sure sqlite file is well installed in your phone system.

 

Step 2: create a foler named “sql” if you don’t have, and then create a new txt file in that foler. Afterwards, copy the script below paste in the txt file. After done, rename the txt file into delsms.sql, which is with .sql as the postfix.

 

delete from sms where address='XXXX' and body like 'YYYYY%';

 

(please refer to the above-mentioned sqlite knowledge to see more details)

 

Step 3: Well, now you may just set up the action part like below in tasker or test it via Gscript to see if it works.

 

Action: script-run shell-command: sqlite3 /data/data/com.android.providers.telephony/databases/mmssms.db < /sdcard/sql/delsms.sql

Check “Use Root” 

Python SL4A script to mark specific unread sms message as read


Python SL4A script to mark specific unread sms message as read

 

In my previous entry, I post an idea about how to mark any specific unread sms message as read via sqlite 3 command.

 

However this method has a serious flaw which could not be fixed anyway.

 

Via sqlite 3 command, you really are able to access the message database and change the specific message state from unread to read, but the problem is this operation could not affect the android message API. Everything you have done is done just within the message database. That means if you go back to the message inbox after you done with sqlite 3 command, you will see the specific message which you were trying to mark as read is still in the state of unread. (PS. Please note, not only sqlite 3 command, but also via python sl4a script, both methods could not update/remove the message app unread notify displayed on the launcher desktop or notification bar. Cause this is related/linked with the android default notification system instead.)

 

Maybe you will say it does not matter at all even if sqlite 3 command has this problem.

 

I should let you know it does matter indeed. If you ever use tasker unread text context to perform some tasks, you will soon find out that the importance to be able to change the message unread state within the message API. Cause tasker will consider there is still an unread text out there and then fire the profile, which you did not expect to be done.

 

So what is the workaround? Python sl4a script should be the way out of this.

 

After you input the hereinafter python script into the sl4a client for android, you may run this script in tasker via run sl4a script function.

 

Allright, let us get into the business.

 

Please be discreet of the indentation of each line, cause it is the basic rule of python language. Also you had better be careful of the text coding format, if you are about to copy it and paste. Cause it might change the coding format into windows coding or ACSII format, which the script would fail to perform.

 

NB. XXXXX stands for the specific sender cellphone number, and YYYYYYY is the specific  keyword of the incoming unread message which you expect to mark it as read.

 

If you have any questions, please feel free to leave me a comment, I will see what I can do for you.

 

 

Script content:

 

 

 

# coding:utf-8

 

import android

 

droid = android.Android()

 

 

msgIDs = droid.smsGetMessageIds(True, 'inbox').result

if msgIDs > 0:

 

  for msgID in msgIDs:

 

    message = droid.smsGetMessageById(msgID, ['address','body']).result

 

    str1 = message['address'].encode('utf-8')

 

    str2 = message['body'].encode('utf-8')

 

    if str1.find('XXXXXXX') >= 0 and str2.find('YYYYYYY') >= 0:

 

      msgRead=[0]

 

      msgRead[0]=msgID

 

      droid.smsMarkMessageRead(msgRead,1)