Xamarin mobile
-
Upload
mike-bluestein -
Category
Technology
-
view
12.877 -
download
4
Transcript of Xamarin mobile
![Page 1: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/1.jpg)
Mike BluesteinDeveloper/WriterXamarin
Xamarin.Mobile API
@mikebluestein
![Page 2: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/2.jpg)
Xamarin.Mobile
• Cross Platform APIXamarin.iOSXamarin.AndroidWindows Store ApplicationsWindows Phone 8Windows Phone 7.1
• Abstracts common device features
![Page 3: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/3.jpg)
Now Open Source!
![Page 4: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/4.jpg)
Architecture
Contacts
Xamarin.Mobile
Geolocation Camera
![Page 5: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/5.jpg)
Contacts
![Page 6: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/6.jpg)
Contacts
• AddressBookRequestPermission
• ContactPhoneEmailAddressWebsiteRelationship
![Page 7: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/7.jpg)
Contacts
• Maps to native implementation on each platform• AddressBook implements IQueryable• LINQ
![Page 8: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/8.jpg)
ABAddressBookRef ab = ABAddressBookCreate(); CFStringRef name = CFSTR ("Smith"); CFArrayRef smiths = ABAddressBookCopyPeopleWithName(ab, name); CFRelease (name); int count = CFArrayGetCount(smiths); for (int i = 0; i < count; ++i) { ABRecordRef person = (ABRecordRef)CFArrayGetValueAtIndex(smiths, (CFIndex)i); if (ABRecordGetRecordType(person) != kABPersonType) continue; NSString *name = (NSString*)ABRecordCopyCompositeName(person); NSLog ("%@\n", name); [name release]; ABMultiValueRef phoneNumberProp = ABRecordCopyValue(person, kABPersonPhoneProperty); NSArray* numbers = (NSArray*)ABMultiValueCopyArrayOfAllValues(phoneNumberProp); CFRelease(phoneNumberProp); for (NSString *pvalue in numbers)
NSLog ("Phone: %@\n", pvalue);
[numbers release]; ABMultiValueRef emailProp = ABRecordCopyValue(person, kABPersonEmailProperty); NSArray* emails = (NSArray*)ABMultiValueCopyArrayOfAllValues(emailProp); CFRelease(emailProp); for (NSString *evalue in emails) NSLog ("Email: %@\n"); [emails release]; } CFRelease (ab); CFRelease (smiths);
Contacts - iOS
![Page 9: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/9.jpg)
Contacts - AndroidContentResolver content= getContentResolver();
Cursor ncursor = null;try { ncursor = content.query (ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data.MIMETYPE, ContactsContract.Contacts.LOOKUP_KEY, ContactsContract.Contacts.DISPLAY_NAME }, ContactsContract.Data.MIMETYPE + "=? AND " + ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME + "=?", new String[] { ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE, "Smith" }, null);
while (ncursor.moveToNext()) { print (ncursor.getString(ncursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) + lineSep); String lookupKey = ncursor.getString (ncursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); Cursor dcursor = null; try { dcursor = content.query (ContactsContract.Data.CONTENT_URI, new String[] { ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.Data.DATA1 }, ContactsContract.Contacts.LOOKUP_KEY + "=?", new String[] { lookupKey }, null); while (dcursor.moveToNext()) { String type = dcursor.getString (ncursor.getColumnIndex(ContactsContract.Data.MIMETYPE));
if (type.equals (ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)) print ("Phone: " + dcursor.getString(dcursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)) +
lineSep); else if (type.equals (ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)) print ("Email: " + dcursor.getString(dcursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA1)) +
lineSep); } } finally { if (dcursor != null) dcursor.close(); } }} finally { if (ncursor != null) ncursor.close();}
![Page 10: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/10.jpg)
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);}
![Page 11: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/11.jpg)
Geolocation
![Page 12: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/12.jpg)
Geolocation
• Geolocator• Position
LatitudeLongitudeAccuracyAltitudeAltitude AccuracyHeading
![Page 13: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/13.jpg)
Geolocation
• Geolocator class• Retrieve current location• Listen for Location changes• DesiredAccuracy influences the location technology that is used
![Page 14: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/14.jpg)
MediaPicker
![Page 15: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/15.jpg)
MediaPicker
• Take Photos and Videos• Select Photos and Videos• Programmatic feature detection
MediaPicker.PhotosSupportedMediaPicker.VideosSupportedMediaPicker. IsCameraAvailable
![Page 16: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/16.jpg)
MediaPicker Camera
• Specify which camera to use• Specify video quality• Async and C# TPL Compatible
Task.ContinueWith, IsCancelled, IsFaulted
![Page 17: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/17.jpg)
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());
![Page 18: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/18.jpg)
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);}
![Page 19: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/19.jpg)
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());}
![Page 20: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/20.jpg)
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
![Page 21: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/21.jpg)
Demo
![Page 22: Xamarin mobile](https://reader033.fdocuments.us/reader033/viewer/2022052523/5554dfc8b4c9051b6e8b530d/html5/thumbnails/22.jpg)
Resources
xamarin.com/mobileapi