Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xamarin/Xamarin.Mobile
A project to use a common way of accessing phone functionality
https://github.com/xamarin/Xamarin.Mobile
Last synced: 3 months ago
JSON representation
A project to use a common way of accessing phone functionality
- Host: GitHub
- URL: https://github.com/xamarin/Xamarin.Mobile
- Owner: xamarin
- License: apache-2.0
- Archived: true
- Fork: true (chrisntr/MonoMobile.Extensions)
- Created: 2011-10-27T19:21:29.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2015-10-28T19:36:39.000Z (about 9 years ago)
- Last Synced: 2024-06-23T04:57:37.752Z (5 months ago)
- Language: C#
- Homepage:
- Size: 5.69 MB
- Stars: 235
- Watchers: 86
- Forks: 85
- Open Issues: 29
-
Metadata Files:
- Readme: readme.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-xamarin - Xamarin.Mobile ★237 - Reading the user's address book and using the camera. (XPlat APIs)
README
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.**Note:** The Windows Phone 7.1 version of the library requires the
Microsoft.Bcl.Async NuGet package. You'll need to restore this package
to use the samples or download this package to any WP7 app using
Xamarin.Mobile.## Examples
To access the address book (requires `READ_CONTACTS` permissions
on Android):```csharp
using Xamarin.Contacts;
// ...var book = new AddressBook ();
// new AddressBook (this); on Androidif (!await book.RequestPermission()) {
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);
}
```To get the user's location (requires `ACCESS_COARSE_LOCATION` and
`ACCESS_FINE_LOCATION` permissions on Android):```csharp
using Xamarin.Geolocation;
// ...var locator = new Geolocator { DesiredAccuracy = 50 };
// new Geolocator (this) { ... }; on AndroidPosition position = await locator.GetPositionAsync (timeout: 10000);
Console.WriteLine ("Position Status: {0}", position.Timestamp);
Console.WriteLine ("Position Latitude: {0}", position.Latitude);
Console.WriteLine ("Position Longitude: {0}", position.Longitude);
```To take a photo:
```csharp
using Xamarin.Media;
// ...var picker = new MediaPicker ();
if (!picker.IsCameraAvailable)
Console.WriteLine ("No camera!");
else {
try {
MediaFile file = await picker.TakePhotoAsync (new StoreCameraMediaOptions {
Name = "test.jpg",
Directory = "MediaPickerSample"
});Console.WriteLine (file.Path);
} catch (OperationCanceledException) {
Console.WriteLine ("Canceled");
}
}
```On Android (requires `WRITE_EXTERNAL_STORAGE` permissions):
```csharp
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 async void OnActivityResult (int requestCode, Result resultCode, Intent data)
{
// User canceled
if (resultCode == Result.Canceled)
return;MediaFile file = await data.GetMediaFileExtraAsync (this);
Console.WriteLine (file.Path);
}
```