I am currently developing an Ionic 3 application where I need to get the phone's Bluetooth MAC address (or something that would identify the device inside a Bluetooth network) on an Android device and I have been trying to obtain the MAC address (or UUID etc.) using the Uid
native plugin for Ionic, along with the native plugin for AndroidPermissions
. I am currently using the method suggested at the plugins homepage https://ionicframework.com/docs/native/uid/
This is the code for getting the MAC address of the device:
async getMAC() {
const { hasPermission } = await this.androidPermissions.checkPermission(
this.androidPermissions.PERMISSION.READ_PHONE_STATE
);
if (!hasPermission) {
const result = await this.androidPermissions.requestPermission(
this.androidPermissions.PERMISSION.READ_PHONE_STATE
);
if (!result.hasPermission) {
throw new Error('Permissions required');
}
return;
}
return this.uidNative.MAC;
}
I have also added the READ_PHONE_STATE
permission to my AndroidManifest.xml
and setup the according providers for Ionic. My phone requests for permission normally.
My problem
After requesting for permission the above Promise is resolved successfully but it returns null
and I cannot figure out why this happens
- Is there any workaround for this? Did anyone had similar problems?
- Is there another way to get the MAC address of the android device and passing it to the Ionic Application?
Thanks in advance