import { Alert, Platform } from 'react-native';
import { NativeEventEmitter, NativeModules } from 'react-native';
import update from 'immutability-helper';
import BLEAdvertiser from 'react-native-ble-advertiser'
import UUIDGenerator from 'react-native-uuid-generator';
import { PermissionsAndroid } from 'react-native';
import BTScanner from './screen/BTScanner';
import BTBroadcast from './screen/BTBroadcast';
// Uses the Apple code to pick up iPhones
const APPLE_ID = 0x4C;
const MANUF_DATA = [0,1];
BLEAdvertiser.setCompanyId(APPLE_ID);
export async function requestLocationPermission() {
try {
if (Platform.OS === 'android') {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
'title': 'BLE Avertiser Example App',
'message': 'Example App access to your location '
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('[Permissions]', 'Location Permission granted')
} else {
console.log('[Permissions]', 'Location Permission denied')
}
}
const blueoothActive = await BLEAdvertiser.getAdapterState().then(result => {
console.log('[Bluetooth]', 'Bluetooth Status', result)
return result === "STATE_ON";
}).catch(error => {
console.log('[Bluetooth]', 'Bluetooth Not Enabled')
return false;
});
if (!blueoothActive) {
await Alert.alert(
'Example requires bluetooth to be enabled',
'Would you like to enable Bluetooth?',
[
{
text: 'Yes',
onPress: () => BLEAdvertiser.enableAdapter(),
},
{
text: 'No',
onPress: () => console.log('Do Not Enable Bluetooth Pressed'),
style: 'cancel',
},
],
)
}
this is my manifest.xml file and i have copied the code from sample app. Scanning is working but cannot broadcast need help.
import React, {Component } from 'react'; import BeaconBroadcast from './screen/BeaconBroadcast'; import {check, checkMultiple, PERMISSIONS, RESULTS} from 'react-native-permissions';
import { SafeAreaView, StyleSheet, ScrollView, View, Text, TouchableOpacity, FlatList, } from 'react-native';
import { Alert, Platform } from 'react-native'; import { NativeEventEmitter, NativeModules } from 'react-native';
import update from 'immutability-helper'; import BLEAdvertiser from 'react-native-ble-advertiser' import UUIDGenerator from 'react-native-uuid-generator'; import { PermissionsAndroid } from 'react-native'; import BTScanner from './screen/BTScanner'; import BTBroadcast from './screen/BTBroadcast';
// Uses the Apple code to pick up iPhones const APPLE_ID = 0x4C; const MANUF_DATA = [0,1];
BLEAdvertiser.setCompanyId(APPLE_ID);
export async function requestLocationPermission() { try { if (Platform.OS === 'android') { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, { 'title': 'BLE Avertiser Example App', 'message': 'Example App access to your location ' } ) if (granted === PermissionsAndroid.RESULTS.GRANTED) { console.log('[Permissions]', 'Location Permission granted') } else { console.log('[Permissions]', 'Location Permission denied') } }
} catch (err) { console.warn(err) } }
class Entry extends Component { constructor(props) { super(props); this.state = { uuid:'', isLogging: false, devicesFound:[] } }
.then((result) => { console.log('Permission result', result); }) .catch((error) => { console.log(error) });
}
const styles = StyleSheet.create({ body: { height: "100%", }, sectionContainerFlex: { flex: 1, marginTop: 12, marginBottom: 12, paddingHorizontal: 24, }, sectionContainer: { flex: 0, marginTop: 12, marginBottom: 12, paddingHorizontal: 24, }, sectionTitle: { fontSize: 24, marginBottom: 8, fontWeight: '600', textAlign: 'center' }, sectionDescription: { fontSize: 18, fontWeight: '400', textAlign: 'center', }, highlight: { fontWeight: '700', }, startLoggingButtonTouchable: { borderRadius: 12, backgroundColor: '#665eff', height: 52, alignSelf: 'center', width: 300, justifyContent: 'center', }, startLoggingButtonText: { fontSize: 14, lineHeight: 19, letterSpacing: 0, textAlign: 'center', color: '#ffffff', }, stopLoggingButtonTouchable: { borderRadius: 12, backgroundColor: '#fd4a4a', height: 52, alignSelf: 'center', width: 300, justifyContent: 'center', }, stopLoggingButtonText: { fontSize: 14, lineHeight: 19, letterSpacing: 0, textAlign: 'center', color: '#ffffff', }, listPastConnections: { width: "80%", height: 200 }, itemPastConnections: { padding: 3, fontSize: 18, fontWeight: '400', }, });
export default Entry;