I have added react-native-ble-plx in my app. I have also linked it using react native link cmd. I have follwed all required step provided in the lib documents. But Its not working. I never ask for user permission and it gives error Deivce is not authorized to use BluetoothLE. Here is my code for
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smartdeviceiot">
<uses-feature android:name="android.hardware.bluetooth_le" android:required="true"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission-sdk-23 android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="23"/>
DeviceSearch.js
import colors from '../constants/colors'; import images from '../constants/images'; import { Button, Icon, Text, Container, Header, Left, Body, Title, Right } from 'native-base'; import { HomeStyle } from './styles/home'; import { BleManager } from'react-native-ble-plx' class DevicesSearch extends Component { static navigationOptions = { title: 'DevicesSearch' }; constructor(props) { super(props); const manager = new BleManager(); this.state = { }; } componentWillMount() { } render() { return ( >this.props.navigation.navigate("DrawerOpen")}> DevicesSearch Search Devices ); } scanAndConnect = () => { alert('asd') console.log('cal'); this.manager.startDeviceScan(null, null, (error, device) => { this.info("Scanning..."); console.log(device);
if (error) { this.error(error.message); return } if (device.name ==='MyDevice') { this.info("Connecting to Tappy"); this.manager.stopDeviceScan(); device.connect() .then((device) => { this.info("Discovering services and characteristics"); return device.discoverAllServicesAndCharacteristics() }) .then((device) => { this.info(device.id); device.writeCharacteristicWithResponseForService('12ab', '34cd',
'aGVsbG8gbWlzcyB0YXBweQ==') .then((characteristic) => { this.info(characteristic.value); return }) }) .catch((error) => { this.error(error.message) }) } }); } } function mapStateToProps(state) { //pass the providers return { } } /* Map Actions to Props */ function mapDispatchToProps(dispatch) >{ return { actions: bindActionCreators({ }, dispatch) }; } export default connect( mapStateToProps, mapDispatchToProps )(DevicesSearch);
if my bluetooth is turn off the code console.log me that bluetooth is off, but when its on it log me me that device is not auth to use bluetooth. I have also tired to use AndroidPermission lib but no success. it doesnt take permission from user