Last active
August 29, 2015 14:03
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ""; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.