1

I need to restrict app subscription to certain number of devices per user. For this I was trying to get unique id for android phone ( Hardware ). I found below options but all of them has certain problems. Is there any solutions which does'nt have these problems ?

  • Imei / Mei numbers using TelephonyManager APIs ( getDeviceId ) - This will be problematic in case of dual sims there might be active and inactive sim slots.
  • AndroidId - Will be reset upon factory reset
  • Wifi mac number - Need wifi connected to get this number and this will not be there for non wifi devices.
  • Advertaising id - Can be reset by user
  • Instance id - Can be reset on factory reset
  • Sim serial number - Not bind to device instead it is for sim
Bill Goldberg
  • 1,699
  • 5
  • 26
  • 50
  • "Is there any solutions which does'nt have these problems ? " -- no, because hardware identifiers raise too many privacy problems. – CommonsWare May 19 '19 at 12:24
  • What is the best way I can implement this logic ? – Bill Goldberg May 19 '19 at 12:40
  • Come up with a business model that does not require you to restrict app subscriptions to certain number of devices per user. For example, you could charge per device, in which case you would want users to have lots of devices. – CommonsWare May 19 '19 at 13:41

1 Answers1

0

After searching and thinking I come up with below solution.

MacID can be used as the unique id. MacID can be get using permission android.permission.READ_PHONE_STATE even with Wifi switch off state. I have successfully tested these in few devices and it works fine. My testing is in progress will update here soon.

public static String getDeviceMacId(){
        try {
            List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
            for (NetworkInterface nif : all) {
                if (!nif.getName().equalsIgnoreCase("wlan0")) continue;

                byte[] macBytes = nif.getHardwareAddress();
                if (macBytes == null) {
                    return "";
                }

                StringBuilder res1 = new StringBuilder();
                for (byte b : macBytes) {
                    res1.append(String.format("%02X:",b));
                }

                if (res1.length() > 0) {
                    res1.deleteCharAt(res1.length() - 1);
                }
                return res1.toString();
            }
        } catch (Exception ex) {
            //handle exception
        }
        return "";
    }



Reference : https://stackoverflow.com/a/35830358/2788009

Bill Goldberg
  • 1,699
  • 5
  • 26
  • 50