21 ratings
  • 1
  • 2
  • 3
  • 4
  • 5
5 star 6
4 star 9
3 star 3
2 star 3
1 star 0
Compatible with
  • iOS
  • Android
  • Windows

Xamarin.Mobile 0.7.1

Xamarin Inc.

Xamarin.Mobile is a library that exposes a single set of APIs for accessing common mobile device functionality across iOS, Android and Windows platforms.

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):

using Xamarin.Contacts;
// ...

var book = new AddressBook ();
//         new AddressBook (this); on Android
if (!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):

using Xamarin.Geolocation;
// ...

var locator = new Geolocator { DesiredAccuracy = 50 };
//            new Geolocator (this) { ... }; on Android

Position 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:

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):

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);
}

Release Notes

Changes from 0.7

Fixes:

  • MediaPicker taking photos should now work correctly on Xperia devices.

  • MediaPicker.TakePhoto/Video now appears fullscreen on iPad as per the Apple guidance.

  • EXTRA_OUTPUT is now used for taking video as well, avoiding a file move with supporting camera apps.

Changes from 0.6.3

Significant changes

  • New APIs for controlling MediaPicker UI on iOS and Android. Previous API has been deprecated on Android.

Fixes:

  • AddressBook.OrderBy() now returns correctly ordered results on Android,

  • Geolocator.GetPositionAsync (CancellationToken) no longer fails on Android.

  • Position ctor now copies Altitude property.

  • Android's Contact.SaveThumbnailAsync now works properly on non-looper threads.

Write a Review

5 reviews

Benjamin Mayrargue rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Very good idea. But too buggy.

Posted on: January 4 / Version: 0.7.1
Torben Kovaltsenko Jørgensen rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Thanks for creating this lib.

We've encountered a problem with the MediaPicker when taking a photo using high resolution ipads we get a memory warning when accepting the newly taken photo. Is it possible you could add more options to StoreCameraMediaOptions? In this case we could use a quality setting or another way to reduce size.

Posted on: December 13, 2013 / Version: 0.7
Alex Mertlich rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

I notice the release notes for 0.7 state "Given the fragility of the Task<> based API ...async API is now marked [Obsolete]". Does that mean we shouldn't be using Task<> in our Android applications??? I haven't read any where else that we should avoid this?

Also, I've noticed that on previous versions the Geolocator seems to always try using the GPS on Android regardless of the accuracy specified. Is that fixed?

Posted on: December 13, 2013 / Version: 0.7
DNPDEV DNPDEV

Very nice component!! However we found a bug using latest version on IOS7 taking a photo using camera: the device orientation not always correspond to the camera orientation; if you take a photo in portrait mode, then change to landscape and take another photo, the camera orientation is not correct. We have posted a snapshot in the 'Component Store' forum. Any idea how to resolve this problem?

Posted on: December 13, 2013 / Version: 0.7
Tom Lagan rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

It's a good start, and we've got the camera working on Samsung and HTC devices, but on the Sony Xperia Z it doesn't work - no exception etc, but just doesn't return a path (continue with method not hit at all).

So we've used the library to capture the picture and then manually extract the information we want from the intent result.

Posted on: December 13, 2013 / Version: 0.7