简体   繁体   English

Android:启用飞行模式时的LocationManager

[英]Android: LocationManager when Airplane mode on

I am testing the location part of my app with various configurations. 我正在使用各种配置测试应用程序的location部分。 In AirPlane mode I don't get any message sent to ILocationListener , good or bad, from the following LocationManager on an Android 2.2. AirPlane模式下,我不会从Android 2.2上的以下LocationManager发送任何消息到ILocationListener ,无论好坏。 In this case the bestProvider is "network". 在这种情况下,bestProvider是“网络”。

How can I determine if there simply is no way to get a location so that I can inform the user? 我如何确定是否根本无法获取位置以便通知用户? When there is a network or GPS it all works fine. 有网络或GPS时,一切正常。

The code I use ( Mono for Android C#) is: 我使用的代码( 适用于Android C#的Mono )为:

            var cr = new Criteria ();
            cr.Accuracy = Accuracy.Coarse;
            cr.PowerRequirement = Power.Low;
            cr.AltitudeRequired = false;
            cr.BearingRequired = false;
            cr.SpeedRequired = false;
            cr.CostAllowed = true;
            string serviceString = Context.LocationService;
            locationManager = (LocationManager)GetSystemService (serviceString);
            var bestProvider = locationManager.GetBestProvider (cr, false);
            locationManager.RequestLocationUpdates (bestProvider, 5000, 500f, this);

as this is your Location Listener you can see the state in onProviderEnabled (String provider) , onProviderDisabled (String provider) or onStatusChanged (String provider, int status, Bundle extras) . 因为this是您的位置侦听器,所以您可以在onProviderEnabled (String provider)onProviderDisabled (String provider)onStatusChanged (String provider, int status, Bundle extras)查看状态。 Read this API for further Information, what each state means 阅读此API以获得更多信息,每种状态意味着什么

You can not use any kind of Communication like GPS,GPRS in AirPlane Mode. 您无法在AirPlane模式下使用任何类型的通信,例如GPS,GPRS。 Airplane mode is a setting available on most cell phones, smartphones and other electronic devices that, when engaged, suspends many of the device's signal transmitting functions – thereby disabling the device's capacity to place or receive calls or text messages – while still permitting use of other functions that do not require signal transmission (eg, games, built-in camera, MP3 player). 飞行模式是大多数手机,智能手机和其他电子设备上可用的设置,启用后,该模式将暂停设备的许多信号传输功能,从而使设备无法拨打或接听电话或短信,同时仍允许使用其他功能不需要信号传输的功能(例如游戏,内置摄像头,MP3播放器)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM