Pyjnius: can't import Contacts

Created on 11 Nov 2015  路  5Comments  路  Source: kivy/pyjnius

This code crashes without catching Exception:

def build(self):
    try:
        return Label(text=str(dir(autoclass('android.provider.ContactsContract.Contacts'))).replace(' ', '\n'))
    except Exception as ex:
        return Label(text=str(ex).replace(' ', '\n'))

this case

def build(self):
    try:
        contract = autoclass('android.provider.ContactsContract')
        return Label(text=str(dir(contract.Contacts)).replace(' ', '\n'))
    except Exception as ex:
        return Label(text=str(ex).replace(' ', '\n')) 

catching Exception type object 'android.provider.ContactsContract' has no attribute 'Contacts'

but I expect that such a class exists: http://developer.android.com/intl/ru/reference/android/provider/ContactsContract.Contacts.html

Most helpful comment

Try importing Contacts directly, like:

Contacts = autoclass('android.provider.ContactsContract$Contacts')

'$' is for accessing nested classes.

All 5 comments

Try importing Contacts directly, like:

Contacts = autoclass('android.provider.ContactsContract$Contacts')

'$' is for accessing nested classes.

it works, thanks!

One more question.
How to get "ContactsContract.Contacts._ID" ?

Contacts = autoclass('android.provider.ContactsContract$Contacts')
System.out.println(' '.join(dir(Contacts))) # CONTACT_CHAT_CAPABILITY CONTACT_LAST_UPDATED_TIMESTAMP CONTACT_PRESENCE CONTACT_STATUS CONTACT_STATUS_ICON CONTACT_STATUS_LABEL CONTACT_STATUS_RES_PACKAGE CONTACT_STATUS_TIMESTAMP CONTENT_FILTER_URI CONTENT_FREQUENT_URI CONTENT_GROUP_URI CONTENT_ITEM_TYPE CONTENT_LOOKUP_URI CONTENT_MULTI_VCARD_URI CONTENT_STREQUENT_FILTER_URI CONTENT_STREQUENT_URI CONTENT_TYPE CONTENT_URI CONTENT_VCARD_TYPE CONTENT_VCARD_URI CORP_CONTENT_URI CUSTOM_RINGTONE DISPLAY_NAME DISPLAY_NAME_ALTERNATIVE DISPLAY_NAME_PRIMARY DISPLAY_NAME_SOURCE ENTERPRISE_CONTACT_ID_BASE EXTRA_ADDRESS_BOOK_INDEX EXTRA_ADDRESS_BOOK_INDEX_COUNTS EXTRA_ADDRESS_BOOK_INDEX_TITLES FILTER FILTER_NONE FILTER_WIDGET HAS_PHONE_NUMBER INDEX_IN_SIM INDICATE_PHONE_SIM IN_DEFAULT_DIRECTORY IN_VISIBLE_GROUP IS_SDN_CONTACT IS_USER_PROFILE LAST_TIME_CONTACTED LOOKUP_KEY NAME_RAW_CONTACT_ID PHONETIC_NAME PHONETIC_NAME_STYLE PHOTO_FILE_ID PHOTO_ID PHOTO_THUMBNAIL_URI PHOTO_URI PINNED QUERY_PARAMETER_VCARD_NO_PHOTO SEND_TO_VOICEMAIL SEND_TO_VOICEMAIL_SIP SEND_TO_VOICEMAIL_VT SORT_KEY_ALTERNATIVE SORT_KEY_PRIMARY STARRED TIMES_CONTACTED _COUNT _ID ...
_ID = Contacts._ID # Error

That's an issue with pyjinius related to https://github.com/kivy/pyjnius/issues/169
You'll have declare variable yourself, like:

CONTACTS_ID = '_id'

and then instead of using Contacts._ID use CONTACTS_ID when building query for accessing Contacts.
Same goes for _COUNT

how can i Access full contact list ,can anyone help??

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

apalala picture apalala  路  7Comments

Thrameos picture Thrameos  路  27Comments

tom19952000 picture tom19952000  路  15Comments

cthoyt picture cthoyt  路  11Comments