Skip to content

Instantly share code, notes, and snippets.

@erm3nda
Forked from tshirtman/main.py
Last active June 15, 2019 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erm3nda/cc6598075a68ddb9aaacad23bdb02e96 to your computer and use it in GitHub Desktop.
Save erm3nda/cc6598075a68ddb9aaacad23bdb02e96 to your computer and use it in GitHub Desktop.
Google Android get messages using URI parser and content.Resolver
def get_message(cursor):
return (
cursor.getString(cursor.getColumnIndex('_id')),
cursor.getString(cursor.getColumnIndex('address')),
cursor.getString(cursor.getColumnIndex('body')))
def fetch_messages(lastindex):
if platform == 'android':
uriSms = Uri.parse('content://sms')
cursor = context.getContentResolver().query(
uriSms,
['_id', 'address', 'body', 'type', 'read'],
"type=1", None,
"date COLLATE LOCALIZED ASC limit 10 offset %s" % lastindex)
if cursor and cursor.getCount():
cursor.moveToFirst()
yield get_message(cursor)
while cursor.moveToNext():
yield get_message(cursor)
cursor.close()
del(cursor)
else:
for i in range(10):
yield ('%s' % i, 'message%s' % i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment