topical media & game development

talk show tell print

#mobile-application-12-MonoForAndroidOther-MonoForAndroidOther-Activity1.cs / cs



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


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.