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)
Cathy
samsung don't update/remove the message app unread notify displayed on the launcher desktop or notification barmy phone 9100gversion 4.1.2
在 2013年4月17日星期三UTC+8下午12时16分06秒,Cathy Lansy写道:
Hello there,I'm running this script but it's not doing anything. I have installed the SL4A APK and am running the script directly from there.I made the script simply print any unread messages. However, it's not working as expected. Perhaps you could tell me what I'm doing wrong?Here is my code:/sdcard/sl4a/scripts/delete_sms.sh
import androiddroid = android.Android()
print droid.smsGetMessages(True, 'inbox')msgs = droid.smsGetMessageIds(True, 'inbox')[1]for msg in msgs:print msg