Is there a way to add contacts from my app to the People app on a Windows Phone 8.1? I looked at different things under the Contact class and nothing seems to work. There are different ways (like ContactManager, ContactPicket, etc.) to retrieve data but nothing seems to allow me to add a new contact as most of the stuff like SaveContactTask in Microsoft.Phone.Tasks is not implemented on WP 8.1.
J.
You don't have write access to the primary contact store on Windows Phone 8, but you have the ability to create your own contact store for the app which you can use to manage contacts created in your own app.
The mechanism is pretty simple:
using Windows.Phone.PersonalInformation;
public async void addPerson() {
var store = await ContactStore.CreateOrOpenAsync();
var contact = new StoredContact(store) {
DisplayName = "Mike Peterson"
};
var props = await contact.GetPropertiesAsync();
props.add(KnownContactProperties.Email, "mike#peterson.com");
props.add(KnownContactProperties.MobileTelephone, "+1 212 555 1234");
await contact.SaveAsync();
}
To inform the OS that you provide contact information, you need to add the ID_CAP_CONTACTS/Contacts capability to your app (in the Capabilities section of the appxmanifest). Contacts remain until the app is removed.
Private, owned by the app contacts are convenient for 'contact' data for the app.
Related
I got a problem with a little application I'm developing using Xamarin.iOS
My goal is simply to get every contacts present on an iPhone.
I have this code, it worked until now on my phone and at least 3 others.
Yesterday I added someone in my provisioning profile, since, I can't get any other value than 'null' on my phone when I try to fetch a container.
My phone is an iPhone 7 iOS 13.1.2 - I can't test it on any other phone until a little moment.
It still works on a simulator (iPhone 8 iOS 13.1).
I have the contact authorization request in my info.plist.
I just don't understand what getting 'null' means when fetching a default container ...
try
{
var keysTOFetch = new[] { CNContactKey.GivenName, CNContactKey.FamilyName, CNContactKey.Nickname, CNContactKey.JobTitle, CNContactKey.DepartmentName, CNContactKey.OrganizationName, CNContactKey.PostalAddresses, CNContactKey.UrlAddresses, CNContactKey.EmailAddresses, CNContactKey.PhoneNumbers };
NSError error;
CNContact[] contactList;
var ContainerId = new CNContactStore().DefaultContainerIdentifier; <---- //This where I get a null I never got before ...
if (ContainerId != null)
{
using (var predicate = CNContact.GetPredicateForContactsInContainer(ContainerId))
using (var store = new CNContactStore())
contactList = store.GetUnifiedContacts(predicate, keysTOFetch, out error);
var contacts = new List<UserContact>();
status = writeCSV(contactList, user);
}
else
Console.WriteLine("Didn't get any container identifier ..");
}
Apple documentation says it can return 'null' but without further explanation ..
Thanks a lot for your help
You are facing this issue on some phones and not other because the phone that work have only one container that it is trying load contacts from, while the phones that don't work have more than one container (i.e. Gmail, Exchange, iCloud accounts used to store contacts). So you are only loading the contacts from the account that is configured as the default, which has 0 contacts. Therefore, it would not load all contacts as requested.
Solution: Get all the containers and iterate over them to extract all contacts from each of them. You might be able to find some samples of it on Github.
Adding a contact from a country like Iran to a telegram account from Canada, causes an error says:
Unfortunately -name- has not joined telegram yet. But you can send
them an invitation.
I think that's because there are two different accounts from two different servers that aren't synced well.
Sometimes Iranian account can add Canadian account, and then Canadian can add Iranian as well, even if Iranian deletes Canadian from contacts. Or if a third person share their contacts or forward a message from one to another, they can add each other. I think these signs shows that telegram servers are not synced well.
As I'm using TLsharp to accomplish that, I can add two telegram accounts, one plays as that third person role, and shares Iranian contact to Canadian, and then he can save that contact.
My step by step plan is:
What I have is an Iranian Telegram account and Canadian one.
Iranian Customer opens my web site.
she/he fills telegram phone number field and submits.
we are going to start sending message in telegram by Canadian account.
try to add contact by Canadian account.
If failed, try to add contact by Iranian account. Else, we are done!
Share contact to Canadian Account.
Add contact by Canadian account.
My problem is:
how to have multiple telegram accounts in my code, because session file name is always "session.dat"
how to share contact in TLSharp
I can't forward message because there isn't any message yet. We should start messaging.
I also tried retrieving UserId and AccessHash by Iranian account, and using by Canadian account in this method:
await client.SendMessageAsync(new TLInputPeerUser() { UserId = xxx, AccessHash= yyyy}, "Hello");
but it has PEER_ID_INVALID error. (That is not true, I just took UserId from telegram!)
The problem is in number of contacts!
Telegram only supports about 1000 contacts (I found it experimental, there isn't any official source to prove this), and it will show you error when you want to add more contacts.
Trying to delete some contacts and reduce the count to 900, allowed me to add new contacts. So, the problem is not in telegram servers, it is in number of contacts limitation. Maybe they have a line of code like this:
Contact[] contacts = new Contact[1000]; //LOL
And for other two questions:
how to have multiple telegram accounts in my code, because session
file name is always "session.dat"
TLSharp.Core.TelegramClient clientAlt = new TLSharp.Core.TelegramClient(api_id, api_hash, sessionUserId: "sessionAlt");
There isn't any good documentation for TLSharp, but the problem solved by using sessionUserId as an optional parameter.
how to share contact in TLSharp?
TLInputMediaContact contact = new TLInputMediaContact()
{
FirstName = FirstName,
LastName = LastName,
PhoneNumber = PhoneNumber
};
TLRequestSendMedia req = new TLRequestSendMedia()
{
Media = contact,
Peer = new TLInputPeerUser() { UserId = AnotherTelegramAccountUserID.Id },
RandomId = UniqueNumber_ToPreventDuplicateMessages,
};
await clientAlt.SendRequestAsync<TLUpdates>(req);
In my app I am trying to make it possible for the user to push a button and make a phone call
At the moment I was using this
if (phoneCallStore != null)
{
var lineGuid = await phoneCallStore.GetDefaultLineAsync();
if (lineGuid != Guid.Empty)
{
var phoneLine = await PhoneLine.FromIdAsync(lineGuid);
if (phoneLine != null && phoneLine.CanDial)
{
phoneLine.Dial(number, name);
}
}
}
But I was rejected by Microsoft as they say
Phone Call In Restricted Market: 2000.5 Phone Call In Restricted Market
The phonecall capability cannot be used in the application since it targets restricted markets (China).
EDIT
I tried removing China from markets, which fixed the problem.
But can I somehow, check if the user is from China?
The phonecall capability cannot be used in the application since it targets restricted markets (China).
Then when you submit your app you should exclude China from the list of target markets.
How can I get the full contact list from user's phone in UWP?
I have found articles on msdn, but thes use only contact picker that doesn't gives me a full list of the contacts. I just would like to get their names and profile images, noting else.
ContactStore.FindContactsAsync
var contactStore = await ContactManager.RequestStoreAsync();
var contacts = await contactStore.FindContactsAsync();
I am using the agsXMPP SDK to create a small GTalk client in C#.
XmppClientConnection connection = new XmppClientConnection();
.
.
.
connection.OnPresence += new PresenceHandler(xmpp_OnPresence);
private void xmpp_OnPresence(object sender, Presence pres)
{
Console.WriteLine(pres.pres.From.User); // this is "3aav33e8erudg29gzjg***"
}
I can read most contacts with their username, but some are not very useful.
This is the body:
<presence xmlns="jabber:client" from="3aav33e8erudg29gzjg*****c#public.talk.google.com/android_talkc2f2f*******" to="**************#gmail.com/agsXMPP678C2F26"><priority>24</priority><caps:c xmlns:caps="http://jabber.org/protocol/caps" node="http://www.android.com/gtalk/client/caps" ver="1.1" ext="pmuc-v1 voice-v1 video-v1 camera-v1" /><show>away</show><x xmlns="vcard-temp:x:update"><photo>4d211fc**************90a130a1345425b1e</photo></x></presence>
Is there any way to get a readable username from this? This person seems to be my contact, but I don't know who it is...
This are automatically created contacts from Google+ circles as far as I know.
The real Google id is hidden for privacy reasons. If you don't want these contacts you can disable them in the G+ Chat privacy settings.