Python SL4A script to mark specific unread sms message as read

923 views
Skip to first unread message

Cathy Lansy

unread,
Apr 17, 2013, 12:16:06 AM4/17/13
to tas...@googlegroups.com

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)

Message has been deleted
Message has been deleted

Cathy Lansy

unread,
Apr 25, 2013, 12:10:43 AM4/25/13
to tas...@googlegroups.com
Hi,
 
 
i have already explained it in my entry. did you notice it?
 
 
(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.)

 

 

 

Cathy

 


On Friday, April 19, 2013 10:09:32 AM UTC+8, Fugang Yin wrote:
samsung don't update/remove the message app unread notify displayed on the launcher desktop or notification bar

my phone 9100g
version 4.1.2

在 2013年4月17日星期三UTC+8下午12时16分06秒,Cathy Lansy写道:

Cathy Lansy

unread,
Apr 29, 2013, 6:48:58 AM4/29/13
to tas...@googlegroups.com
Hi,
 
first of all, i was wondering if you have installed python for android? if yes, second question is did you install all required modules inside the interpreter?
 
if the answer is yes, please read on.
 
msgs = droid.smsGetMessageIds(True, 'inbox')[1]
 
for msg in msgs:
print msg
 
did you notice you use [1] as argument specified that you just the second message ID from all the unread message IDs.
 
so you are suppposed to use for statement since then. that could cause a logic error.
 
well, that is what i speculate, you may try to remove [1] and test what will happen.
 
if any questions, please keep me posted.
 
Cathy
 
 
 
 
 

On Monday, April 29, 2013 8:18:13 AM UTC+8, Ryan Steffer wrote:
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 android

droid = android.Android()
print droid.smsGetMessages(True, 'inbox')
msgs = droid.smsGetMessageIds(True, 'inbox')[1]

for msg in msgs:
print msg

bdanders

unread,
May 8, 2013, 12:04:29 PM5/8/13
to tas...@googlegroups.com
Thanks for sharing, this looks like it could be very useful. Do you have any thoughts on how it could be modified to mark all messages as read?

bdanders

unread,
May 8, 2013, 12:35:21 PM5/8/13
to tas...@googlegroups.com
Nevermind, I think I got it. It's just a much simpler version of what you already have. Thanks again for sharing.


# coding:utf-8
import android

droid = android.Android()
msgIDs = droid.smsGetMessageIds(True, 'inbox').result
droid.smsMarkMessageRead(msgIDs,1)

Cathy Lansy

unread,
May 10, 2013, 4:40:40 AM5/10/13
to tas...@googlegroups.com
Hi,
 
sorry for this late reply.
 
yes, droid.smsMarkMessageRead(msgIDs,1) this is correct to mark all message IDs you listed earlier by smsGetMessageids function call with specified argument of Ture which means unread messages only.
 
for more information about sl4a and tasker integration, you may go access my blog for review.
 
 
Cathy

Wes Stacey

unread,
Aug 19, 2013, 11:58:45 AM8/19/13
to tas...@googlegroups.com
I'm ressurecting an old thread here but i'd like to try this out only problem is i'm not sure what files i need to grab. It would appear i need the sl4a apk and python apk but i'm not sure where to find them. I looked over your blog but don't see any links to the sl4a and python files.

can anyone point me in the right direction here?

bdanders

unread,
Aug 19, 2013, 12:17:50 PM8/19/13
to tas...@googlegroups.com
This is helpful if you haven't already seen it: http://tasker.wikidot.com/sl4a

Wes Stacey

unread,
Aug 19, 2013, 12:28:16 PM8/19/13
to tas...@googlegroups.com
Excellent,

This is exactly what i needed.

Thank you.

COVERek

unread,
Aug 22, 2013, 5:27:25 AM8/22/13
to tas...@googlegroups.com
I have S4 with rooted stock JB 4.2.2 system, and this script doesn't work... It only checked as read in database, but it not cleared sms notification on taskbar.
What should i do to run this script properly?

Wes Stacey

unread,
Aug 22, 2013, 9:22:56 AM8/22/13
to tas...@googlegroups.com
In the post it specifically says:

both methods could not update/remove the message app unread notify displayed on the launcher desktop or notification bar.

If you want to be able to clear it you'll need to set the messaging app to not display notifications at all and just use Tasker to display unread SMS notifications.

e.f.a.c.f.e...@gmail.com

unread,
Nov 2, 2013, 9:39:14 PM11/2/13
to tas...@googlegroups.com
Wow, this is really useful! Thanks!!

Do you know who to delete all entries from the CALL LOG?


Reply all
Reply to author
Forward
0 new messages