Home  >  Q&A  >  body text

javascript - I was troubled by the problem late at night and asked for a solution. The problem of rn's API PermissionsAndroidd

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  PermissionsAndroid,
  Platform
} from 'react-native';


async function requestCameraPermission() {
  try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.CAMERA,
      {
        'title': 'Cool Photo App Camera Permission',
        'message': 'Cool Photo App needs access to your camera ' +
                   'so you can take awesome pictures.'
      }
    )
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log("You can use the camera")
    } else {
      console.log("Camera permission denied")
    }
  } catch (err) {
    console.warn(err)
  }
}
requestCameraPermission()

if(Platform.Version === 23){
  console.log('Running on Lollipop!');
}

export default class myproject2 extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.android.js
        </Text>
        <Text style={styles.instructions}>
          Double tap R on your keyboard to reload,{'\n'}
          Shake or press menu button for dev menu
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('myproject2', () => myproject2);

The problem is this. I want to obtain a certain permission. I have read the API on the official website and checked some information. I have configured it in AndroidManifest.xml. Both the mobile phone and the emulator are Android 6.0. The version of the SDK is 23 is no problem, but when I tested it, I found that when I called it, it directly returned true and displayed You can use the camera in the browser console, but there was no response in the APP. Why is this? I'm very troubled. I'm very confused. I want to ask, is this how you wrote it, or do you need to configure something else?

大家讲道理大家讲道理2642 days ago655

reply all(1)I'll reply

  • 漂亮男人

    漂亮男人2017-06-28 09:24:43

    It seems that permissions are automatically granted. You can remove the permissions in settings and see again

    reply
    0
  • Cancelreply