9/22/2013

Mark Unread Sms As Read Thoroughly via Tasker

For quite some time, I use a task to mark unread sms as read programmatically via Tasker. But these method worked not so effectively.

Firstly, I adopt the database-process-directly way. With a specific SQL syntax, I can mark all unread sms as read. Like this:

Run Shell [ Command: sqlite3 /data/data/com.android.providers.telephony/databases/mmssms.db "update sms set read=1 where read=0" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: Continue Task After Error:On ]

Yes, it mark the unread sms as read. But it can’t refresh the unread count in “Messaging” app. And it can’t clear the unread notification in notification bar.


Then I tried the “SL4A+Python” method(refer here). Yes, it can mark unread sms as read and reset the unread count in “Messaging App”. But it can’t clear the unread notification too.


With the “SL4A+Python” method, we made a step forward. But it’s not very perfect. As for notification problem, I had looked up some information. It’s not allowed to clear notification of other app programmatically in android. The notification can be cleared by the tapping of user or by the app itself. We will be taken to the main window of app when we tapped the specific notification normally. And it seems not to be a friendly way. So we can consider about the other way. But app will not clear its notification at our sweet will. I’ve been stuck here for a long time.

Until recently, the principle behind "Launch Camera App" inspired me to try to do something similar about the package of "Messaging" app.



I tried it and it proves me right on MIUI 3.9.6. Now I can mark unread sms as read thoroughly via Tasker! Here is the flowchart:


More: Clear An App's Notification

Launch Camera App With Predefined Settings via Tasker

During the mid-autumn vacation, someone requested help in my QQ troop of Tasker (ID: 333174356), about how to launch camera app with predefined parameters(e.g. picture size, picture quality, and so on) for specific situation. Because of some other reason, I just give him an idea to try, and I haven’t put it into effect. After the vacation, I have chance to try my idea and it turns out the idea is right. Realized the principle behind the idea may be helpful to more similar situations, hereinafter I will explain the idea in detail, and take the “picture size” parameter of rear camera for example.




Firstly, we know that the “Media -> Take Photo” action will open the camera with custom parameters and then take photo automatically. Unfortunately, we can’t use this action to open the camera with custom parameters just for preview, then take photo manually.


I know a specific intent, which named “android.media.action.IMAGE_CAPTURE” in android, can launch the camera app with preview window. I’ve tried it before. And I find it not support camera parameters. I mean that it only open the camera window with default settings which we can’t change it programmatically.

Below shows the intent I tried:

Send Intent [ Action:android.media.action.IMAGE_CAPTURE Cat:Default Mime Type: Data: Extra: Extra: Package:com.android.camera Class:com.android.camera.Camera Target:Activity ]

As everyone knows, most settings are stored in the format of file, even databases. After some digging, I found the file (data/data/com.android.camera/shared_prefs/com.android.camera_xiaomi_preferences_0.xml) contains the “picture size” setting. We can change the value of “pref_camera_picturesize_key” node in the xml file programmatically. Then we launch the camera app. At last, we can restore the “picture size” setting.


Be careful! If you only follow these steps, the loaded camera app will not meet the desired effect. Because the camera app maybe can’t realize some settings changed, I think. There is a trick that you can disable and enable the app to take into effect. It’s very probably that the app will re-read the preferences file after the disable and enable operation. I guess the camera app read the settings and always runs in background when the device boots. We can disable and enable an app manually in android.


Of course, we can do this with the “Secure Setting” plugin for Tasker.



As for how to change the setting string in the preferences file, you can use shell script(especially “sed”, “awk” command) or use two files for renaming and swapping.

