Reack本机版本。在地理位置权限被拒绝的更高版本android设备中发生apk崩溃错误

Reack本机版本。在地理位置权限被拒绝的更高版本android设备中发生apk崩溃错误,android,react-native,react-native-android,Android,React Native,React Native Android,我创建了一个简单的应用程序,它有一个登录页面,当用户单击登录按钮时,它会导航到另一个页面。每当我使用react native run android运行我的应用程序时,它都可以正常工作。但每当我在更高版本的Android设备中运行.apk文件时,应用程序就会崩溃(在Android 5和6中运行良好) package.json { "name": "awsUpload", "version": "0.0.1", "private": true, "scripts":

我创建了一个简单的应用程序,它有一个登录页面,当用户单击登录按钮时,它会导航到另一个页面。每当我使用react native run android运行我的应用程序时,它都可以正常工作。但每当我在更高版本的Android设备中运行.apk文件时,应用程序就会崩溃(在Android 5和6中运行良好)

package.json

{
    "name": "awsUpload",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
    },
    "dependencies": {
        "aws-sdk": "^2.395.0",
        "link": "^0.1.5",
        "react": "16.6.3",
        "react-native": "^0.58.3",
        "react-native-aws3": "0.0.8",
        "react-native-device-info": "^0.26.2",
        "react-native-file-upload": "^1.0.4",
        "react-native-image-picker": "^0.28.0",
        "react-native-material-dropdown": "^0.11.1",
        "react-native-router-flux": "^4.0.6",
        "uniqid": "^5.0.3"
    },
    "devDependencies": {
        "babel-core": "7.0.0-bridge.0",
        "babel-jest": "24.0.0",
        "jest": "24.0.0",
        "metro-react-native-babel-preset": "0.51.1",
        "react-test-renderer": "16.6.3"
    },
    "jest": {
        "preset": "react-native"
    }
}
我使用下面的代码来获取地理位置。据我所知,由于受到保护,在更高版本的Android设备中获取地理位置已经存在问题,并且在堆栈溢出中有一个解决方案。但我不知道如何使用它

我的密码是

import React, {Component} from 'react';
import {Text, View} from 'react-native';

export default class App extends Component<Props> {

       constructor(props) {
        super(props);
        this.state = {

          currentLongitude: 'unknown',//Initial Longitude
          currentLatitude: 'unknown',//Initial Latitude

        }
      }
    componentDidMount = () => {
        navigator.geolocation.getCurrentPosition(
          //Will give you the current location
           (position) => {
              const currentLongitude = JSON.stringify(position.coords.longitude);
              //getting the Longitude from the location json
              const currentLatitude = JSON.stringify(position.coords.latitude);
              //getting the Latitude from the location json
              this.setState({ currentLongitude:currentLongitude });
              //Setting state Longitude to re re-render the Longitude Text
              this.setState({ currentLatitude:currentLatitude });
              //Setting state Latitude to re re-render the Longitude Text
           },
           (error) => alert(error.message),
           { enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
        );
        this.watchID = navigator.geolocation.watchPosition((position) => {
          //Will give you the location on location change
            console.log(position);
            const currentLongitude = JSON.stringify(position.coords.longitude);
            //getting the Longitude from the location json
            const currentLatitude = JSON.stringify(position.coords.latitude);
            //getting the Latitude from the location json
           this.setState({ currentLongitude:currentLongitude });
           //Setting state Longitude to re re-render the Longitude Text
           this.setState({ currentLatitude:currentLatitude });
           //Setting state Latitude to re re-render the Longitude Text
        });
    }
   componentWillUnmount = () => {
      navigator.geolocation.clearWatch(this.watchID);

   }
    render() {
      return (
                <View>
                   <Text>Longitude: {this.state.currentLongitude}</Text>
                   <Text>Latitude: {this.state.currentLatitude}</Text>

                   {this.state.error ? <Text>Error: {this.state.error}</Text> : null}
                </View> 
          );
        }
      }

错误是完全清楚的,您需要获得访问该位置的权限

有两种类型的权限:

1-只需将权限添加到
manifest.xml

2-用户本人必须接受该权限的权限。(这些权限通常显示在
对话框中,并要求用户授予应用程序访问权限…)

位置权限是第二种类型。因此,将该权限添加到
Manifest.xml
不会起任何作用

您可以在中检查权限列表

下面的链接解释了请求用户权限的方法:


尝试在更高版本的emulator中运行,并查看日志cat logsI发现,my.apk正在崩溃,因为我正在获取用户位置。如何解决这个问题?你提供的信息还不够!请给出一些代码或StackTrace,您是否使用android studio进行调试?我需要添加那个权限MainActivity.java文件。我不知道如何添加它。我编辑了我的asnwer。如果您使用react native进行编码,则无需在
MainActivity.java
中编写代码,我希望它能帮助您
https://stackoverflow.com/questions/33865445/gps-location-provider-requires-access-fine-location-permission-for-android-6-0/33866959