¿ Cómo leer sms desde kivy en android?

in #python7 years ago

Enviar mensajes sms en kivy en android es muy sencillo, basta con checa un poco de pyler y ya está. No obstante leer es una historia muy diferente, a continuación te coloco un código sencillo para leer sms.

#-*- coding: utf-8 -*-
import kivy
kivy.require('1.8.0')
from kivy.app import App
from kivy.uix.screenmanager import ScreenManager
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.utils import platform

class Principal(App):
    def prueba(self,ins):
        if platform == 'android':
            from jnius import autoclass
            from jnius import cast
            from android import activity
            
            # change if trouble with sdl or pygame
            #PythonActivity = autoclass('org.kivy.android.PythonActivity')
            PythonActivity = autoclass('org.renpy.android.PythonActivity')
            Intent = autoclass('android.content.Intent')
            Uri = autoclass('android.net.Uri')
            
            Cursor = autoclass('android.database.Cursor')
            
            currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
            
            uriSms = Uri.parse('content://sms')
            cursor = currentActivity.getContentResolver().query(uriSms,[
                '_id', 'address', 'body', 'type', 'read'],
                "type=1", None,
                "date COLLATE LOCALIZED ASC limit 10")
            
            if cursor and cursor.getCount():
                cursor.moveToFirst()
                print(cursor.getString(cursor.getColumnIndex('_id')))
                print(cursor.getString(cursor.getColumnIndex('body')))
            cursor.close()

    def build(self):
        L = BoxLayout(orientation='vertical',padding=[30,30,30,0], spacing = [4,4])
        btninfo = Button(
            text='Arriba', size_hint=(0.5, None),
            background_color = kivy.utils.get_color_from_hex('300076'),
            background_normal=''
        )
        L.add_widget(btninfo)
        btninfo.bind(on_press=self.prueba)
        return L

if __name__ == '__main__':
    Principal().run()
Sort:  

Congratulations @eolandro! You received a personal award!

1 Year on Steemit

Click here to view your Board

Do not miss the last post from @steemitboard:

Christmas Challenge - Send a gift to to your friends

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @eolandro! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.22
TRX 0.27
JST 0.041
BTC 104601.56
ETH 3878.85
SBD 3.32