Git Product home page Git Product logo

xamarin.mobile's Introduction

Xamarin.Mobile is an API for accessing common platform features, such as reading the user's address book and using the camera, across iOS, Android, and Windows Phone.

The goal of Xamarin.Mobile is to decrease the amount of platform-specific code needed to perform common tasks in multiplatform apps, making development simpler and faster.

Xamarin.Mobile is currently a preview release and is subject to API changes. Current known issues:

Examples

To access the address book (requires READ_CONTACTS permissions on Android):

using Xamarin.Contacts;
// ...

var book = new AddressBook ();
//         new AddressBook (this); on Android
book.RequestPermission().ContinueWith (t => {
 if (!t.Result) {
		Console.WriteLine ("Permission denied by user or manifest");
		return;
	}

	foreach (Contact contact in book.OrderBy (c => c.LastName)) {
		Console.WriteLine ("{0} {1}", contact.FirstName, contact.LastName);
	}
}, TaskScheduler.FromCurrentSynchronizationContext());

To get the user's location (requires ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permissions on Android):

using Xamarin.Geolocation;
// ...

var locator = new Geolocator { DesiredAccuracy = 50 };
//            new Geolocator (this) { ... }; on Android
locator.GetPositionAsync (timeout: 10000).ContinueWith (t => {
	Console.WriteLine ("Position Status: {0}", t.Result.Timestamp);
	Console.WriteLine ("Position Latitude: {0}", t.Result.Latitude);
	Console.WriteLine ("Position Longitude: {0}", t.Result.Longitude);
}, TaskScheduler.FromCurrentSynchronizationContext());

To take a photo:

using Xamarin.Media;
// ...

var picker = new MediaPicker ();
if (!picker.IsCameraAvailable)
	Console.WriteLine ("No camera!");
else {
	picker.TakePhotoAsync (new StoreCameraMediaOptions {
		Name = "test.jpg",
		Directory = "MediaPickerSample"
	}).ContinueWith (t => {
		if (t.IsCanceled) {
			Console.WriteLine ("User canceled");
			return;
		}
		Console.WriteLine (t.Result.Path);
	}, TaskScheduler.FromCurrentSynchronizationContext());
}

On Android (requires WRITE_EXTERNAL_STORAGE permissions):

using Xamarin.Media;
// ...

protected override void OnCreate (Bundle bundle)
{
	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);
	}
}

protected override void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
	// User canceled
	if (resultCode == Result.Canceled)
		return;

	data.GetMediaFileExtraAsync (this).ContinueWith (t => {
		Console.WriteLine (t.Result.Path);
	}, TaskScheduler.FromCurrentSynchronizationContext());
}

xamarin.mobile's People

Contributors

anders-hammervold avatar bojanrajkovic avatar chrisntr avatar dvdsgl avatar ermau avatar follesoe avatar ignaciofuentes avatar keithballinger avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.