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

[Question] Creating new contacts #71

Closed
fgubler opened this issue Aug 14, 2022 · 5 comments
Closed

[Question] Creating new contacts #71

fgubler opened this issue Aug 14, 2022 · 5 comments
Labels
question Further information is requested

Comments

@fgubler
Copy link

fgubler commented Aug 14, 2022

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:

  1. I cant/don't have to pass a contactId along. Therefore, I assume that the ID will be assigned automatically: Is that correct (would make sense to me as Android is better able to guarantee its uniqueness).
  2. I have to pass the account into which the contact should be stored. 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?
@alexstyl
Copy link
Owner

alexstyl commented Aug 14, 2022

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.

@alexstyl alexstyl added the question Further information is requested label Aug 14, 2022
@fgubler
Copy link
Author

fgubler commented Aug 14, 2022

Thanks for the explanation :-).

You can use AccountManager.get(this).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.

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?

@alexstyl
Copy link
Owner

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.

@fgubler
Copy link
Author

fgubler commented Aug 14, 2022

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)

@alexstyl
Copy link
Owner

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.

@fgubler fgubler closed this as completed Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants