John S.
John S.

Reputation: 15

How can I use Android.App.Application and Xamarin.Forms.Application in the same class?

I get an error message because I have the following two lines of code in the same class:

using Xamarin.Forms;
using Android.App;

Error CS0104: 'Application' is an ambiguous reference between 'Android.App.Application' and 'Xamarin.Forms.Application'

 if (Device.RuntimePlatform == Device.Android)
   deviceID = Settings.Secure.GetString(Application.Context.ContentResolver, Settings.Secure.AndroidId);

How can I use Android.App to execute the code? I need the deviceID. I can not remove "using Xamarin.Forms;" because I use it in the class.

Upvotes: 1

Views: 831

Answers (1)

Jason
Jason

Reputation: 89214

you can assign an alias to a namespace

using xf = Xamarin.Forms;
using aa = Android.App;

...

aa.Application.Context.ContentResolver...

or you can just use the fully qualified namespace in your code

Android.App.Application.Context.ContentResolver...

or use the global keyword if your project namespace conflicts with another namespace

global::Android.App.Application.Context.ContentResolver...

Upvotes: 1

Related Questions