Windows phone 8.1 using Contact Picker to retrieve both email and phone number - windows-phone-8.1

I am using the following code to allow the user to select contacts:
ContactPicker ContactPicker = new ContactPicker();
ContactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
var Contacts = await ContactPicker.PickContactsAsync();
if (Contacts.Count > 0)
{
foreach (Contact contact in Contacts)
{
string telephone = string.Empty;
string email = string.Empty;
if (contact.Phones.Count > 0)
{
telephone = contact.Phones[0].Number;
}
if (contact.Emails.Count > 0)
{
email = contact.Emails[0].Address;
}
PartyPerson person = new PartyPerson(DateTime.Now.ToString("PP_yyMMdd_hhmmss_ffff"), true, contact.DisplayName, 0, 0, 0, email, telephone);
AddPartyPerson(person);
}
}
ContactPicker = null;
However, I only get phone number, the object "contact" does not contain any email addresses even though they are present in the contact information.
One option is to switch:
ContactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
with
ContactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email);
But then I don't get a phone number... I want to be able to retrieve all the information in one select.
Is there any way to select both information via one select?
(I also tried adding more than one entry to DesiredFieldsWithContactFieldType but then I get an exception...)
Best regards,
Keran
EDIT 07.08.2015:
Since the "ContactPicker.DesiredFieldsWithContactFieldType" can only accept one type of "ContactFieldType", the way I worked around this was first allow the user to get the contacts by ContactFieldType.PhoneNumber and then I programatically retrieve the email addressess of the selected contacts.
From the users point of view, this won't be a problem since everything will be visible correctly in the ContactPicker.PickContactsAsync, we just need to retrieve the missing email information manually in code-behind, which is easy since we know what contacts were selected by the user.

Try this:
ContactStore contactStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);
ContactPicker contactPicker = new ContactPicker();
IList<Contact> pickedContacts = await contactPicker.PickContactsAsync();
int pickedCount = pickedContacts != null ? pickedContacts.Count : 0;
if (pickedCount > 0)
{
for (int i = 0; i < count; ++i)
{
Contact c = pickedContacts[i];
Contact realContact = await contactStore.GetContactByIdAsync(c.Id);
//...
}
}
So, you first need to get the "skeleton" of the contact, and then you can get the whole contact entity with all its properties from the ContactStore object.
It works for me on Windows 10 Mobile. There shouldn't be much difference from Windows 8.
Hope it helps.

Related

Add contacts to Google Contacts' main Contacts list (not hidden)

I'm using the GAS code bellow to add a new contact into Google Contacts (https://contacts.google.com/):
var contact = ContactsApp.createContact('Bbbb', 'Cccc', 'mymail#mails.com').addUrl(ContactsApp.Field.WORK_WEBSITE, 'https://sites.google.com/site/...');
The code works perfectly but for a single detail: it adds the new contact to a hidden list and not to the main or visible «Contacts» list.
I know it works because when I use the lookup box to search for the newly created contact it's there, in the «Other contacts» list. I need it to be created in the main «Contacts» list from the beginning, otherwise I would have to do it manually using the «Add to contacts» icon with every contact created (I'm planning to add some thousands of contacts.)
Thanks.
For me, I have to add them to the ContactGroup named System Group: My Contacts.
function finishAddingContact(contact) {
var mainGroup = ContactsApp.getContactGroup("System Group: My Contacts");
if(mainGroup)
mainGroup.addContact(contact);
}
Note that getContactGroup(string) is an exact name match.
I recommend inspecting your ContactGroups for system groups, and then selecting the appropriate one from that list. It's probably the one with the most contacts in it:
function inspect() {
var groups = ContactsApp.getContactGroups();
for(var g = 0; g < groups.length; ++g) {
if(groups[g].isSystemGroup()) {
Logger.log(groups[g].getName() + ": " + groups[g].getContacts().length + " members, id=" + groups[g].getId());
}
}
}
Thanks a lot tehhwch.
I used your second code to get the right group ("System Group: My Contacts"), and then:
var contact = ContactsApp.createContact('Wunder', 'Bar', 'excellent#help.com');
var group = ContactsApp.getContactGroup("System Group: My Contacts");
group.addContact(contact);
It works, and the contact is immediately visible in my Android device.

