from kivy.uix.screenmanager import Screen
from jnius import autoclass
from kivymd.uix.button import MDRectangleFlatButton
from android.permissions import request_permissions, Permission
class MainApp(MDApp):
def build(self):
screen = Screen()
screen.add_widget(
MDRectangleFlatButton(
text="Hello, AaryaLab",
pos_hint={"center_x": 0.5, "center_y": 0.5},
)
)
self.get_cantact()
return screen
def get_cantact(self):
request_permissions([Permission.READ_CONTACTS])
PythonActivity = autoclass("org.renpy.android.PythonActivity")
ContactsContract = autoclass("android.provider.ContactsContract")
cr = PythonActivity.mActivity.getContentResolver()
null = None # this will help to convert java examples into python ones :)
cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null)
if (cur.getCount() > 0):
while (cur.moveToNext()):
id = cur.getString(cur.getColumnIndex(
ContactsContract.Contacts._ID))
# I think this is not DISPLAY_NAME in all versions ...
name = cur.getString(cur.getColumnIndex(
ContactsContract.Contacts.DISPLAY_NAME))
print("->", id, name)
MainApp().run()