1
如何确定定位服务开/关在firemonkey应用程序中?确定定位服务是否打开
我知道这篇文章:How to check if network is available on Android (Delphi XE5)。我不确定这可以帮助我检测位置服务是打开还是关闭。
如何确定定位服务开/关在firemonkey应用程序中?确定定位服务是否打开
我知道这篇文章:How to check if network is available on Android (Delphi XE5)。我不确定这可以帮助我检测位置服务是打开还是关闭。
要确定位置服务是开/关,则必须检查GPS和网络定位服务被激活,为此,你必须使用LocationManager
类的isProviderEnabled
方法,在Delphi这个类是在Androidapi.JNI.Location
定义单元。
检查该样本
uses
Androidapi.Helpers,
Androidapi.JNI.Location,
Androidapi.JNIBridge,
FMX.Helpers.Android,
Androidapi.JNI.GraphicsContentViewText;
{$R *.fmx}
procedure TForm1.Button1Click(Sender: TObject);
var
locationManager : JLocationManager;
begin
locationManager := TJLocationManager.Wrap(
((SharedActivity.getSystemService(TJContext.JavaClass.LOCATION_SERVICE))
as ILocalObject).GetObjectID);
if locationManager.isProviderEnabled(TJLocationManager.JavaClass.GPS_PROVIDER) then
; //do something
if locationManager.isProviderEnabled(TJLocationManager.JavaClass.NETWORK_PROVIDER) then
; //do something else
end;