SL4A python script to manage android default sms message
since i have been studying on sl4a python script these days, i think it could be helpful if i post how sl4a script manages android default sms message.
in my earlier entry, i already posted the script about how to mark specific sms as read via keyword and sender phone number.
if you are interested, you may take a look as well.
## unread sms count ####
import android
droid = android.Android()
count = droid.smsGetMessageCount(True).result
print count ## you will see the unread sms count result in there
## send sms ###
# coding:utf-8
import android
droid = android.Android()
number = "........."
message = "........."
droid.smsSend(number, message.encode("utf-8"))
## mark all unread sms as read ####
import android
droid = android.Android()
msgIDs = droid.smsGetMessageIds(True, 'inbox').result
if msgIDs > 0:
droid.smsMarkMessageRead(megIDs, 1)
### delete all unread sms #######
import android
droid = android.Android()
msgIDs = droid.smsGetMessageIds(True, 'inbox').result
if msgIDs > 0:
for msgID in msgIDs:
droid.smsDeleteMessage(msgID)
#### delete specific message in outbox ####
# coding:utf-8
import android
droid = android.Android()
msgIDs = droid.smsGetMessageIds(False, 'sent').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('XXXXX') >= 0 and str2.find('YYYY') >= 0: ##XXXX reprents phone number, YYYY represents message keywords
droid.smsDeleteMessage(msgID)
#### delete specific message in inbox and outbox ####
# coding:utf-8
import android
droid = android.Android()
msgIDs = droid.smsGetMessageIds(False, 'inbox').result
msgIDs.extend(droid.smsGetMessageIds(False, 'sent').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('XXXX') >= 0 and str2.find('YYYY') >= 0: ##XXXX reprents phone number, YYYY represents message keywords
droid.smsDeleteMessage(msgID)
The blog posted is very interesting from all aspects and it will surely benefit the readers by all means.
ReplyDeletesms message
Hi,
ReplyDeleteI am using ms=droid.smsGetMessages(False, 'inbox', None).result to access all my messages.
Any idea how I can convert the dates to a readable format?
Thank you
## mark all unread sms as read ####
ReplyDelete### delete all unread sms #######
Not work. :((((
Me too. Is there any solution?? I am trying update status via sqlite but my phone doesn't rooted.
DeleteI Find it very informative about sms marketing.Thanks for sharing such great information. hope you keep sharing such kind of information how to send bulk message
ReplyDelete