don / cordova-plugin-ble-peripheral

Apache Cordova plugin for implementing BLE (Bluetooth Low Energy) peripherals.
Other
31 stars 30 forks source link

Android 12 #21

Open markarupert opened 1 year ago

markarupert commented 1 year ago

Has anyone gotten this working with Android 12. I am getting a permission error for BLUETOOTH_ADVERTISE. I put it in the AndroidManifest. and have tried enabling with cordova.plugins.diagnostic.requestBluetoothAuthorization.

This is the error I am getting.

Possibly unhandled Error: Need android.permission.BLUETOOTH_ADVERTISE permission for AttributionSource { uid = 11308, packageName = biz.geowiz.mobile, attributionTag = null, token = android.os.BinderProxy@288b4e9, next = null }: GattService startAdvertisingSet

ragcsalo commented 6 months ago

Use the permissions plugin, and check the permission programmatically:

  permissions.checkPermission('android.permission.BLUETOOTH_ADVERTISE', function( status ){
    if (!status.hasPermission ) {
      console.log('Requesting BLUETOOTH_ADVERTISE permission...');
      permissions.requestPermission('android.permission.BLUETOOTH_ADVERTISE', function() {
        console.log('BLUETOOTH_ADVERTISE granted by user :-)');
      }, function() {
        console.log('BLUETOOTH_ADVERTISE denied :-(');
      });
    }
    else {
      console.log('BLUETOOTH_ADVERTISE already granted :-)');
    }
  });

https://github.com/NeoLSN/cordova-plugin-android-permissions