question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PermissionsAndroid.request never resolves

See original GitHub issue

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes.

Environment

Environment: OS: macOS Sierra 10.12.6 Node: 9.4.0 Yarn: 1.3.2 npm: 5.6.0 Watchman: 4.9.0 Xcode: Xcode 9.2 Build version 9C40b Android Studio: 3.0 AI-171.4443003

Packages: (wanted => installed) react: 16.2.0 => 16.2.0 react-native: 0.53.0 => 0.53.0

Edit: according to @MateRyze, it still happens on react-native 0.55.4.

Target Platform: Android 6.0.1

Steps to Reproduce

We have a Camera component and it should check for the Camera permission before mounting.

In my app’s AndroidManifest.xml I have the line, along with many other permissions:

<uses-permission android:name="android.permission.CAMERA"/>

In our component’s componentDidMount() we call a function that should return true if we have permission and false if we do not have, here is the relevant snippet of the function:

if (Platform.OS === 'android') {
const isGranted = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.CAMERA);
      if (isGranted) {
        return true;
      }
      try {
        console.log('before request');
        const granted = await PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.CAMERA,
          {
            title: 'Dialog Title',
            message: 'Dialog Message',
          }
        );
        console.log('after request');
        return granted === PermissionsAndroid.RESULTS.GRANTED;
      } catch (err) {
        console.log('error');
        console.log(err);
      }
}

Expected Behavior

A dialog with my title and message should appear, if the user clicks on “Allow”, the promise should resolve and my component should render as expected.

Actual Behavior

A dialog with a different message and title appears. I click on “Allow” and the promise is never resolved or rejected.

In my logs, only the “before request” log appears. Neitherconsole.log('after request') or console.log('error') is logged, so I presume the code is stuck in the await.

I am following this doc.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:14
  • Comments:40 (1 by maintainers)

github_iconTop GitHub Comments

16reactions
react-native-botcommented, May 15, 2018

Thanks for posting this! It looks like your issue may refer to an older version of React Native. Can you reproduce the issue on the latest release, v0.55?

Thank you for your contributions.

10reactions
kanekoticcommented, Aug 6, 2018

After debugging and trying a few cases. If the request is called with the rationale parameter as undefined the request permission works correctly. When the rationale object is provided permissions are not requested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native - Difference between PermissionsAndroid.request ...
Returns a promise resolving to a boolean value as to whether the specified permissions has been granted. PermissionsAndroid.request.
Read more >
PermissionsAndroid - React Native
PermissionsAndroid provides access to Android M's new permissions model ... to true and request should always resolve to PermissionsAndroid.
Read more >
Android: Request Permissions do not show dialog boxes
Android: Request Permissions do not show dialog boxes. The process to merge three manifest files, lowest priority (left) into highest priority (right) ...
Read more >
react-native-permissions - npm
Permission checks and requests resolve into one of these statuses: ... Android will never return blocked after a check , you have to...
Read more >
Managing app permissions in React Native - LogRocket Blog
Learn how to ask your users for permission to record and capture video, ... cuts through the noise to proactively resolve issues in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found