Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read sms message from Android #8

Open
euvgub opened this issue Mar 10, 2021 · 0 comments
Open

Read sms message from Android #8

euvgub opened this issue Mar 10, 2021 · 0 comments

Comments

@euvgub
Copy link
Contributor

euvgub commented Mar 10, 2021

`from datetime import datetime
import os
import pipes
import subprocess

ADB_BINARY = "adb"
SMS_DB = "/data/data/com.android.providers.telephony/databases/mmssms.db"
SELECT_SMS_SQL = 'SELECT _id, address, date, body FROM sms WHERE read=0;'
UPDATE_READ_SQL = 'UPDATE sms SET read=1 WHERE _id in (%d);'

def get_unread_messages():
cmd = 'adb shell "su -c sqlite3 %s %s"' % (SMS_DB, pipes.quote(SELECT_SMS_SQL))
print cmd
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
(out, err) = p.communicate()
result = []
for msg in out.replace('\r', '').strip('\n').split('\n'):
msg = msg.split('|')
result.append(dict(id=msg[0], sender=msg[1],
date_time=str(datetime.fromtimestamp(int(int(msg[2])/1000))), message=msg[3]))
return result
def set_read_message(msg_id):
"""
Sets a message identified by msg_id to read.
:param msg_id:
:return:
"""
cmd = 'adb shell "su -c sqlite3 %s %s"' % (SMS_DB, pipes.quote(UPDATE_READ_SQL % msg_id))
os.system(cmd)
def main():
result = get_unread_messages()
for r in result:
print r
if name == 'main':
main()`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant