Device APIs with Xamarin

Slides:



Advertisements
Similar presentations
Inside Windows Boot Process Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Advertisements

Guidelines to Preparing and Delivering an Elevator Pitch Presentation Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training.
Two basic algorithms for path searching in a graph Telerik Algo Academy Graph Algorithms.
XAML and Controls Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Eclipse + Android SDK, VS + Windows Phone SDK Telerik Software Academy Hybrid Mobile Applications.
Welcome to the JSON-stores world Learning & Development Telerik Software Academy.
Eclipse + Android SDK, VS + Windows Phone SDK Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Things you need to know George Georgiev Technical Trainer GeorgeAtanasov George Atanasov Front-End Developer.
Hamiltonian Cycle Penka Borukova Student at Telerik Academy.
Group Policy Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation “Baba Tonka” High School of Mathematics.
Telerik Software Academy ASP.NET MVC.
Sales Processes, Sales Cycle and the Sales Force Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System Analyst Telerik.
Design Patterns that ease the design by identifying a simple way to realize relationships between entities. Antony Jekov Telerik Software Academy academy.telerik.com.
Xamarin.Forms Hands On.
The way to create cross-platform apps Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
PEST Analysis, Porter’s 5 Forces and Sustainability Strategies Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System.
Searching for a Job, Writing CV and Cover Letter, Passing a Job Interview Telerik Academy for Software Engineers October 6 th 2012 – Sofia academy.telerik.com.
Drive Partitioning Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Telerik Software Academy Mobile apps for iPhone & iPad.
Consuming REST Services from C# SoftUni Team Technical Trainers Software University
Google APIs and Facebook API Ivaylo Kenov Penka Borukova Telerik Corporation Telerik Academy Students.
The magic of virtual machines Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Telerik Software Academy Mobile apps for iPhone & iPad.
Academy.telerik.com Class of , Fall 2013.
Telerik Software Academy Databases.
Google APIs and Facebook API Ivaylo Kenov Penka Borukova Telerik Corporation Telerik Academy Students.
Telerik Software Academy ASP.NET Web Forms.
JavaScript Modules and Patterns Telerik Software Academy
Deal with initializing and configuring classes and objects Telerik Software Academy High-Quality Code.

Approximate string matching Evlogi Hristov Telerik Corporation Student at Telerik Academy.
Xamarin with SQLite Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
Ivaylo Kenov Telerik Software Academy Technical Assistant.
The PhoneGap History Doncho Minkov Telerik Software Academy Technical Trainer
Building Rock-Solid Software Svetlin Nakov Telerik Software Academy Manager Technical Training
Cultivating Professionals for Your Company The Success Story of Telerik Svetlin Nakov, PhD Manager Technical Training Telerik Corp.
Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
Installation, Sample Usage, Strings and OOP Telerik Software Academy Software Quality Assurance.
In JavaScript Learning & Development Telerik Software Academy.
Services in AngularJS Telerik Software Academy
Svetlin Nakov Telerik Software Academy Manager Technical Training
What is Roslyn and how can we use it? Telerik Academy Plus C# 6.0 and Roslyn Seminar.
Changing the default visualization of views in Xamarin.Forms Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
LINQ and Lambda Expressions Telerik Software Academy LINQ Overview.
Telerik Software Academy HTML5.
What to expect from the new IDE Telerik Academy Plus Visual Studio 2015 and ASP.NET 5.
Hristian Hristov Telerik Corporation
Backup and Security Management Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Network Configuration Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
I have to use math? I am out of here… Telerik School Academy Unity 2D Game Development.
Virtualization Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Penka Borukova Student at Telerik Academy. 1. Boyer Moore String Search Algorithm 2. The bad character rule 3. The good suffix rule 4. The algorithm itself.
Cross-platform mobile development. Simplified. Pavel Kolev Telerik Software Academy Software Developer
Windows Administration Course Overview Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Automating Windows Deployment Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Serving HTTP requests Learning & Development Telerik School Academy.
Shared Application Telerik School Academy Xamarin apps for iOS, Android & WinPhone.
Server Roles and Features Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Binary, Decimal and Hexadecimal Numbers Telerik Software Academy C# Fundamentals – Part 2.
File and Print Services Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Adding UI and Audio element Telerik Academy Plus Unity 2D Game Development.
Redis and Redis with .NET
Mocking Tool for easier unit testing
Entity Framework Performance
Web Service Testing …in another way Software Quality Assurance
File Upload in ASP.NET Ivaylo Kenov Technical Assistant
Android Introduction Camera.
Presentation transcript:

Device APIs with Xamarin http://schoolacademy.telerik.com Device APIs with Xamarin Accessing Phonebook, Location, Camera http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/databases/ Xamarin apps for iOS, Android & WinPhone Telerik School Academy http://schoolacademy.telerik.com

Table of Contents Reference Xamarin.Mobile Accessing Device APIs * Table of Contents Reference Xamarin.Mobile Accessing Device APIs Geo location Address book Camera (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Xamarin.Mobile Download Xamarin.Mobile or install through Components for each platform

Table of Contents Geo location Reference Xamarin.Mobile * Table of Contents Reference Xamarin.Mobile Accessing Device APIs Geo location Address book Camera (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Geolocation Shared Code Add interface IGeolocator Use DependencyServices to call methods Use MessageingCenter to Subscribe to event Public interface IGeolocator { void GetPosition(); } IGeolocator locator = DependencyService .Get<IGeolocator>(); locator.GetPosition(); MessagingCenter.Subscribe<IGeolocator, AppPosition>(this, [matching string], DisplayPosition);

Geolocation Implementation Add device implementation and use Dependency [assembly: Dependency (typeof (Geolocator_Android))] public class Geolocator_Android : Action, IGeolocator { public GeoLocation GetPosition () { var locator = new Geolocator(Forms.Context) { DesiredAccuracy = 50 }; if (locator.IsListening != true) { locator.StartListening( minTime: 1000, minDistance: 0); } var pos = await locator.GetPositionAsync( timeout: 20000); MessagingCenter.Send<IGeolocator, AppPosition>( this, "gotLocation", new AppPosition( pos.Latitude, pos.Longitude) });

Table of Contents Address book Reference Xamarin.Mobile * Table of Contents Reference Xamarin.Mobile Accessing Device APIs Geo location Address book Camera (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Address Book Shared Code Add interface IContactsGetter Use DependencyServices to call methods Use MessageingCenter to Subscribe to event Public interface IContactsGetter { void GetPhonebook(); } IContactsGetter contactsGetter = DependencyService .Get<IContactsGetter>(); contactsGetter.GetPhonebook(); MessagingCenter .Subscribe<IContactsGetter, IEnumerable<AppContact>> (this, [matching string], DisplayContacts);

Address Book Implementation Add device implementation and use Dependency public async void GetPhonebook() { var book = new AddressBook(Forms.Context); var hasAccess = await book.RequestPermission(); if (hasAccess) { List<AppContact> contacts = new List<AppContact>(); foreach (var c in book) { contacts.Add(new AppContact() { Name = c.DisplayName, Number = c.Phones.FirstOrDefault().Number }); } MessagingCenter .Send<IContactsGetter,IEnumerable<AppContact>> (this, "gotContacts", contacts); } }

Table of Contents Camera Reference Xamarin.Mobile * Table of Contents Reference Xamarin.Mobile Accessing Device APIs Geo location Address book Camera (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Camera Shared Code Add interface ITakePhoto Add assembly Dependency Public interface ITakePhoto { void TakePhoto(); } IPhotoTaker picker = DependencyService .Get<IPhotoTaker>(); picker.TakePhoto(); MessagingCenter .Subscribe<IPhotoTaker, string>( this, "photoTaken", PathPhotoTaken);

Camera Android (1) Add device implementation and use Dependency public async void TakePhoto() { var picker = new MediaPicker(Forms.Context); var intent = picker.GetTakePhotoUI(new StoreCameraMediaOptions { DefaultCamera = CameraDevice.Rear, Directory = "DemoFolder", Name = "myPic.jpg" }); StartActivityForResult(intent, 1); }

Camera Android (2) Override OnActivityResult protected async override void OnActivityResult( int requestCode, Result resultCode, Intent data) { if (resultCode == Result.Canceled) return; var mediaFile = await data .GetMediaFileExtraAsync(Forms.Context); MessagingCenter.Send<IPhotoTaker, string>( this, "photoTaken", mediaFile.Path); }

Camera iOS Add interface and use the Xamarin.DependencyServices using Xamarin.Media; // ... var picker = new MediaPicker(); picker .PickPhotoAsync() .ContinueWith (t => { MediaFile file = t.Result; Console.WriteLine (file.Path); }, TaskScheduler.FromCurrentSynchronizationContext());

Device APIs with Xamarin http://academy.telerik.com

Free Trainings @ Telerik Academy C# Programming @ Telerik Academy csharpfundamentals.telerik.com Telerik Software Academy academy.telerik.com Telerik Academy @ Facebook facebook.com/TelerikAcademy Telerik Software Academy Forums forums.academy.telerik.com