Created
September 15, 2014 02:28
-
-
Save moltak/acb51c698eb27201d2d8 to your computer and use it in GitHub Desktop.
android adverties keys
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
// code | |
// Do not call this function from the main thread. Otherwise, | |
// an IllegalStateException will be thrown. | |
public void getIdThread() { | |
AdvertisingIdClient.Info adInfo = null; | |
try { | |
adInfo = AdvertisingIdClient.getAdvertisingIdInfo(this); | |
} | |
catch (IOException e) { | |
// Unrecoverable error connecting to Google Play services (e.g., | |
// the old version of the service doesn't support getting AdvertisingId). | |
e.printStackTrace(); | |
} | |
catch (GooglePlayServicesNotAvailableException e) { | |
// Google Play services is not available entirely. | |
e.printStackTrace(); | |
} | |
catch (GooglePlayServicesRepairableException e) { | |
e.printStackTrace(); | |
} | |
final String id = adInfo.getId(); | |
final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
Toast.makeText(MyActivity.this, id, Toast.LENGTH_SHORT).show(); | |
} | |
}); | |
} | |
// dependencies | |
dependencies { | |
compile fileTree(dir: 'libs', include: ['*.jar']) | |
compile 'com.android.support:support-v4:20.0.0' | |
compile 'com.android.support:appcompat-v7:20.0.0' | |
compile 'com.google.android.gms:play-services:5.0.89' | |
} | |
// android manifest | |
<meta-data | |
android:name="com.google.android.gms.version" | |
android:value="5089000" /> | |
<!-- about a google map --> | |
<uses-library android:name="com.google.android.maps" /> | |
<meta-data | |
android:name="com.google.android.maps.v2.API_KEY" | |
android:value="AIzaSyB4CUWyxfR2p2sf59C4opnpRr5zHb0JLZk" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment