public static void asyncFetchAdvertisingInfo( final Context context, final GpsHelperListener gpsHelperListener) { if (!classFound(sAdvertisingIdClientClassName)) { if (gpsHelperListener != null) { gpsHelperListener.onFetchAdInfoCompleted(); } } new Thread( new Runnable() { @Override public void run() { try { MethodBuilder methodBuilder = MethodBuilderFactory.create(null, "getAdvertisingIdInfo") .setStatic(Class.forName(sAdvertisingIdClientClassName)) .addParam(Context.class, context); Object adInfo = methodBuilder.execute(); if (adInfo != null) { updateSharedPreferences(context, adInfo); } } catch (Exception exception) { MoPubLog.d("Unable to obtain AdvertisingIdClient.getAdvertisingIdInfo()"); } finally { if (gpsHelperListener != null) { gpsHelperListener.onFetchAdInfoCompleted(); } } } }) .start(); }
public static void asyncFetchAdvertisingInfoIfNotCached( final Context context, final GpsHelperListener gpsHelperListener) { // This method guarantees that the Google Play Services (GPS) advertising info will // be populated if GPS is available and the ad info is not already cached // The above will happen before the callback is run if (isGpsAvailable(context) && !isSharedPreferencesPopluated(context)) { asyncFetchAdvertisingInfo(context, gpsHelperListener); } else { gpsHelperListener.onFetchAdInfoCompleted(); } }