Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't import Contacts #180

Closed
coffebar opened this issue Nov 11, 2015 · 5 comments
Closed

can't import Contacts #180

coffebar opened this issue Nov 11, 2015 · 5 comments

Comments

@coffebar
Copy link

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

@pythonic64
Copy link

Try importing Contacts directly, like:

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

'$' is for accessing nested classes.

@coffebar
Copy link
Author

it works, thanks!

@coffebar
Copy link
Author

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

@coffebar coffebar reopened this Nov 11, 2015
@pythonic64
Copy link

That's an issue with pyjinius related to #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

@Intasir
Copy link

Intasir commented Sep 25, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants