/// <summary> /// Gets the memory cache size based on a percentage of the max available VM memory. /// </summary> /// <example>setting percent to 0.2 would set the memory cache to one fifth of the available memory</example> /// <param name="percent">Percent of available app memory to use to size memory cache</param> /// <returns></returns> private static int GetCacheSizeInPercent(float percent) { if (percent < 0.01f || percent > 0.8f) { throw new Exception("GetCacheSizeInPercent - percent must be between 0.01 and 0.8 (inclusive)"); } var context = new Android.Content.ContextWrapper(Android.App.Application.Context); var am = (ActivityManager)context.GetSystemService(Context.ActivityService); bool largeHeap = (context.ApplicationInfo.Flags & ApplicationInfoFlags.LargeHeap) != 0; int memoryClass = am.MemoryClass; if (largeHeap && Utils.HasHoneycomb()) { memoryClass = am.LargeMemoryClass; } int availableMemory = 1024 * 1024 * memoryClass; return((int)Math.Round(percent * availableMemory)); }
public void InitLocationService() { var wrapper = new Android.Content.ContextWrapper(Forms.Context); _locationManager = (LocationManager) wrapper.GetSystemService(Context.LocationService); Criteria criteriaForLocationService = new Criteria { Accuracy = Accuracy.Fine }; IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true); if (acceptableLocationProviders.Any()) { _locationProvider = acceptableLocationProviders.First(); _locationManager.RequestLocationUpdates(_locationProvider, 2000, 10, this); } else { _locationProvider = String.Empty; } Console.WriteLine("Using " + _locationProvider + "."); }
public void InitLocationService() { var wrapper = new Android.Content.ContextWrapper(Forms.Context); _locationManager = (LocationManager)wrapper.GetSystemService(Context.LocationService); Criteria criteriaForLocationService = new Criteria { Accuracy = Accuracy.Fine }; IList <string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true); if (acceptableLocationProviders.Any()) { _locationProvider = acceptableLocationProviders.First(); _locationManager.RequestLocationUpdates(_locationProvider, 2000, 10, this); } else { _locationProvider = String.Empty; } Console.WriteLine("Using " + _locationProvider + "."); }
/// <summary> /// Gets the memory cache size based on a percentage of the max available VM memory. /// </summary> /// <example>setting percent to 0.2 would set the memory cache to one fifth of the available memory</example> /// <param name="percent">Percent of available app memory to use to size memory cache</param> /// <returns></returns> private static int GetCacheSizeInPercent(float percent) { if (percent < 0.01f || percent > 0.8f) throw new Exception("GetCacheSizeInPercent - percent must be between 0.01 and 0.8 (inclusive)"); var context = new Android.Content.ContextWrapper(Android.App.Application.Context); var am = (ActivityManager) context.GetSystemService(Context.ActivityService); bool largeHeap = (context.ApplicationInfo.Flags & ApplicationInfoFlags.LargeHeap) != 0; int memoryClass = am.MemoryClass; if (largeHeap && Utils.HasHoneycomb()) { memoryClass = am.LargeMemoryClass; } int availableMemory = 1024 * 1024 * memoryClass; return (int)Math.Round(percent * availableMemory); }