Skip to content

Instantly share code, notes, and snippets.

@vaelen
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaelen/b7e525764dfeb4350fd0 to your computer and use it in GitHub Desktop.
Save vaelen/b7e525764dfeb4350fd0 to your computer and use it in GitHub Desktop.
This class shows an example of how to use AdvertisingIdentifier.java. It is not intended as a full working example.
public class UseAdvertisingIdentifier {
public String getBiParams(Activity activity) {
String mac = getMacAddress();
String macMd5 = "";
if (mac.length() > 0) {
macMd5 = Utility.md5(mac);
}
String openUdid = getOpenUdid();
String udid = getUdid();
AdvertisingIdentifier adId = AdvertisingIdentifier.getInstance(activity);
JSONObject jsonObj = new JSONObject();
try {
jsonObj.put("open_udid", openUdid);
jsonObj.put("udid", udid);
jsonObj.put("mac", mac);
jsonObj.put("mac_hash", macMd5);
switch(adId.getType()) {
case GOOGLEPLAY_ADVERTISING_ID:
jsonObj.put("googleplay_advertising_id", adId.getId());
break;
case ANDROID_ID:
default:
jsonObj.put("device_id", adId.getId());
break;
}
return jsonObj.toString();
} catch (JSONException ex) {
// Fail silently and return empty string
}
return "";
}
}
@vaelen
Copy link
Author

vaelen commented Jul 8, 2014

It's important to remember that the advertising id can't be logged or stored in the same place as the MAC address or other device identifiers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment