Well with Google doing away with us using AdID I am once again on a search for a way to tell if my app is running on a device the user paid for or are they sharing Google Log Ins
I came across this code (Unique ID / Android 10 >)
Not being very good (well actually pretty bad) I took Erel's (thanks Erel) code Udp Broadcast Address and made it look like Crap but it does return my Wi-Fi Mac address on Android 11
The ONLY difference in the Mac Address it shows and my real Wi-Fi Mac Address is the one that is shown in this code starts with 16 and on my device and the Status Information shows it starting with a 14
Makes me wonder if I need to take off the FAKE IP 02:00:00:00:00:00 Taking that 02 off the first number would make everything exact.
Maybe someone could try this code and see what if outputs as far as what the Status Information page show.
BobVal
I came across this code (Unique ID / Android 10 >)
B4X:
public static String getMacAddr() {
StringBuilder res1 = new StringBuilder();
try {
List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
for (NetworkInterface nif : all) {
if (!nif.getName().equalsIgnoreCase("p2p0")) continue;
byte[] macBytes = nif.getHardwareAddress();
if (macBytes == null) {
continue;
}
res1 = new StringBuilder();
for (byte b : macBytes) {
res1.append(String.format("%02X:",b));
}
if (res1.length() > 0) {
res1.deleteCharAt(res1.length() - 1);
}
}
} catch (Exception ex) {
}
return res1.toString();
}
Not being very good (well actually pretty bad) I took Erel's (thanks Erel) code Udp Broadcast Address and made it look like Crap but it does return my Wi-Fi Mac address on Android 11
B4X:
Private Sub GetAddress As String
Dim niIterator As JavaObject
niIterator = niIterator.InitializeStatic("java.net.NetworkInterface").RunMethod("getNetworkInterfaces", Null)
Do While niIterator.RunMethod("hasMoreElements", Null)
Dim ni As JavaObject = niIterator.RunMethod("nextElement", Null)
Dim Name As String = ni.RunMethod("getName", Null)
Log("GetAddress - Name:" &Name)
If Name.EqualsIgnoreCase("p2p0") = False Then
Continue
End If
Dim MacBytes() As Byte = ni.RunMethod("getHardwareAddress", Null)
If MacBytes.Length = 0 Then
Continue
End If
Dim BC As ByteConverter
Dim MacAddr As String
For Each B As Byte In MacBytes
MacAddr = MacAddr &BC.HexFromBytes(Array As Byte(B)) &":"
Next
If MacAddr.Length > 0 Then
MacAddr = MacAddr.SubString2(0, MacAddr.Length-1)
Log($"MacAddr[${MacAddr}]"$)
If MacAddr.Length > 0 Then
Return MacAddr
End If
End If
Loop
Return ""
End Sub
The ONLY difference in the Mac Address it shows and my real Wi-Fi Mac Address is the one that is shown in this code starts with 16 and on my device and the Status Information shows it starting with a 14
Makes me wonder if I need to take off the FAKE IP 02:00:00:00:00:00 Taking that 02 off the first number would make everything exact.
Maybe someone could try this code and see what if outputs as far as what the Status Information page show.
BobVal