connectivity-samples
connectivity-samples copied to clipboard
BleAdvertisements sample code need be updated for Android 8 and above
For people who need run BleAdvertisements sample on Android 8 or above, below changes are necessary:
- add android.permission.ACCESS_FINE_LOCATION to manifest, and ask run time permission for it.
- add android.permission.FOREGROUND_SERVICE to manifest, otherwise app would crash once it starts advertising service.
- Create a notification channel for the advertising service, otherwise startForground() will complain bad notification and crash the app.
Yo also have to change Notification.Builder(Context context) to Notification.Builder(Context context, String string)
We have provided a Kotlin version that is up to date: https://github.com/android/connectivity-samples/tree/main/BluetoothAdvertisementsKotlin