'How do I make it so when the user returns after enabling location permission in their settings the app will automatically do getlocationpermission()

    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 wont 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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source