Get SIM MSISDN & IMSI number in Windows Phone Application

Is it possible to get the SIM MSISDN & IMSI number in windows Phone app development?
I have gone through some of the Q/A but they all are asked a long time ago.
You could get SIM MSISDN & IMSI number in Windows Phone Application. Please notice that you should manually edit your application Package.appxmanifest as follows:
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">
......
<Capabilities>
<rescap:Capability Name="cellularDeviceIdentity" />
</Capabilities>
The cellularDeviceIdentity capability allows apps to access cellular identification data.
Anyone may request access to these capabilities for store submission.
You could use MobileBroadbandModem class to get all CurrentDeviceInformation, and the following is core codes.
using Windows.Networking.NetworkOperators;
......
public IReadOnlyList<SimCard> GetSimCards()
{
var results = new List<SimCard>();
var modem = MobileBroadbandModem.GetDefault();
if (modem == null)
{
return results.AsReadOnly();
}
var account = modem.CurrentAccount;
if (account == null)
{
return results.AsReadOnly();
}
var simCard = new SimCard();
simCard.ICCID = account.CurrentDeviceInformation.SimIccId;
simCard.IMSI = account.CurrentDeviceInformation.SubscriberId;
simCard.MSISDN = modem.DeviceInformation.TelephoneNumbers;
simCard.MCC = ExtractMCC(simCard.IMSI);
simCard.MNC = ExtractMNC(simCard.IMSI);
simCard.MSID = ExtractMSID(simCard.IMSI);
results.Add(simCard);
return results.AsReadOnly();
}
I have uploaded code sample to git hub. Please check!

Using ItemCollection on a BoxFolder type with Box API only returns 100 results and cannot retrieve the remaining ones

For a while now, I've been using the Box API to connect Acumatica ERP to Box and everything has been going fine until recently. Whenever I try to use a BoxCollection type with the property ItemCollection, I'll only get the first 100 results no matter the limit I set in the GetInformationAsync(). Here is the code snippet:
[PermissionSet(SecurityAction.Assert, Name = "FullTrust")]
public BoxCollection<BoxItem> GetFolderItems(string folderId, int limit = 500, int offset = 0)
{
var response = new BoxCollection<BoxItem>();
var fieldsToGet = new List<string>() { BoxItem.FieldName, BoxItem.FieldDescription, BoxItem.FieldParent, BoxItem.FieldEtag, BoxFolder.FieldItemCollection };
response = Task.Run(() => Client.FoldersManager.GetFolderItemsAsync(folderId, limit, offset)).Result;
return response;
}
I then pass that information on to a BoxFolder type variable, and then try to use the ItemCollection.Entries property, but this only returns 100 results at a time, with no visible way to extract the remaining 61 (in my case, the Count = 161, but Entries = 100 always)
Another code snippet of the used variable, I am basically trying to get the folder ID based on the name of the folder inside Box:
private static void SyncProcess(BoxFolder rootFolder, string folderName)
{
var boxFolder = rootFolder.ItemCollection.Entries.SingleOrDefault(ic => ic.Type == "folder" && ic.Name == folderName);
}
I wasn't able to find anything related to that limit = 100 in the documentation and it only started to give me problems recently.
I had to create a work around by using the following:
var boxCollection = client.GetFolderItems(rootFolder.Id);
var boxFolder = boxCollection.Entries.SingleOrDefault(ic => ic.Type == "folder" && ic.Name == folderName);
I was just wondering if there was a better way to get the complete collection using the property ItemCollection.Entries like I used to, instead of having to fetch them again.
Thanks!
Box pages folder items to keep response times short. The default page size is 100 items. You must iterate through the pages to get all of the items. Here's a code snippet that'll get 100 items at a time until all items in the folder are fetched. You can request up to 1000 items at a time.
var items = new List<BoxItem>();
BoxCollection<BoxItem> result;
do
{
result = await Client.FoldersManager.GetFolderItemsAsync(folderId, 100, items.Count());
items.AddRange(result.Entries);
} while (items.Count() < result.TotalCount);
John's answer can lead to a duplicate values in your items collection if there will be external/shared folders in your list. Those are being hidden when you are calling "GetFolderItemsAsync" with "asUser" header set.
There is a comment about it in the Box API's codeset itself (https://github.com/box/box-windows-sdk-v2/blob/main/Box.V2/Managers/BoxFoldersManager.cs)
Note: If there are hidden items in your previous response, your next offset should be = offset + limit, not the # of records you received back.
The total_count returned may not match the number of entries when using enterprise scope, because external folders are hidden the list of entries.
Taking this into account, it's better to not rely on comparing the number of items retrieved and the TotalCount property.
var items = new List<BoxItem>();
BoxCollection<BoxItem> result;
int limit = 100;
int offset = 0;
do
{
result = await Client.FoldersManager.GetFolderItemsAsync(folderId, limit, offset);
offset += limit;
items.AddRange(result.Entries);
} while (offset < result.TotalCount);

How do i parse the KairosSDK JSON recognise response in Swift?

For those who don't know what the Kairos SDK is, it's basically a facial recognition api.
When you give it an image, it will tell you who if they can match you with someone in the database.
When i give it an image; the api sends me back this response:
[images: (
{
attributes = {
gender = {
confidence = "80%";
type = F;
};
};
candidates = (
{
"enrollment_timestamp" = 1436883322;
face3rd = "0.988351106643677";
},
{
"enrollment_timestamp" = 1436883214;
hi = "0.94137054681778";
},
{
"enrollment_timestamp" = 1436883132;
hi = "0.94137054681778";
}
);
time = "6.43676";
transaction = {
confidence = "0.988351106643677";
"distance_apart" = "0.046980559825897";
"gallery_name" = test1;
height = 482;
"matching_threshold" = "0.4";
"next_subject" = hi;
"next_subject_confidence" = "0.94137054681778";
"simularity_threshold" = "0.1";
status = success;
subject = face3rd;
topLeftX = 148;
topLeftY = 92;
width = 482;
};
}
)]
What i have done is put three images in the database and have called each of them respectively, face3rd, hi, hi (sorry for the two hi's)
I have been trying to parse the names and the number next to it for soo long, i can get around the 6 second response time.
The reason i have not been able to get the names is because, as you can see, i don't know what to tell Swift to look for. The image name changes depending on who i get back.
I don't know if i've explained my situation, bestly, but if you look at the response. The parts that say:
face3rd = "0.988351106643677";
hi = "0.94137054681778";
hi = "0.94137054681778";
I need the information on both sides of the equal sign.
Thank you for your help and apologise, if reading it was pedantic or you felt like their was a lot of repetion.
Thanks!
Yes, it is poorly formatted JSON that we are returning. We will fix it in an upcoming version of the API (no release date at this time..sorry).
If all you need is the closest match, you can just access the subject variable directly and ignore the candidates array.
Otherwise, you would need to parse the candidates array manually unfortunately. I'm not sure how to do that in Swift.

sharedobjects multiple item

Is there a way to store multiple items in a shared object? I want to store the score and it's profile name at the same time in an android game.
here is my code so far.
if(playerScore > lvl1Score.data.score1 || lvl1Score.data.score1 == 0)
{
lvl1Score.data.score5 = lvl1Score.data.score4;
lvl1Score.data.score4 = lvl1Score.data.score3;
lvl1Score.data.score3 = lvl1Score.data.score2;
lvl1Score.data.score2 = lvl1Score.data.score1;
lvl1Score.data.score1 = playerScore;
lvl1Score.data.scoreName1 = curUser;
lvl1Score.flush();
}
scoreBoard.one.text = String(lvl1Score.data.score1);
can someone please help me?
You can store Objects in a shared object.
Following your example, this may look as follows:
lvl1Score.data.score5 = { score: 2, profileName: "some_score" };