Windows Phone 7.5 People Tile - windows

I know that Windows Phone 7.5 has the ability to store contacts in the phone itself. I was wondering if there is a way to modify / extend the people tile so that I can add an option to save the contact to phone instead?

As far as I know from experience as a Windows Phone user and developer, a Contact can be saved to any linked account but not to a generic storage location on the phone. Contacts can be imported from the SIM card, but not saved to it. Contacts that appear to be stored on the phone are actually synced with a linked account (i.e. Hotmail, Google, etc). The People tile/hub aggregates Contact data from all linked accounts.
If you want to programmatically add a contact to the phone, you can use the SaveContactTask from the Microsoft.Phone.Tasks namespace.
using Microsoft.Phone.Tasks;
SaveContactTask _saveContactTask;
void SaveContact()
{
_saveContactTask = new SaveContactTask();
_saveContactTask.Completed +=
new EventHandler<SaveContactResult>(SaveContactTask_Completed);
try
{
saveContactTask.FirstName = "John";
saveContactTask.LastName = "Doe";
saveContactTask.MobilePhone = "2125551212";
saveContactTask.Show();
}
catch (System.InvalidOperationException ex)
{
MessageBox.Show("An error occurred.");
}
}
void SaveContactTask_Completed(object sender, SaveContactResult e)
{
switch (e.TaskResult)
{
case TaskResult.OK:
MessageBox.Show("Contact saved successfully.");
break;
case TaskResult.Cancel:
MessageBox.Show("Contact save cancelled.");
break;
case TaskResult.None:
MessageBox.Show("Contact could not be saved.");
break;
}
}
The official "How To" documentation can be found here:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394013(v=vs.92).aspx

The contacts are stored by default to the phone itself. It is just synced to your windows live/google/any other account you like to!

Related

Xamarin Essentials Android Contacts: is there a way to determine which phone number? EG: Home, Work, Mobile?

Xamarin Essentials Contacts: is there a way to determine which phone number is which? EG: Home, Work, Mobile?
This is just for Android only.
Currently it just has the phone number(s) only, but I have a need to only display Mobile phone numbers (for SMS) and I can't see a way to determine if a number is tagged as 'Mobile'. Like when you create a contact on your andriod phone, you can set the phone number to be Home, Mobile, Work, etc.
Or anyone know of another library that does this? thanks.
Let take the example from docs. You could use the property ContactType of type enum ContactType, but it only defines Unknown, Personal and Work values:
try
{
var contact = await Contacts.PickContactAsync();
if(contact == null)
return;
var phones = contact.Phones; // List of phone numbers
foreach (var phone in phones)
{
if (phone.ContactType == ContactType.Personal || phone.ContactType == ContactType.Work) //just an example
}
}
catch (Exception ex)
{
// Handle exception here.
}

How to add an Attachment to Outlook Mail from UWP App programmatically?

I am developing an UWP Application , i want to add a Attachment to outlook from UWP app programmatically
Request you to please me know if any alternatives are there.
Looking forward for your response.
You can use the share contract to send some data to the compliant applications (including outlook). It allows you to share some text and data with any compliant apps.
To activate the sharing, you just need to register to the DataRequested event and show the share UI:
DataTransferManager.GetForCurrentView().DataRequested += OnDataRequested;
DataTransferManager.ShowShareUI();
Then, in the event handler:
private async void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
var deferral = args.Request.GetDeferral();
try
{
args.Request.Data.Properties.Title = "Share Title"
args.Request.Data.Properties.Description = "Share some data/file";
var file = await ApplicationData.Current.TemporaryFolder.GetFileAsync("myFileToShare.xxx");
args.Request.Data.SetStorageItems(new IStorageItem[] { logFile });
}
catch
{
args.Request.FailWithDisplayText("Unable to share data");
}
finally
{
deferral.Complete();
sender.DataRequested -= OnDataRequested;
}
}
Once done, the system will show the share UI where the user will be able to select the app he want. This app will receive the sent data.
While #Vincent's answer is perfect when you want to use Share Contract, if you want to use Just Email and attach the File, Below is a simple Method that i use in one of my App.
internal async void ShowEmail(string body, string subject, StorageFile attachment)
{
EmailMessage email = new EmailMessage();
email.Subject = subject;
email.Body = body;
var stream = RandomAccessStreamReference.CreateFromFile(attachment);
email.SetBodyStream(EmailMessageBodyKind.Html, stream);
await EmailManager.ShowComposeNewEmailAsync(email);
}
Above method is a strip down of the example from Here

Get the list of Contacts on Windows 10 Phone

I am needing to know how to read the contact list on a Windows 10 Phone. I don't want to use a contact picker; I just need to be able to iterate through all contacts to access their name and phone number, and store it in a List. (Similar to how WhatsApp is able to read your contact list and display it in their app)
I've taken some code from another answer here.
With this code you should be able to get the contacts out.
public async Task IterateThroughContactsForContactListId()
{
ContactStore allAccessStore = await ContactManager.RequestStoreAsync(ContactStoreAccessType.AllContactsReadOnly);
var contacts = await allAccessStore.FindContactsAsync();
foreach (var contact in contacts)
{
//process aggregated contacts
if (contact.IsAggregate)
{
//here contact.ContactListId is "" (null....)
//in this case if you need the the ContactListId then you need to iterate through the raw contacts
var rawContacts = await allAccessStore.AggregateContactManager.FindRawContactsAsync(contact);
foreach (var rawContact in rawContacts)
{
//Here you should have ContactListId
Debug.WriteLine($"aggregated, name: {rawContact.DisplayName }, ContactListId: {rawContact.ContactListId}");
}
}
else //not aggregated contacts should work
{
Debug.WriteLine($"not aggregated, name: {contact.DisplayName }, ContactListId: {contact.ContactListId}");
}
}
}
He also notes:
And very important: In the appxmanifest you have to add the contacts
capability. Right click to it in the solution explorer and "View Code"
and then under Capabilities put
<uap:Capability Name="contacts" />
There is no UI for this. See this.

Is it possible to check whether the location services are active?

is it possible to check whether the location services are active?
I mean Settings > Location > Location services
There is probably no direct API for calling, but could it work with the GeoCoordinateWatcher?
GeoCoordinateWatcher g = new GeoCoordinateWatcher();
g.Start();
if (g.Permission.Equals(GeoPositionPermission.Granted))
{
//Your location services is enabled. Go ahead.
//Your codes goes here.
}
else if (g.Permission.Equals(GeoPositionPermission.Denied) || g.Permission.Equals(GeoPositionPermission.Unknown))
{
MessageBox.Show("Location services are disabled. To enable them, Goto Settings - Location - Enable Location Services.", "Location services", MessageBoxButton.OK);
}
You can use the following code to determine the status of the Location service:
var watcher = new GeoCoordinateWatcher();
if (GeoPositionStatus.Disabled == watcher.Status)
{
// Watcher is disabled.
}
More realistically, you'll want to pay more attention to change to the status (just because the service isn't disabled doesn't mean you've got location data), so you shoudl take a look at the MSDN Documentation for working with the Location service.
There's also a good post on filtering and emulating location data using the Reactive extensions, which is perfect for that pre-device testing, though to save you time on that front the Widnows Phone Team have released the Windows Phone GPS Emulator.
Even with the started GeoCoordinateWatcher you will get NoData if the sensor is disabled. What you should try using instead is TryStart:
GeoCoordinateWatcher g = new GeoCoordinateWatcher();
MessageBox.Show(g.TryStart(false,TimeSpan.FromSeconds(30)).ToString());
If it returns False, it means that the sensor is disabled. If it returns True, it is enabled. Set an appropriate timeout period (in the snippet above I am using 30 seconds) and delegate this process to a secondary thread, so it won't hang the UI.
You can add a StatusChanged event to your GeoCoordinateWatcher and test for GeoPositionPermission.Denied in the permissions when it fires.
watcher = new GeoCoordinateWatcher();
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.Start();
void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
if (watcher.Permission == GeoPositionPermission.Denied)
{
// Location services were disabled
}
}
Hope that helps.
Made this one based on TeJ's answer.
public override void OnNavigatedTo()
{
using (var watcher = new GeoCoordinateWatcher())
{
try
{
watcher.Start();
}
finally
{
IsAllowedInSystem = watcher.Permission.Equals(GeoPositionPermission.Granted);
watcher.Stop();
}
}
}
And my apps' ToggleSwitch.IsEnabled is binded to IsAllowedInSystem.
When i'm switching to Location Service, disable it and return back to app, my ToggleSwitch is disabled (also a string "Please, enable Location Service in System settings" in visible). When i'm switching to Location Service, enable it and return back to my app, my ToggleSwitch is enabled and user can set it up.

isTrial and the Marketplace for Windows phone 7

I'm trying to wrap up my latest app and I want to make it a Free Trial app.
I've done all my checks to see if it is in trial mode or not and now I'm about to launch the MarketPlace so they can buy it. I have a couple of questions...
In this code below, do I have to pass any sort of ID that my app generates so that it knows where to go in the Marketplace? Or is it all done for me in this call?
MarketplaceDetailTask detailTask = new MarketplaceDetailTask();
detailTask.Show();
My second question is in regards to the tombstoning that will happen when this code gets called and what happens after they buy it? Is there some special event that I should be looking for (like a completed event)? From what I understand I need to recheck the license and I'm just wondering what the best practices are for that.
Just as a reference this is the example I'm currently following:
http://msdn.microsoft.com/en-us/library/ff967559%28v=VS.92%29.aspx
Thanks!
1) First Question: if you don't specify the id, WP7 will take the id of the calling app (yours)
2)I have a service in front of the Licence class and when the user goes to the marketplace I reset a field to read again the trial status when ask afterwards (see the buy method below)
public class TrialService : ITrialService
{
private LicenseInformation license;
public bool IsTrial()
{
if (RunAsTrial)
return true;
else
{
if (license == null)
license = new LicenseInformation();
return license.IsTrial();
}
}
public void Buy()
{
license = null;
var launcher = new MarketplaceDetailTask();
launcher.Show();
}
public bool RunAsTrial { get; set; }
}

Resources