Skip to content

Instantly share code, notes, and snippets.

@tshirtman
Last active August 3, 2016 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tshirtman/efe110309d4b22f3a97b to your computer and use it in GitHub Desktop.
Save tshirtman/efe110309d4b22f3a97b to your computer and use it in GitHub Desktop.
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)
@erm3nda
Copy link

erm3nda commented Aug 3, 2016

Where did you created context?

@tshirtman
Copy link
Author

tshirtman commented Aug 3, 2016

if platform == 'android':
    from jnius import autoclass
    Uri = autoclass('android.net.Uri')
    Cursor = autoclass('android.database.Cursor')
    Service = autoclass('org.renpy.android.PythonService')
    context = Service.mService

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment