How get the unique identify for phone device under ios or android

How get the unique identify for phone device under ios or android
0.0 0


How get the unique identify for phone device under ios or android.

I don’t know how to get the unique identify under ios and android using c**.
I know under android I can use java like this
to get the device id .
and how can i use c** to get this, and how can i use c++ to get the ios device id.

Get Device Id in Cocos2dX 3.3

You can invoke java code via jni. Refer
cocos2d-x/HelloWorld/andorid/src/org/cocos2dx/lib/ and

On iOS, you can get the device id by:

[[UIDevice currentDevice] uniqueIdentifier]

It is written by object-c, but it can be mixed used with c++.


Ming, I think we can add a wiki page describing how to invoke java interface from JNI.
We’ve answered this very question for many times.


Thanks I get the imei like this

extern "C" { const char* get_imei_jni() { JniMethodInfo t; if (JniHelper::getStaticMethodInfo(t , "org/cocos2dx/lib/Cocos2dxActivity" //org/cocos2dx/lib/Cocos2dxActivity , "getIMEI" , "()Ljava/lang/String;")) { jstring jstr = NULL; jstr = (jstring)t.env->CallStaticObjectMethod(t.classID, t.methodID); char* cstr = NULL; cstr = (char*) t.env->GetStringUTFChars(jstr, 0); std::string ret(cstr); t.env->ReleaseStringUTFChars(jstr, cstr); t.env->DeleteLocalRef(jstr); return ret.c_str(); } return NULL; } }
and ios
const char* CommonUtils::getIMEI() { NSString *str = [[UIDevice currentDevice] uniqueIdentifier]; return [str UTF8String]; }

I learn how C++ code invoke java interface by reading the code MessageJNI


On iOS, you can get the device id by:
It is written by object-c,

but it can be mixed used with c++: can you pls tell. How exactly?

thank you.


Rename file to, then you can use c*+ and object-c in the file.
For detail information, you can research mixing usage of c*+ and object-c by google.



I think there should be a unified API which will return the unique id of the device.
It doesn’t make sense for all of the developers [who need this, obviously]to write custom code to get it.
Currently cocos2dx supports: ios, android, bada, nokia[?], blackberry [?], others… and if one wants to release version of the game for all of the devices, it would be cool to have one single api to call to get the number.
I am sending this information in all of requests to the server and now I’m facing a problem - how to get this id on all of the platforms.


#932 is created for it.
I don’t know if all the platforms have a unique id and if they all return the same type, such as int or string.


But uniqueIdentifier is deprecated on iOS5.0, how to get unique identify?


I would follow this guide:


Can this method used before iOS5.0?
And it is app dependent, is it a good method?


Looking at the new iOS policy I don’t think there’s any other method.
I am not sure how it works on devices before 5.0, I will have to take a look once I’m back in the cocos2d-x project.
What I know is that we can’t have 2 methods for checking the device id.
Developers should adapt to the new way and change their code in games.
In our project we use deviceId as a first way to identify user [before they create account]. If the deviceId changes, they will loose all the data.
Also take a look at the first comment on the page I gave link to.
Storing the id in the keychain might be a good way to go, but still I think user will be able to “wipe” the device and loose the previously saved device id.
Damn :confused:


This generates a unique identifier based on the mac address of the iOS 5 device in combination with the bundle identifier.



Is there any news about this ?
I saw the issue #932, but there is nothing indicating it has progressed…



Is there any last idea?


Guys I need this too. It is very important and I can not workaround getting device unique id. What is the status of feature 932? It was opened 1.5 years ago and still no progress as I see. But there should be some approaches/codes, people have used all this time. Maybe someone can share his experience?


you need to use the OS for this however its not uniform.

before ios 6 you could use: [UIDevice currentDevice].uniqueIdentifier;

ios 6 you could use: [UIDevice currentDevice].identifierForVendor.UUIDString

ios 7, neither of the above work and you can’t access network card mac address, its protected.

for Android you can use: Secure.ANDROID_ID


BTW I don’t know in other cases, but in my case I don’t need any real hardware ID (network card mac address, IMEI or so). I just need to identify different devices. In other words, the enumeration (actually generating UUID on each device once) of devices that play my game would be just fine. And I think lots of people will need just this to identify the device.

Is it possible to realize the following scenario with cocos2d-x existing API? Generate a UUID on the first run of the application on the device and serialize it. And even if the app will be uninstalled and installed later, the UUID will be serialized in a “safe” place and it can be reused instead of generating a new UUID on each install. In order to do this I need:

  • UUID generator which works on all cocos2d-x supported platforms
  • a place to serialize UUID that will not be deleted when the app is uninstalled, and is far from the eye of the user, so he could not delete it manually

Any ideas?


Is there a solution for this?? thanks