搜索

首页  >  问答  >  正文

javascript - 深夜被问题困扰求解惑,rn的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);

问题是这样的,我想获取某个权限,看过官网的API也查了一些资料我在AndroidManifest.xml里面是配置过的,手机和模拟器都是安卓6.0的,SDK的版本是23都是没有问题,但是我在测试的时候就发现,当我调用了,他是直接返回true的,显示的是You can use the camera,在浏览器的控制台里,但是APP里没有任何反应这是为什么呢?我非常的困扰。我非常的不解,我想问下,大家是这么写的,还是说还要配置其他的什么吗?

大家讲道理大家讲道理2695 天前694

全部回复(1)我来回复

  • 漂亮男人

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

    好像是自动赋予权限的,你再设置里面把权限去掉再看呢

    回复
    0
  • 取消回复