Here is the flowchart of the whole idea. (I've tried it successfully in MIUI 3.9.6)


9/18/2013

Launch App From Its Name

Long time ago, I want to launch app when AutoVoice recongnized the app name I said. Unfortunately, the "Launch App" will not support app name as variable at present. After some digging, I found a way out. Here it is.

A launcher is something similar with desktop shell in Windows, I think. You should know most app will leave its package information in the database of launcher when installed. So we can dive into the database of launcher and pull the specific information out. The figures below shows the database of MIUI launcher in my MIUI ROM. You can find the database in path /data/data/com.miui.home/databases/launcher.db.


Figure 1. tables in launcher.db


Figure 2. records in the table "favourites"


Figure 3. record of app named "SwipePad"

In "Figure 3", the field "intent" is very important for us. We can launch app with "am start" command in Android shell. You can type "am start" command in shell to get detailed help of this command.


Figure 5. "am start" command help

We can launch specific app with "am start" command when we extract useful intent information from corresponding "intent" field.

Here is one of my AutoVoice task which aimed to launch app from speech:

Task: LaunchApp
A1: Run Shell [ Command:sqlite3 /data/data/com.miui.home/databases/launcher.db "SELECT intent FROM favorites WHERE intent IS NOT NULL AND title LIKE '%%avcommnofilter%' LIMIT 1;" Timeout (Seconds):0 Use Root:On Store Output In:%intent Store Errors In: Store Result In: ] 
A2: If [ %intent Is Set ]
A3: Variable Search Replace [ Variable:%intent Search:#Intent;action= Ignore Case:On Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With:am start -a  ] 
A4: Variable Search Replace [ Variable:%intent Search:;category= Ignore Case:On Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: -c  ] 
A5: Variable Search Replace [ Variable:%intent Search:;launchFlags= Ignore Case:On Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: -f  ] 
A6: Variable Search Replace [ Variable:%intent Search:;component= Ignore Case:On Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: -n  ] 
A7: Variable Search Replace [ Variable:%intent Search:;end Ignore Case:On Multi-Line:Off One Match Only:Off Store Matches In: Replace Matches:On Replace With: ] 
A8: Run Shell [ Command:%intent Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ] 
A9: Else 
A10: Music Play [ File:Tasker/Notify/Dialog/sorry.wav Start:0 Loop:Off Stream:3 ] 
A11: End If 

Note: 
1. Records are case-sensitive in SQLite database. My former task can not process this situation.
2. Few apps can't show on desktopof launcher, and even can't be found in launcher.db. You can't launch it in this way.
3. Although I talked here with taking the MIUI launcher as example, I think the principle will be same with other launcher. Maybe databases differ!
4. If you want do it with a separate app, you can try AutoLaunch(paid).
5. Some useful files for all packages installed:  /data/system/packages.list  /data/system/packages.xml
6. A useful command to list packages: "pm list packages -f"

9/10/2013

How To Set Default App for Various Categories via Tasker

Sometimes we want to set default application for some certain actions.(Just like building associations) Following figure shows the dialog of setting default app for audio player.


You can use Default App Manager or change the setting manually.(refer here for more information)

Following figures show the UI of Default App Manager.




Recently I came up with an idea about how to set default app for various categories via Tasker.

After looking up information and doing several tests, I can make it through now. Hereinafter I will show you how. Note that you can't set default app in the background silently in Android.

You can callout the dialog of setting default app for various categories after sending specific intent parameters to com.android.internal.app.ResolverActivity. Intents are messages of android applications somehow. You can send intents via the “Send Intent” action directly or “Run Shell” action with specific commands. I suggest you’d better use the “Run Shell” action, because some intents may need some specific limits of authority.(Don’t forget “Run Shell” action have option of using root while “Send Intent” just act as usual) Here we go!

<app.View.Resolver>


Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.apk" -t "application/vnd.android.package-archive" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<audio.View.Resolver>



Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.mp3" -t "audio/*" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<audiostream.View.Resolver>



Run Shell [ Command:am start -a android.intent.action.VIEW -d "http:///null.mp3" -t "audio/*" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<video.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.mp4" -t "video/*" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<videostream.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "http:///null.mp4" -t "video/*" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<image.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.jpg" -t "image/*" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<image.GetContent.Resolver>
Run Shell [ Command:am start -a android.intent.action.GET_CONTENT -d "file:///null.jpg" -t "image/*" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<image.Crop.Resolver>
Run Shell [ Command:am start -a com.android.camera.action.CROP -d "file:///null.jpg" -t "image/*" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<browser.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "http://null.com" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<calender.Edit.Resolver>
Run Shell [ Command:am start -a android.intent.action.EDIT -t "vnd.android.cursor.item/event" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<email.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "mailto:" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<epub.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.epub" -t "application/epub+zip" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<mobi.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.mobi" -t "application/x-mobipocket-ebook" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<doc.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.doc" -t "application/msword" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<docx.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.docx" -t "application/vnd.openxmlformats-officedocument.wordprocessingml.document" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<ppt.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.ppt" -t "application/vnd.ms-powerpoint" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<pptx.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.pptx" -t "application/vnd.openxmlformats-officedocument.presentationml.presentation" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<xls.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.xls" -t "application/vnd.ms-excel" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<xlsx.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.xlsx" -t "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<pdf.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.pdf" -t "application/pdf" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<txt.View.Resolver>
Run Shell [ Command:am start -a android.intent.action.VIEW -d "file:///null.txt" -t "text/plain" -n "android/com.android.internal.app.ResolverActivity" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: ]

<launcher.Main.Resolver>
Send Intent [ Action:android.intent.action.MAIN Cat:Home Mime Type: Data: Extra: Extra: Package:android Class:com.android.internal.app.ResolverActivity Target:Activity ]

You can make a scene to list every one of the “resolver” task above showing as an icon. Every icon is bind to specific task to perform. Then you can set default app for specific categories when the correspondent icon is taped.

Following figure shows a simple UI of my creation.



Note: 
1. AFAIK, you can’t retrieve the default app name for specific categories via Tasker.
2. You can try this tip, if you want to "Control which app is the default for an action (root only)".

9/09/2013

Custom the display of Operator name via Tasker

The figure following show the custom operator of mine:


The setting UI for custom operator name:



Hereinafter I will show you how to custom the display of operator name via Tasker.

I found the system save the operator name in /data/data/com.android.providers.settings/databases/settings.db

The system table of Setting.db contains operator name-value pairs(records, its professional name). We need to change the value of specific SIM operator.



Note that table may have more than one records whose name with “MOBILE_OPERATOR_NAME_” prefix. Trial and error, I found the numbers which following “MOBILE_OPERATOR_NAME_”, mean the MCC+MNC part of IMSI. In China, 46001 means China Unicom, While 46000, 46002,46007 mean China Mobile Communication(CMCC for short).

But how can Tasker judge the SIM inserted represent which operator? Firstly, you may think of specific part of phone number. But here I will tell you that Android saystem can’t get the exact phone number for some new SIM card unfortunately. I got nothing with my SIM card of CMCC when I try to use the built-in variable %PNUM.

Things seem to be stuck for a time. Finally the problem was solved when I know the first 6 characters of SIM numbers(refer to ICCID) differ from operators internationally. ASAIK, 898600 was assigned to CMCC while 898601 was assigned to China Unicom. So I get my ideas into shape finally.



Tips: You can set special characters or symbols as personalized operator name. A simple way is to use special symbols in Input Method.

As for detailed steps, you can see below.

         Step 1: Variable Clear [ Name:%Runcmd Pattern Matching:Off ]
Clear the query variable

         Step 2: Variable Query [ Title: Please Input Custom Operator Name: Variable:%Runcmd Input Type:Normal Text Default: Background Image: Layout:scene_VarQuery Timeout (Seconds):40 Show Over Keyguard:On ]

         Step 3: Stop [ With Error:Off Task: ] If [ %Runcmd ! Set ]

         Step 4: Variable Set [ Name:%sim To:%SIMNUM Do Maths:Off Append:Off ]

         Step 5: Variable Section [ Name:%sim From:1 Length:6 Adapt To Fit:Off Store Result In:%sim ]

         <CMCC>
         Step 6: Variable Set [ Name:%spn_list To:46000,46002,46007 Do Maths:Off Append:Off ] If [ %sim = 898600 ]

         <China Unicom>
         Step 7: Variable Set [ Name:%spn_list To:46001 Do Maths:Off Append:Off ] If [ %sim = 898601 ]

         Step 8: Variable Split [ Name:%spn_list Splitter:, Delete Base:Off ]
         
         Step 9: Airplane Mode [ Set:On ]

         Step 10: For [ Variable:%spn Items:%spn_list() ]

         <only change specific SIM operator name>
         Step 11: Run Shell [ Command:sqlite3 /data/data/com.android.providers.settings/databases/settings.db "update system set value='%Runcmd' where name='MOBILE_OPERATOR_NAME_%spn'" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: Continue Task After Error:On ]

         Step 12: End For 

         <change all SIM operator name>
         Step 13: [X] Run Shell [ Command:sqlite3 /data/data/com.android.providers.settings/databases/settings.db "update system set value='%Runcmd' where name like 'MOBILE_OPERATOR_NAME_%'" Timeout (Seconds):0 Use Root:On Store Output In: Store Errors In: Store Result In: Continue Task After Error:On ]


         Step 14: Airplane Mode [ Set:Off ]

Note: If you want to change current SIM operator in China, use step 1-2,14. Well, if you want change all SIM operator name in China, use step 1-3,9,13,14. 

9/08/2013

Something About MIUI Daily Motto

We will talk something about MIUI daily motto here.

What's MIUI daily motto?


MIUI daily motto is representative remarks from MIUI forum members everyday. When browsing MIUI forum, you will see the so-called MIUI daily motto as follows.(Of course, you can submit your own excellent remarks to the forum.)



How can we get the content separately?


I have strip the MIUI daily motto and built it into RSS feed URL. You can get it here. Here is the motto individual.


Custom info display on lock screen based on MIUI daily motto.

Grab the MIUI daily motto individual and save in database everyday at specific time, then show it on lock screen randomly. Here we go!

Step 1:  

Profile:(daily motto - update and save)

Context: Time [From 12:00 till 12:01]

Task: 1. "Mobile Data"[set on];
      2. "Wait"[1 second];
      3. "HTTP Get"[Server port: feed43.com/miuidailymotto.xml
                    Mime type: text/*](continue Task after error)

      4. "Variable Set"[%motto to %HTTPD];
      5. "If"{%HTTPR != -1}
             "Variable Split"[Name: %motto ;Splitter: <pubDate>]
             "Variable Split"[Name: %motto2 ;Splitter: </pubDate>]
             "Variable Set"[Name: %pubdate ;to: %motto21]
             "Variable Split"[Name: %motto22 ;Splitter: </title>]
             "Variable Split"[Name: %motto221 ;Splitter: <title>]
             "Variable Set"[Name: %Motto ;to: %motto2212]
             "Run Shell"[configure as follows]


           "End if"
      6. "Mobile Data"[set off]

Take a glance at motto.db.



Step 2:

Pull out MIUI daily motto randomly with sqlite3 from motto.db.

"Run Shell"(configure as follows)

As for other steps, you can refer my related notes.("Show Lock Info on Lock Screen")

Notice: the global variable "%MNT_SD" refers to SD card mounted path.

Now let's straighten out ideas with flowchart below.


Show Custom Info On Lock Screen

Do you want to display custom information(e.g. data traffic usage, new words/phases, motto) on lock screen? Here is my solution.


Environment:

1. MIUI ROM or of Any ROM support display owner info on lock screen.

2. Security Setting plugin for Tasker(maybe require Helper).


How to:

Profile: (update lock screen info)

Context: "Display off" event

Task: 
     1. Any action to get info content into variable %own_info ;
     2. "Security Setting -> Lock Screen Owner Info" [State:enabled; var: %own_info]


If all run well, you'll get custom info on lock screen like mine.(show English words of mine)



I use owner info to show English words from my new words collection in YouDao Dict database, or MIUI daily motto(here) randomly when phone is waked.

The following figure shows how can I pull out my new words collection randomly.



Note: I had use Tasker scene and display off/on context to show custom info or image on lock screen, but sometimes the overlay scene still show when I unlock the screen because of scene's slow response. Of course, you can try the scene method. 

Retrieve SD Card Mounted Path

Sometimes we want to set/get the external storage root path as global variable in Tasker, no matter which ROM we flash or update. Next time when you want to use file path in SD card, just use variable %MNT_SD as path prefix.

You can do it like this:

Profile:(Device Boot)

Context: "Event -> Device Boot"

Task: 1. "Wait[5 seconds]";

            /*wait 5 seconds to let system initialize some settings*/

      2. "Run Shell(use root)
                      [Command: cat /system/etc/vold.fstab | busybox grep "sdcard" | busybox awk '{printf $3}'

                       Use Root: check;
                       
                       Store Output In: %MNT_SD ]"

"Run Shell" action configure:


vold.fstab file in MIUI(/system/etc/):



Note: I had test it on my MiOneS phone(MIUI ROM). More info about vold.fstab file, please refer here.

9/05/2013

Tools or Language To Develop Applications On Android

Many people want to develop apps on Android for certain reason. There are some tools at their choice. Here is a part of list.

Java

As everyone knows, a lot of apps are developed by using Java language. You can find numerous resource about it.


App Inventor

A visual development environment for developing simple application on Android. It is published at about 2010. At about 2011, Google distribute the project to MIT. So it's a online product of MIT now. You can find it here.


Tasker AppFactory

Through the awesome app - Tasker, you can make some powerful creations. Then you can package and export your creation as an app. You can get it from Google Play.


SL4A

Scripting Layer for Android (SL4A) brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device. These scripts have access to many of the APIs available to full-fledged Android applications, but with a greatly simplified interface that makes it easy to get things done.
Visit SL4A homepage>>


Kivy + Python

Kivy - Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps.
Visit Kivy homepage>>

A brief experience of Kivy + Paython on Android, here you go.

9/03/2013

Excellent App Designed With Tasker

You can create and export your own app when using Tasker in concert with AppFactory. After exported, the package can run without Tasker. Here are some excellent apps designed with Tasker.

I can them app because they worked like application. They consist of some of Tasker profiles, tasks, actions, even some profiles etc, indeed. Maybe, you can call them "Tasker Creations".


Note: with source



Note: with source



Note: only package.



Note: with source.


Simple Music Player

Note: with source.



continue...

Automate Screen or Button Taps via Tasker

When using Tasker, sometimes we want to do some automation on screen e.g. screen or button taps.

At present, there are some ways can reach it.


1."Input" action

We can use actions in "Input" category(especially "Dpad" action and "type" Action) to do some simple click/tap.

An example: http://tasker.wikidot.com/auto-usb-mass-storage

2. Use script

Use some type of Script to do this. Yes, script may be the best solution for automation. Be careful! Sleep values might need some tweaking!
  
 
  2.1 Monkey Script

      Did you remember the "typewriter monkeys" theory? Certainly, the monkey immigrant to Android now. You can reference Android Develop Document for details if you want know parameters of monkey script. Or you can use the app named "Action Box"(Tasker plugin) directly. It providers a somehow "IDE" for monkey script.

     You may need to calculate the coordinate in screen. It's so hard.

In order to get the correct coordinates, on your device go to Settings -> dev options and turn on "show pointer location" then you can go into your app and tap on the correct location and it will display the x/y coordinates of the tap which you can input on that script. 
     Some docs about the monkey tool>>>.

  2.2 "Input" command in shell

      With "input" command in shell, we can simulate keypress event on Android. The keycode sucks!

      More info about "Input" command, here.

  2.3 Sendevent and Getevent command in Shell

      Android shell support sendevent and getevent command to grab and generate tap/swipe events on screen. So we can make a way to do this. The method "listens" to your input actions (screen taps, button presses, etc) and turns them into a script you can use to reproduce them. Think of it as something similar to Excel's Macro Recording feature. Of course, you need have knowledge of basic screen events(refer to tutorial).

  Solution 1:
1. run getevent ini adb shell
2. copy/paste it's output to file on PC
3. run script which contents one line cat $1 | gawk --non-decimal-data '{print $1, ("0x"$2)+0, ("0x"$3)+0, ("0x"$4)+0}' | sed 's/://g;s/^/sendevent /g' as convert.sh file.in > file out
4. put file.out on SD-card
5. Source it with Run Shell action

Note: the solution comes from here. Thanks to Vladimir Oz .

  Solution 2:

     You can use "Sendevent->Getevent Toolbox" to find a way out.

Note:I had test it on my MiOneS phone (ROM: MIUI-3.9.6). Yes, works very well(the shell script need some minor tweaking). Maybe it's the easiest way at present in my opinion. Thanks to GermainZ.