using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; using Android.Locations; using System.Text; using System.IO; namespace MonoForAndroidOther { [Activity (Label = "MonoForAndroidOther", MainLauncher = true)] public class Activity1 : Activity,ILocationListener { protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Main); LocationManager locationManager = (LocationManager)GetSystemService(LocationService); var criteria = new Criteria() { Accuracy = Accuracy.NoRequirement }; string bestProvider = locationManager.GetBestProvider(criteria, true); Location lastLocation = locationManager.GetLastKnownLocation(bestProvider); if (lastLocation != null) Console.WriteLine("Last location, lat: {0}, long: {1}", lastLocation.Latitude, lastLocation.Longitude); locationManager.RequestLocationUpdates(bestProvider, 5000, 2, this); } private void SharePreferences() { // save shared preference item ISharedPreferences saveSharedPreference = GetPreferences (FileCreationMode.Append); ISharedPreferencesEditor editor = saveSharedPreference.Edit (); editor.PutString ("StringSetting", "string"); editor.PutInt ("IntSetting", 1); editor.PutBoolean ("BoolSetting", false); editor.Commit (); // get shared preference item ISharedPreferences getSharedPreference = GetPreferences (FileCreationMode.Append); string stringSetting = getSharedPreference.GetString ("StringSetting", "Default Value"); int intSetting = getSharedPreference.GetInt ("IntSetting", 1); bool boolSetting = getSharedPreference.GetBoolean ("BoolSetting", true); } void ILocationListener.OnLocationChanged (Location location) { Console.WriteLine("Location updated, lat: {0}, long: {1}",location.Latitude, location.Longitude); } void ILocationListener.OnProviderDisabled (string provider) { } void ILocationListener.OnProviderEnabled (string provider) { } void ILocationListener.OnStatusChanged (string provider, Availability status, Bundle extras) { } } }