[英]How do I make it so the app will automatically call getlocationpermission after the user returns from enabling location permission automatically
public void statusCheck() {
final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
Intent intent = new Intent(MainActivity.this, NewActivity.class);
buildAlertMessageNoGps();
}
while(manager.isProviderEnabled(LocationManager.GPS_PROVIDER) && i<2)
{
getLocationPermission();
i++;
}
}
这是我的代码。 现在,如果未启用位置权限,将会出现一个警告对话框,将用户带到他们的设置以启用它。 但是,当他们返回时, getlocationpermission()
未运行,因此该应用程序将无法运行。 如何使应用程序在用户启用位置权限返回后自动调用getlocationpermission()
? 为什么我的代码不起作用,为什么在用户manager.isProviderEnabled(LocationManager.GPS_PROVIDER)
为真后它不调用getLocationpermission
。
我认为连接 GPS 需要更多时间,请尝试使用 boolean。
例子:
while(!GpsWorking)
{
getLocationPermission();
}
publick void getLocationPermission()
{
//if gps working
GpsWorking = true;
}
简单来说,您将调用该方法,直到获得位置
收到位置后, while(!GpsWorking)将退出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.