[英]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++;
}
}
This is my code.这是我的代码。 Right now if location permission is not enabled, there will be an alert dialog that will take the user to their settings to enable it.
现在,如果未启用位置权限,将会出现一个警告对话框,将用户带到他们的设置以启用它。 However, when they return
getlocationpermission()
is not run so the app won't work.但是,当他们返回时,
getlocationpermission()
未运行,因此该应用程序将无法运行。 How do I make it so that the app will automatically call getlocationpermission()
after the user returns from enabling location permission?如何使应用程序在用户启用位置权限返回后自动调用
getlocationpermission()
? Why is my code not working, why will it not call getLocationpermission
after user manager.isProviderEnabled(LocationManager.GPS_PROVIDER)
is true.为什么我的代码不起作用,为什么在用户
manager.isProviderEnabled(LocationManager.GPS_PROVIDER)
为真后它不调用getLocationpermission
。
i think it need more time to connect GPS, try use boolean.我认为连接 GPS 需要更多时间,请尝试使用 boolean。
Exemple:例子:
while(!GpsWorking)
{
getLocationPermission();
}
publick void getLocationPermission()
{
//if gps working
GpsWorking = true;
}
in simple terms you will call the method until you get the location简单来说,您将调用该方法,直到获得位置
once the location is received, the while(!GpsWorking) will exit收到位置后, while(!GpsWorking)将退出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.