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. How do I make it so that the app will automatically call getlocationpermission()
after the user returns from enabling location permission? Why is my code not working, why will it not call getLocationpermission
after user manager.isProviderEnabled(LocationManager.GPS_PROVIDER)
is true.
i think it need more time to connect GPS, try use 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.