zoontek / react-native-permissions

An unified permissions API for React Native on iOS, Android and Windows.
MIT License
4.08k stars 831 forks source link

Android - App crashes when I change permission from settings #307

Closed HugoLiconV closed 5 years ago

HugoLiconV commented 5 years ago

Describe your environment

How to repeat issue and an example

I request for permissions for the location and I authorized it. But, then with the app open, I go to setting and I denied the permission and the app crash. I read in the Troubleshooting that that's normal in IOs, but I wanna know if that's something normal in Android

Solution

Do you know what needs to be done to address this issue? Ideally, provide a pull request with a fix.

mikehardy commented 5 years ago

This is standard android behavior. If you revoke permissions from an app, the system kills the app. Immediately. There is no workaround, it is system behavior.

To quickly address the opposite scenario - you will not receive any notification at all if the user uses the system settings to grant permission while your app is running.

HugoLiconV commented 5 years ago

@mikehardy Thanks, I just wanted to be sure that that was the expected behavior

Pat-Gekoski commented 4 years ago

You can check to see if a specific permission has been granted using the AppState API. For example, using Expo Location you can write something like this:

import {AppState} from "react-native";

const [appState, setAppState] = useState(AppState.currentState);

const checkWhenAppStateChanges = (nextAppState) => {
        if (appState.match(/inactive|background/) && nextAppState === "active") {
            checkForPermission();
        }
        setAppState(nextAppState)
    }

const checkForPermission = async () => {
     const permission = await getPermissionAsync();
     return permission.status === 'granted';
}
mikehardy commented 4 years ago

This is true but it should be noted that many (most?) times when permission changes from the system preferences in Android, the system kills and restarts your app

Pat-Gekoski commented 4 years ago

I came to this page with the same issue. While my app was running, if I revoked the permission for location, the app would re-start. If I did it a second time, the app would terminate without restarting. I thought it was a bug in my code or in React. Thanks for the info 👍🏻

deepaksinghcb commented 2 years ago

This is standard android behavior. If you revoke permissions from an app, the system kills the app. Immediately. There is no workaround, it is system behavior.

To quickly address the opposite scenario - you will not receive any notification at all if the user uses the system settings to grant permission while your app is running.

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

mikehardy commented 2 years ago

@deepaksinghcb great report! If you can figure out how they do it (perhaps storing dehydrated local state / nav position, restoring it on restart?) then everyone here would know how to do it as well.

My statements above are facts though as far as I know. You can poll permissions perhaps - at important parts of your app - to get grants but there is no "I was granted a permission" listener you can set. And revokes will kill your app. That is actually a system behavior, not app-specific

KiranSayone commented 11 months ago

Is there any method to overcome this issue, .ie., keeping the app open even when the permission is denied from settings. As @deepaksinghcb mentioned apps like uber is handling it somehow. So does anyone know how to handle this scenario. The problem is that when this happens first time the app just restarts and when this happens next time onwards the andorid system starts to show a warning dialogue box telling that this app is crashing many time.

vishaljnimblechapps commented 7 months ago

Does anyone have a solution for this problem?