2017-06-15 95 views

回答

1

首先你需要權限,將READ_CONTACTS准予加入你的建築規格。現在

,你應該使用pyjnius使用Java SDK是這樣的:

- 這不是測試 -

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)); 
      name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) #I think this is not DISPLAY_NAME in all versions ... 
      print("->", id, name) 

     #you can further query contact by its id 

邏輯從這個答案採取:android get all contacts

您也可以嘗試plyer這個拉動請求:https://github.com/kivy/plyer/pull/125/