Advertise given message using BLE
For installing this package from GitHub Package registry read the steps here
Authenticate to GitHub package registry using below command. Use Token
$ npm login --scope=@teamdotworld --registry=https://npm.pkg.github.com
> Username: USERNAME
> Password: TOKEN
> Email: PUBLIC-EMAIL-ADDRESS
Now install the package. See the releases and use latest version
npm install @teamdotworld/rn-ble-advertiser@3.0.5
Add this to your AndroidManifest.xml inside application tag
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application ...>
...
<service android:name="dev.dotworld.ble.bluetooth.gatt.GattBackgroundService" />
<receiver
android:name="dev.dotworld.ble.receivers.RestartReceiver"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
...
</application>
Add this to Info.plist file for permission
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location permission to verify if you are scanning in correct location</string>
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Need bluetooth permission for this app to function properly</string>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
</array>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>bluetooth-le</string>
</array>
import { Platform } from 'react-native';
import ReactNativeBleAdvertiser from '@teamdotworld/rn-ble-advertiser';
// Use a switch to turn it on or off
ReactNativeBleAdvertiser.initializeBle(); // Initalize the service
ReactNativeBleAdvertiser.setData('1234'); // set the data
setTimeout(() => {
// start the service after setting data. Restart if the data is changed after starting
ReactNativeBleAdvertiser.startBroadcast();
setTimeout(() => {
// start the service after setting data. Restart if the data is changed after starting
ReactNativeBleAdvertiser.stopBroadcast();
}, 4000);
}, 4000);
Known issues
- Module currenly supports minimum android sdk of 22. Change your minSdkVersion in android/build.gradle to 22
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT