React Native PermissionsAndroid - 尝试使用权限API,但主机Activity未实现PermissionAwareActivity

时间:2017-06-05 20:02:08

标签: reactjs react-native react-native-android

我正在尝试使用react-native中的PermissionsAndroid在运行时期间在Android M(API 23)上请求蓝牙权限。

我收到以下错误Tried to use permissions API but the host Activity doesn't implement PermissionAwareActivity。关于如何解决这个错误的任何想法?

我的代码是

Bluetooth.js:

componentWillMount() {
    ...
    this.checkAndGrantPermissions();
}
async checkAndGrantPermissions() {
    const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.LOCATION,
      {
        title: 'Cool Photo App Camera Permission',
        message: 'Cool Photo App needs access to your camera ' +
                   'so you can take awesome pictures.'
      });
}

我也试过这样做:

async checkAndGrantPermissions() {
    await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.LOCATION,
        {
        title: 'Cool Photo App Camera Permission',
        message: 'Cool Photo App needs access to your camera ' +
        'so you can take awesome pictures.'
        }
    ).then(() => {

    }).catch((err) => {
        console.log(err);
    });
}

但后来我收到了这个错误:

{"framesToPop":1,"code":"E_INVALID_ACTIVITY","line":8001,"column":29,"sourceURL":"http://packager.xb-kvy.darkwata.pentaheliosapp.exp.direct:80/main.bundle?platform=android&dev=true&hot=false&minify=false"}

0 个答案:

没有答案