Java tutorial
//package com.java2s; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import android.content.Context; public class Main { public static String getId(Context context) { String id = null; try { Class aicclass = Class.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient"); Method m1 = aicclass.getMethod("getAdvertisingIdInfo", Context.class); Object oInfo = m1.invoke(null, context); Class infoclass = Class.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient$Info"); Method m2 = infoclass.getMethod("getId"); id = (String) m2.invoke(oInfo); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } return id; } }