I have a developer's options pane inside my app, where a developer can input test MAC address of the device. The question is how to validate it correctly? Does Android have some methods out of the box to do this?
One way to represent them is to form six pairs of the characters separated with a hyphen (-) or colon(:). For example, 01-23-45-67-89-AB is a valid MAC address. Another way to represent them is to form three groups of four hexadecimal digits separated by dots(.). For example, 0123.4567.
A MAC address is a 48-bit hexadecimal address. It's usually six sets of two digits or characters, separated by colons. An example MAC address would be 00:00:5e:00:53:af. Many network card and other hardware manufacturers use a unique sequence at the beginning of their products' MAC addresses.
Bluetooth devices shows as MAC addresses, and only after a couple refreshes only SOME of them have names.
Thank everybody for your help. I found the solution. BluetoothAdapter.checkBluetoothAddress(String)
validates the MAC address. It checks if MAC matches the pattern given here, if length equals 17 chars, if all letters are uppercase and whether all chars are hex chars.
MAC addresses have this format:
String formatMAC = "%02X:%02X:%02X:%02X:%02X:%02X";
So you can check that a device's MAC address matches this format using String's matches()
method:
public boolean matches(String regex) {
return Pattern.matches(regex, this);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With