Closed fgubler closed 2 years ago
hi @fgubler, this is the right place to ask questions :)
I assume that the ID will be assigned automatically
This is correct. As soon as you store a contact via ContactStore, Android itself will assign a new id to it. There is no need to provide your own ids.
Is there a way to get the information from Android (or ideally from this library), which accounts are available and which of them is the default?
You can use AccountManager.get(context).accounts
to get all accounts on the device. Each Account
contains a name and a type, which you can use to create an InternetAccount
and use that when you create a contact via ContactStore.
AFAIK there is no concept of 'default' in Android, but it is something each app handles on their own.
Thanks for the explanation :-).
You can use
AccountManager.get(this).accounts
to get all accounts on the device. EachAccount
contains a name and a type, which you can use to create anInternetAccount
and use that when you create a contact via ContactStore. AFAIK there is no concept of 'default' in Android, but it is something each app handles on their own.
Ok, makes sense. The system's contact app so far always correctly predicted which account to choose as default for me (across vendors). But maybe it just checked which one had the most contacts in it.
There is also usually an option to just store a contact locally on the phone without any account. Is that also supported by the library? Is it just a kind of dummy-account?
Is that also supported by the library? Is it just a kind of dummy-account?
Yup it is supported. Pass no account and it will be stored locally.
Last question for now: when loading an existing contact: is there a way to find out which account it belongs to? (to e.g. determine which account has the most contacts assigned and use it as default)
No. Each contact returned by contact store can be the result of combining multiple contacts together from different sources.
For your case, the number of contacts might not mean that this is the account the user would prefer saving the contacts (as the account can be managed from a different device). An alternative would be to check what kind of account you would like to promote (i.e. google) and pick that first.
Sorry, this is more of a question than an issue but I was not sure about the ideal channel of communications and maybe the question is also interesting for other users of the library.
As explained in the Readme, it is possible to create a new contact in the Android contact database, however for my real-world use-case I have two additional questions: