-
-
Save erm3nda/cc6598075a68ddb9aaacad23bdb02e96 to your computer and use it in GitHub Desktop.
Google Android get messages using URI parser and content.Resolver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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