本文整理汇总了C#中Android.Locations.LocationManager.IsProviderEnabled方法的典型用法代码示例。如果您正苦于以下问题:C# LocationManager.IsProviderEnabled方法的具体用法?C# LocationManager.IsProviderEnabled怎么用?C# LocationManager.IsProviderEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Android.Locations.LocationManager
的用法示例。
在下文中一共展示了LocationManager.IsProviderEnabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LocationTracker
/// <summary>
/// コンストラクタ
/// </summary>
/// <param name="context"></param>
public LocationTracker(Context context, string provider = LocationManager.GpsProvider)
{
locationMan = (LocationManager)context.GetSystemService(Service.LocationService);
if(locationMan.GetProviders(true).Contains(provider))
{
Provider = provider;
}
else if (locationMan.IsProviderEnabled(LocationManager.GpsProvider))
{
Provider = LocationManager.GpsProvider;
}
else if (locationMan.IsProviderEnabled(LocationManager.NetworkProvider))
{
Provider = LocationManager.NetworkProvider;
}
else
{
Criteria crit = new Criteria();
crit.Accuracy = Accuracy.Fine;
Provider = locationMan.GetBestProvider(crit, true);
}
LastGPSReceived = DateTime.MinValue;
}
示例2: GetLocation
public Location GetLocation() {
try {
locationManager = (LocationManager)mContext.GetSystemService("location");
// Getting GPS status
isGPSEnabled = locationManager.IsProviderEnabled(LocationManager.GpsProvider);
// Getting network status
isNetworkEnabled = locationManager.IsProviderEnabled(LocationManager.NetworkProvider);
if (!isGPSEnabled && !isNetworkEnabled) {
//showalert in activity
}
else {
this.CanGetLocation = true;
if (isNetworkEnabled) {
locationManager.RequestLocationUpdates(
LocationManager.NetworkProvider,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager.GetLastKnownLocation(LocationManager.NetworkProvider);
if (location != null) {
latitude = location.Latitude;
longitude = location.Longitude;
}
}
}
if (isGPSEnabled) {
if (location == null) {
locationManager.RequestLocationUpdates(
LocationManager.GpsProvider,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager.GetLastKnownLocation(LocationManager.GpsProvider);
if (location != null) {
latitude = location.Latitude;
longitude = location.Longitude;
}
}
}
}
}
} catch (Exception e) {
AlertsService.ShowToast(this.mContext, "Nie masz w³¹czonej lokalizacji!");
}
return location;
}
示例3: CheckLocationRequirements
private PhoneRequirements CheckLocationRequirements()
{
_locationManager = (LocationManager)GetSystemService(LocationService);
_connectivityManager = (ConnectivityManager)GetSystemService(ConnectivityService);
var internetAccess = _connectivityManager.ActiveNetworkInfo;
return new PhoneRequirements()
{
Gps = _locationManager.IsProviderEnabled(LocationManager.GpsProvider),
Network = _locationManager.IsProviderEnabled(LocationManager.NetworkProvider),
Internet = internetAccess != null && internetAccess.IsConnected
};
}
示例4: OnResume
protected override void OnResume()
{
base.OnResume();
locMgr = GetSystemService(Context.LocationService) as LocationManager;
#if DEBUG
// 利用可能な LocationManager の Provider とオンオフをチェック
foreach (var item in locMgr.AllProviders)
{
Log.Debug("NetworkList", "Provider: " + item.ToString());
Log.Debug("NetworkList", "Avalable: " + locMgr.IsProviderEnabled(item.ToString()));
}
#endif
button.Click += (sender, e) =>
{
if (button.Text.ToUpper() == "GET LOCATION")
{
button.Text = "Location Service Running";
if (locMgr.AllProviders.Contains(LocationManager.NetworkProvider)
&& locMgr.IsProviderEnabled(LocationManager.NetworkProvider))
{
// Network: Wifi と 3G で位置情報を取得します。電池使用量は少ないですが精度にばらつきがあります。
Log.Debug(tag, "Starting location updates with Network");
locMgr.RequestLocationUpdates(LocationManager.NetworkProvider, 10000, 10, this);
}
else
{
// GetBestProvider で最適な Provider を利用できるようです。(Network があればそれが Best になるようです。)
var locationCriteria = new Criteria();
locationCriteria.Accuracy = Accuracy.Coarse;
locationCriteria.PowerRequirement = Power.Medium;
string locationProvider = locMgr.GetBestProvider(locationCriteria, true);
Log.Debug(tag, "Starting location updates with " + locationProvider.ToString());
locMgr.RequestLocationUpdates(locationProvider, 10000, 10, this);
}
}
else
{
Log.Debug(tag, "Stop locMgr manually");
locMgr.RemoveUpdates(this);
button.Text = "Get Location";
}
};
}
示例5: GetCurrentLocation
protected override void GetCurrentLocation()
{
locationManager = context.GetSystemService(Context.LocationService) as LocationManager;
if (locationManager.IsProviderEnabled(LocationManager.GpsProvider))
locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 1, this);
}
示例6: OnResume
protected override void OnResume()
{
base.OnResume();
// LocationManagerを初期化
locMgr = GetSystemService(Context.LocationService) as LocationManager;
button.Click += (sender, e) =>
{
if (locMgr.AllProviders.Contains(LocationManager.NetworkProvider)
&& locMgr.IsProviderEnabled(LocationManager.NetworkProvider))
{
// Network: Wifiと3Gで位置情報を取得します。電池使用量は少ないですが精度にばらつきがあります。
Log.Debug(tag, "Starting location updates with Network");
locMgr.RequestLocationUpdates(LocationManager.NetworkProvider, 10000, 10, this);
}
else
{
// GetBestProviderで最適なProviderを利用できるようです。(NetworkがあればそれがBestProviderになるようです。)
var locationCriteria = new Criteria();
locationCriteria.Accuracy = Accuracy.Coarse;
locationCriteria.PowerRequirement = Power.Medium;
string locationProvider = locMgr.GetBestProvider(locationCriteria, true);
Log.Debug(tag, "Starting location updates with " + locationProvider.ToString());
locMgr.RequestLocationUpdates(locationProvider, 10000, 10, this);
}
};
}
示例7: PlatformSpecificStart
protected override void PlatformSpecificStart(MvxLocationOptions options)
{
if (_locationManager != null)
throw new MvxException("You cannot start the MvxLocation service more than once");
_locationManager = (LocationManager)Context.GetSystemService(Context.LocationService);
if (_locationManager == null)
{
MvxTrace.Warning("Location Service Manager unavailable - returned null");
SendError(MvxLocationErrorCode.ServiceUnavailable);
return;
}
var criteria = new Criteria()
{
Accuracy = options.Accuracy == MvxLocationAccuracy.Fine ? Accuracy.Fine : Accuracy.Coarse,
};
_bestProvider = _locationManager.GetBestProvider(criteria, true);
if (_bestProvider == null)
{
MvxTrace.Warning("Location Service Provider unavailable - returned null");
SendError(MvxLocationErrorCode.ServiceUnavailable);
return;
}
_locationManager.RequestLocationUpdates(
_bestProvider,
(long)options.TimeBetweenUpdates.TotalMilliseconds,
options.MovementThresholdInM,
_locationListener);
Permission = _locationManager.IsProviderEnabled (_bestProvider)
? MvxLocationPermission.Granted
: MvxLocationPermission.Denied;
}
示例8: OnCreate
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
// Get our button from the layout resource,
// and attach an event to it
nameEditText = FindViewById<EditText>(Resource.Id.firstNameTextField);
surnameEditText = FindViewById<EditText>(Resource.Id.surNameTextField);
locM = GetSystemService(Context.LocationService) as LocationManager;
if (locM.IsProviderEnabled(LocationManager.GpsProvider))
locM.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 1, this);
Button notificationButton1 = FindViewById<Button>(Resource.Id.notificationButton1);
Button notificationButton2 = FindViewById<Button>(Resource.Id.notificationbutton2);
Button notificationButton3 = FindViewById<Button>(Resource.Id.notificationbutton3);
Button notificationButton4 = FindViewById<Button>(Resource.Id.notificationbutton4);
Button notificationButton5 = FindViewById<Button>(Resource.Id.notificationbutton5);
textView = FindViewById<TextView>(Resource.Id.textView2);
notificationButtons = new Button[] { notificationButton1, notificationButton2, notificationButton3, notificationButton4, notificationButton5 };
foreach (Button button in notificationButtons)
{
button.Enabled = false;
button.Click += SendNotification;
}
}
示例9: IsGPSProviderEnabled
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//Check if GPS Enabled
public static bool IsGPSProviderEnabled(LocationManager pLocMgr)
{
if (pLocMgr.IsProviderEnabled(LocationManager.GpsProvider))
{
return true;
}
else
{
return false;
}
}
示例10: InitializeLocationManager
void InitializeLocationManager()
{
locMgr = GetSystemService (Context.LocationService) as LocationManager;
if (locMgr.AllProviders.Contains (LocationManager.NetworkProvider)
&& locMgr.IsProviderEnabled (LocationManager.NetworkProvider)) {
locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 0, 0, this);
} else {
MApplication.getInstance().longitude = 0;
MApplication.getInstance().latitude = 0;
}
}
示例11: GeolocationContinuousListener
public GeolocationContinuousListener(LocationManager manager, TimeSpan timePeriod, IList<string> providers)
{
this.manager = manager;
this.timePeriod = timePeriod;
this.providers = providers;
foreach (string p in providers)
{
if (manager.IsProviderEnabled(p))
this.activeProviders.Add(p);
}
}
示例12: OnResume
protected override void OnResume()
{
base.OnResume ();
locMgr = GetSystemService (Context.LocationService) as LocationManager;
if (locMgr.AllProviders.Contains (LocationManager.NetworkProvider)
&& locMgr.IsProviderEnabled (LocationManager.NetworkProvider)) {
locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 2000, 1, this);
} else {
Toast.MakeText (this, "The Network Provider does not exist or is not enabled!", ToastLength.Long).Show ();
}
}
示例13: StartService
public void StartService()
{
_locMan = Application.Context.GetSystemService (Context.LocationService) as LocationManager;
if (_locMan.GetProvider (LocationManager.GpsProvider) != null && _locMan.IsProviderEnabled (LocationManager.GpsProvider))
{
_pi = PendingIntent.GetBroadcast(Application.Context, 0, new Intent(), PendingIntentFlags.UpdateCurrent);
_locMan.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 5, _pi);
_locMan.GetLastKnownLocation (LocationManager.GpsProvider);
}
else
throw new GPSNotEnabledException (Const.NO_GPS_ERROR_MESSAGE);
}
示例14: GeolocationContinuousListener
/// <summary>
/// Initializes a new instance of the <see cref="GeolocationContinuousListener" /> class.
/// </summary>
/// <param name="manager">The manager.</param>
/// <param name="timePeriod">The time period.</param>
/// <param name="providers">The providers.</param>
public GeolocationContinuousListener(LocationManager manager, TimeSpan timePeriod, IList<string> providers)
{
_manager = manager;
_timePeriod = timePeriod;
_providers = providers;
foreach (var p in providers)
{
if (manager.IsProviderEnabled(p))
{
_activeProviders.Add(p);
}
}
}
示例15: OnStart
public override void OnStart (Android.Content.Intent intent, int startId)
{
base.OnStart (intent, startId);
DBRepository dbr = new DBRepository ();
userAndsoft = dbr.getUserAndsoft ();
userTransics = dbr.getUserTransics ();
var t = DateTime.Now.ToString("dd_MM_yy");
string dir_log = (Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads)).ToString();
ISharedPreferences pref = Application.Context.GetSharedPreferences("AppInfo", FileCreationMode.Private);
string log = pref.GetString("Log", String.Empty);
//GetTelId
TelephonyManager tel = (TelephonyManager)this.GetSystemService(Context.TelephonyService);
var telId = tel.DeviceId;
//Si il n'y a pas de shared pref
if (log == String.Empty){
log_file = Path.Combine (dir_log, t+"_"+telId+"_log.txt");
ISharedPreferencesEditor edit = pref.Edit();
edit.PutString("Log",log_file);
edit.Apply();
}else{
//il y a des shared pref
log_file = pref.GetString("Log", String.Empty);
if (((File.GetCreationTime(log_file)).CompareTo(DateTime.Now)) > 3) {
File.Delete(log_file);
log_file = Path.Combine (dir_log, t+"_"+telId+"_log.txt");
ISharedPreferencesEditor edit = pref.Edit();
edit.PutString("Log",log_file);
edit.Apply();
log_file = pref.GetString("Log", String.Empty);
}
}
File.AppendAllText(log_file,"[SERVICE] Service Onstart call "+DateTime.Now.ToString("t")+"\n");
DoStuff ();
// initialize location manager
locMgr = GetSystemService (Context.LocationService) as LocationManager;
if (locMgr.AllProviders.Contains (LocationManager.NetworkProvider)
&& locMgr.IsProviderEnabled (LocationManager.NetworkProvider)) {
locMgr.RequestLocationUpdates (LocationManager.NetworkProvider, 2000, 1, this);
File.AppendAllText(log_file,"[GPS] Lancer le"+DateTime.Now.ToString("t")+"\n");
} else {
File.AppendAllText(log_file,"[GPS] Le GPS est désactiver"+DateTime.Now.ToString("t")+"\n");
}
}