Pyjnius: impossible d'importer des contacts

Créé le 11 nov. 2015  ·  5Commentaires  ·  Source: kivy/pyjnius

Ce code plante sans attraper 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'))

ce cas

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')) 

attraper l' objet de type Exception

mais je suppose qu'une telle classe existe : http://developer.android.com/intl/ru/reference/android/provider/ContactsContract.Contacts.html

Commentaire le plus utile

Essayez d'importer des contacts directement, comme :

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

'$' est pour accéder aux classes imbriquées.

Tous les 5 commentaires

Essayez d'importer des contacts directement, comme :

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

'$' est pour accéder aux classes imbriquées.

ça marche, merci !

Une dernière question.
Comment obtenir "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

C'est un problème avec pyjinius lié à https://github.com/kivy/pyjnius/issues/169
Vous devrez déclarer la variable vous-même, comme :

CONTACTS_ID = '_id'

puis au lieu d'utiliser Contacts._ID, utilisez CONTACTS_ID lors de la création d'une requête pour accéder aux contacts.
Idem pour _COUNT

Comment puis-je accéder à la liste de contacts complète, quelqu'un peut-il m'aider ??

Cette page vous a été utile?
0 / 5 - 0 notes