How can I read SMS with Pyjnius?

1,366 views
Skip to first unread message

Benjimaestro

unread,
Jan 18, 2018, 4:21:28 AM1/18/18
to Kivy users support
I was wondering how I would go about reading SMSes on Android with Pyjnius (content://sms/inbox). I have never used Java before so I have really no idea how to do this, and I've looked all over the internet for this.
I just want to be able to read from the SMS inbox into a list or dictionary or something like that. VERY grateful for any help.

Alexander Taylor

unread,
Jan 18, 2018, 6:37:14 PM1/18/18
to Kivy users support
I had a quick look around the Android API docs and the various blog posts and stackoverflow questions about this, but it looks like it's slightly involved to do it. It might not be hard with pyjnius, but the details aren't immediately obvious - it would probably need some experimentation.

Benjimaestro

unread,
Jan 26, 2018, 4:16:51 PM1/26/18
to Kivy users support


On Thursday, 18 January 2018 23:37:14 UTC, Alexander Taylor wrote:
I had a quick look around the Android API docs and the various blog posts and stackoverflow questions about this, but it looks like it's slightly involved to do it. It might not be hard with pyjnius, but the details aren't immediately obvious - it would probably need some experimentation.

Never mind I fixed the stupid thing

    PythonActivity = autoclass('org.kivy.android.PythonActivity')
   
Intent = autoclass('android.content.Intent')
   
Uri = autoclass('android.net.Uri')
   
ComponentName=autoclass('android.content.ComponentName')
   
ActivityInfo= autoclass("android.content.pm.ActivityInfo")
   
PackageInfo= autoclass("android.content.pm.PackageInfo")
   
PackageManager= autoclass("android.content.pm.PackageManager")
   
Cursor=autoclass("android.database.Cursor")
    am
= PythonActivity.mActivity
    s
='content://sms/inbox'

   
PythonActivity.toastError(s)
    providerInfo
=am.getContentResolver
    cursor
= am.getContentResolver().query(Uri.parse(s),None,None,None,None)
    array
=cursor.getColumnNames()
    columns
=cursor.getColumnCount()
    rows
=cursor.getCount()
   
if (cursor.moveToFirst()==True):
        r
=1
        row_values
=""
       
while (r<=rows):
           c
=1
           
while (c<columns):
               type
=cursor.getType(c)
               
if type == 1:
                   
                   value
=cursor.getInt(c)
               
elif type == 2:
                   value
=cursor.getFloat(c)
               
if type == 3:
                   value
=cursor.getString(c)
               
elif  type == 4:
                   value
=cursor.getBlob(c)
               
elif type==0:
                   value
="START5"
               row_values
=row_values + "\n" + str(type)+str(value)
               c
+=1              
           r
+=1
           cursor
.moveToNext()
           row_values
=row_values+ "\n"
           
PythonActivity.toastError(s + ":" + row_values)

 
Reply all
Reply to author
Forward
0 new messages