2

I am developing an application using phonegap for both ios and android. My application is going to have a free trial of 5 items, for every additional item the user will have to pay.

My problem is hat i cant get any unique identifier of the device using my app, so a user can use the 5 free items , then uninstall and reinstall the App and get aditional 5 free items.

I have tried using the device.udid provided by phonegap api , but it changes every time i reinstall it.

Any ideas?

Dror 'Yitzhakov
  • 280
  • 5
  • 15

3 Answers3

5

Get the MAC address of the device and do a SHA1 hash on it to obfuscate. There is open source code out there for getting it for Android and iOS devices.

And this type of solution works regardless of if you continue to use PhoneGap or write native code in the future. Also, Apple has no issues with it as far as the App review process is concerned.

UPDATE: This WAS the right answer up to and through iOS 6, however for all versions of the iOS SDK GREATER THAN 6, this is NO LONGER POSSIBLE. Any attempt to use the low level calls which formerly worked now ALWAY return a MAC Address of 2. Advertising ID and the AdSupport.framework is the only way to. If you have a jailbroken phone and can get root privileges, it might still work. Not sure.

Cliff Ribaudo
  • 8,932
  • 2
  • 55
  • 78
  • I don't use PhoneGap, we write native iOS and Java, but my understanding is that PhoneGap allows you write native code and inject it into PhoneGap. So you would write/find on the internet some simple low level methods that will get the MAC address and do to it what you want, and then pass that to your PhoneGap code. – Cliff Ribaudo Jun 29 '12 at 13:35
  • Hello @CliffRibaudo could you post a reliable link for code of getting mac address. And one think I want to ask one thing that; we know [IMEI](http://en.wikipedia.org/wiki/IMEI) is the identity no of a phone, if so then why there is a possibility of returning null in code such as my ans in this post ? – Soumyadip Das Jun 30 '12 at 10:25
  • We started with this, cleaned it up and obfuscated it by doing SHA256 on it. Start here: http://ios.biomsoft.com/2011/11/07/determine-mac-address/ – Cliff Ribaudo Jun 30 '12 at 22:21
  • 1
    Wouldn't know where to look for that. Try google. Any chance of getting an "accepted answer" from you. It is sort of customary to do that if you find peoples comments helpful here. :) – Cliff Ribaudo Jul 02 '12 at 22:49
  • FYI.... as of iOS 7 getting a MAC address on an IOS Device is actually NOT POSSIBLE. The SDK obfuscates it and returns 2. Yup, '2'. So... you MUST use the Advertising ID. – Cliff Ribaudo Sep 08 '13 at 22:58
1

Personally, I find the best way for a unique Android ID to is to just generate a random String ranging from 16-26 alphanumeric characters, check it doesn't exist on your server, and then save it in the local preferences.

I've experimented with other ways to get a unique ID (IE. TelephonyManager), but all of the ones I'm aware of have the chance of returning null (which isn't good at all). If anyone else has a better way that cannot potentially return null, I would love to hear it.

Cruceo
  • 6,763
  • 2
  • 31
  • 52
1

use device IMEI as follows--

Activity File:

public class Welcome extends Activity {

    private TextView display;
    private Button checkAgain;
    private TelephonyManager telephonyManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        display = (TextView) findViewById(R.id.display);
        checkAgain = (Button) findViewById(R.id.buttonCheckAgain);

        display.setText("");

        telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        updateDisplay();

        checkAgain.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                updateDisplay();
            }
        });

    }

    private void updateDisplay() {
        display.setText(getDeviceID(telephonyManager));
        System.out.println("Display upadated");
    }

    private String getDeviceID(TelephonyManager phonyManager) {

        String id = phonyManager.getDeviceId();
        if (id == null) {
            id = "not available";
        }

        int phoneType = phonyManager.getPhoneType();
        switch (phoneType) {
        case TelephonyManager.PHONE_TYPE_NONE:
            return "NONE: " + id;

        case TelephonyManager.PHONE_TYPE_GSM:
            return "GSM: IMEI=" + id;

        case TelephonyManager.PHONE_TYPE_CDMA:
            return "CDMA: MEID/ESN=" + id;

        default:
            return "UNKNOWN: ID=" + id;
        }
    }
}

and you need this permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
Soumyadip Das
  • 1,781
  • 3
  • 16
  • 34
  • applicable for Android Only, but you may use same Idea for iPhone also. – Soumyadip Das Jun 28 '12 at 16:41
  • TelephonyManager has the possibility of returning a null ID, as mentioned in my answer below, which is a no go. – Cruceo Jun 28 '12 at 16:47
  • yes.. but I never tested this. So what is the possibility of getting null in 100 ?? Please reply. – Soumyadip Das Jun 28 '12 at 16:52
  • It completely depends on the device. Also, keep in mind, TelehonyManager will return null on Tablets. And several of the other methods will also return different device ID's upon a factory reset. You can find out a lot more info on this page, but the comments actually contain better answers of where things can go wrong: http://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id – Cruceo Jun 28 '12 at 16:58
  • yes.. its a important topic & link provided by you. Thanks for that. I don't really know whats the real solution. Waiting for a better approach from anyone else :) – Soumyadip Das Jun 28 '12 at 17:11
  • I've pretty much tried them all and I have to say generating your own Random ID is probably the way to go if you want it to work on all devices. – Cruceo Jun 28 '12 at 17:14
  • One think I want to ask that; we know [IMEI](http://en.wikipedia.org/wiki/IMEI) is the identity no. for a phone, if so then why there is a possibility of returning null in code such as my ans in this post ? – Soumyadip Das Jun 30 '12 at 10:27