Xamarin.Mobile
• Cross Platform API
Xamarin.iOS
Xamarin.Android
Windows Store Applications
Windows Phone 8
Windows Phone 7.1
• Abstracts common device features
Xamarin.Mobile Contacts
var book = new AddressBook ();
foreach (Contact c in book.Where (c => c.LastName == "Smith")) {
Console.WriteLine (c.DisplayName);
foreach (Phone p in c.Phones)
Console.WriteLine ("Phone: " + p.Number);
foreach (Email e in c.Emails)
Console.WriteLine ("Email: " + e.Address);
}
Geolocation
• Geolocator class
• Retrieve current location
• Listen for Location changes
• DesiredAccuracy influences the location technology that is used
MediaPicker
• Take Photos and Videos
• Select Photos and Videos
• Programmatic feature detection
MediaPicker.PhotosSupported
MediaPicker.VideosSupported
MediaPicker. IsCameraAvailable
MediaPicker Camera
• Specify which camera to use
• Specify video quality
• Async and C# TPL Compatible
Task.ContinueWith, IsCancelled, IsFaulted
MediaPicker iOS
var picker = new MediaPicker();
MediaPickerController controller = picker.GetTakePhotoUI (new
StoreCameraMediaOptions {
Name = "test.jpg",
Directory = "MediaPickerSample"
});
PresentViewController (controller, true, null);
controller.GetResultAsync().ContinueWith (t => {
// Dismiss the UI yourself
controller.DismissViewController (true, () => {
MediaFile file = t.Result;
});
}, TaskScheduler.FromCurrentSynchronizationContext());
MediaPicker Android
var picker = new MediaPicker (this);
if (!picker.IsCameraAvailable)
Console.WriteLine ("No camera!");
else {
var intent = picker.GetTakePhotoUI (new StoreCameraMediaOptions {
Name = "test.jpg",
Directory = "MediaPickerSample"
});
StartActivityForResult (intent, 1);
}
MediaPicker Android
protected override void OnActivityResult (int requestCode, Result resultCode,
Intent data)
{
// User canceled
if (resultCode == Result.Canceled)
return;
data.GetMediaFileExtraAsync (this).ContinueWith (t => {
if (requestCode == 1) { // Video request
ShowVideo (t.Result.Path);
} else if (requestCode == 2) { // Image request
ShowImage (t.Result.Path);
}
}, TaskScheduler.FromCurrentSynchronizationContext());
}
var mediaPickerController = mediaPicker.GetPickPhotoUI();
mediaPickerController.GetResultAsync()
.ContinueWith (t => {
mediaPickerController.DismissViewController (
true, () => {
// User canceled or something went wrong
if (t.IsCanceled || t.IsFaulted)
return;
// We get back a MediaFile
MediaFile media = t.Result;
});
}, TaskScheduler.FromCurrentSynchronizationContext());
MediaPicker Selecting Photos