36 ratings
  • 1
  • 2
  • 3
  • 4
  • 5
5 star 12
4 star 12
3 star 3
2 star 5
1 star 4
Compatible with
  • iOS
  • Android
  • Windows

Xamarin.Mobile 0.7.4

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.3

  • Improvements / Documentation for iOS 8 ActionSheet use

Changes from 0.7.2

  • Geolocator.IsGeolocationEnabled now tests for the iOS8 possible return status values

Changes from 0.7.1

  • Geolocator now requests location authorization on iOS 8 and higher based on which option is specified in Info.plist
  • Xamarin.iOS Unified API Support

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

15 reviews

Shane Boyed rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Having issues with image taking on iPad iOS8. A few other people are having the same problem:

https://forums.xamarin.com/discussion/25234/preview-issue-with-xamarin-media-mediapicker-after-update-to-ios8#latest

Please could you fix this ASAP!

Posted on: October 19 / Version: 0.7.4
Joe Mather rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

For geolocation with Xamarin.iOS 8.2 and iOS 8, you need to store a reference to the CLLocationManager in a class variable. If the CLLocationManager goes out of scope, you will not see the permission alert generated by iOS 8 and thus not receive location updates. More info:

http://forums.xamarin.com/discussion/comment/81298/#Comment_81298

The documentation for this component needs to be updated with this information.

Posted on: October 14 / Version: 0.7.4
Rahul rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

can we use this component for cross platform in Xamarin.Forms?

Posted on: October 8 / Version: 0.7.4
Chris Sells rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Why doesn't this show up for WP8 in NuGet? It only shows up in iOS and Android, even though it's tagged for WP8 as well.

Posted on: October 5 / Version: 0.7.4
Carel Lotz

Any plans to update the NuGet package (xamstore-xamarin.mobile) with the latest changes?

Posted on: September 25 / Version: 0.7.3
Bill Holmes

@Jonas @Abtin @Boris - We are working on an update to support iOS Unified. The CLLocationManager change will be in this update. You should see an update in the next few days as long as we do not hit a blocker.

Posted on: September 23 / Version: 0.7.1
Jonas Andersson rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

GPS does not work for iOS 8. Need an update soon!

Posted on: September 23 / Version: 0.7.1
Abtin Rostamian rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Great library but as Boris said, it doesn't work on iOS 8 because Apple has breaking changes in CLLocationManager which now require calling requestWhenInUseAuthorization to prompt the user for Location Services access. Xamarin, can you please update this library?

Posted on: September 22 / Version: 0.7.1
Boris Donev rates this with
  • 1
  • 2
  • 3
  • 4
  • 5

Great and easy to use!

One recently discovered issue: It doesn't work with iOS 8.

Posted on: September 15 / Version: 0.7.1
vipin kr

i download sample and compile it on visual studio 2010 and 2012 on my windows pc but project not loaded what is the problem. i am intersted in Xamarin.Mobile.iOS.Samples but it is now load.

error is The project type is not supported by this installation.

Posted on: July 3 / Version: 0.7.1
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