/** * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format * @flow */ 'use strict'; const React = require('react'); const ReactNative = require('react-native'); const { PermissionsAndroid, Picker, StyleSheet, Text, TouchableWithoutFeedback, View, } = ReactNative; const Item = Picker.Item; exports.displayName = (undefined: ?string); exports.framework = 'React'; exports.title = 'PermissionsAndroid'; exports.description = 'Permissions example for API 23+.'; class PermissionsExample extends React.Component<{}, $FlowFixMeState> { state = { permission: PermissionsAndroid.PERMISSIONS.CAMERA, hasPermission: 'Not Checked', }; render() { return ( Permission Name: Check Permission Permission Status: {this.state.hasPermission} Request Permission ); } _onSelectPermission = (permission: string) => { this.setState({ permission: permission, }); }; _checkPermission = async () => { let result = await PermissionsAndroid.check(this.state.permission); this.setState({ hasPermission: (result ? 'Granted' : 'Revoked') + ' for ' + this.state.permission, }); }; _requestPermission = async () => { let result = await PermissionsAndroid.request(this.state.permission, { title: 'Permission Explanation', message: 'The app needs the following permission ' + this.state.permission + ' because of reasons. Please approve.', }); this.setState({ hasPermission: result + ' for ' + this.state.permission, }); }; } exports.examples = [ { title: 'Permissions Example', description: 'Short example of how to use the runtime permissions API introduced in Android M.', render: () => , }, ]; var styles = StyleSheet.create({ container: { flex: 1, backgroundColor: 'white', }, singleLine: { fontSize: 16, padding: 4, }, text: { margin: 10, }, touchable: { color: '#007AFF', }, picker: { flex: 1, }, });