react-native-geolocation icon indicating copy to clipboard operation
react-native-geolocation copied to clipboard

Android App crashes when I change Location permission from settings react native

Open amir-ibrahim opened this issue 2 years ago • 3 comments

I have a problem with React Native Permissions on Android. If the user changes Location Permission from the Device setting while the app is running the app crashes right after that.

I search on the internet for a while I found someone who said this is a normal android behavior to restart the app after permissions changes but there is some app out there that manages to avoid this.

did anyone out there know how to handle this?

ask the user to allow Location permission code:

useEffect(() => {
    Geolocation.getCurrentPosition(
      ({coords}) => {
        let position = {
          latitude: coords.latitude,
          longitude: coords.longitude,
          latitudeDelta: latitudeDelta,
          longitudeDelta: longitudeDelta,
        };
        setLocation(position);
      },
      error => {
        if (enabled && Platform.OS === 'android') {
          return false;
        } else {
          Alert.alert(t('Access Denied'), error.message);
        }
      },
      {
        enableHighAccuracy: false,
        timeout: 10000,
        maximumAge: 0,
      },
    );
  }, []);

amir-ibrahim avatar Nov 28 '22 10:11 amir-ibrahim

Do you have a crash stack trace? I'll take a look on that

michalchudziak avatar Nov 30 '22 12:11 michalchudziak

I have a problem with my app when revoking permissions from settings, the system kills the app. Immediately. while the app is running

Apps like Uber/Snapchat are able to manage this scenario. I have checked some other apps as well which are able to check dynamic changes from settings.

did anyone out there know how to handle this?

const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, { title: 'Location Access Required', message: 'This App needs to Access your location', }, ); if (granted) { console.log('granted ==>', granted); } else { console.log('denied'); }

Mujahid122418 avatar Dec 07 '22 09:12 Mujahid122418

This will help https://www.youtube.com/watch?v=E7X9DjezSR0

BraveEvidence avatar Mar 03 '23 13:03 BraveEvidence