当前位置: 首页>>代码示例>>Java>>正文


Java AdvertisingIdClient类代码示例

本文整理汇总了Java中com.google.android.gms.ads.identifier.AdvertisingIdClient的典型用法代码示例。如果您正苦于以下问题:Java AdvertisingIdClient类的具体用法?Java AdvertisingIdClient怎么用?Java AdvertisingIdClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AdvertisingIdClient类属于com.google.android.gms.ads.identifier包,在下文中一共展示了AdvertisingIdClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onFetchCurrentLocation

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
private void onFetchCurrentLocation(final Location location, final OpenLocateLocationCallback callback) {
    FetchAdvertisingInfoTask task = new FetchAdvertisingInfoTask(context, new FetchAdvertisingInfoTaskCallback() {
        @Override
        public void onAdvertisingInfoTaskExecute(AdvertisingIdClient.Info info) {

            callback.onLocationFetch(
                    OpenLocateLocation.from(
                            location,
                            info,
                            InformationFieldsFactory.collectInformationFields(context, configuration)
                    )
            );
        }
    });
    task.execute();
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:17,代码来源:OpenLocate.java

示例2: getAdvertisingId

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
/**
 * Retrieves the advertising ID. Requires Google Play Services. Note: This method must not run on
 * the main thread.
 */
private static DeviceIdInfo getAdvertisingId(Context caller) throws Exception {
  try {
    AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(caller);
    if (info != null) {
      String advertisingId = info.getId();
      String deviceId = checkDeviceId("advertising id", advertisingId);
      if (deviceId != null) {
        boolean limitedTracking = info.isLimitAdTrackingEnabled();
        return new DeviceIdInfo(deviceId, limitedTracking);
      }
    }
  } catch (Throwable t) {
    Log.e("Error getting advertising ID. Google Play Services are not available: ", t);
  }
  return null;
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:21,代码来源:Util.java

示例3: setValues

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void setValues(Intent intent) {


    endpoints = intent.getParcelableArrayListExtra(Constants.ENDPOINTS_KEY);

    advertisingInfo = new AdvertisingIdClient.Info(
            intent.getStringExtra(Constants.ADVERTISING_ID_KEY),
            intent.getBooleanExtra(Constants.LIMITED_AD_TRACKING_ENABLED_KEY, false)
    );

    setLocationRequestIntervalInSecs(intent);
    setTransmissionIntervalInSecs(intent);
    setLocationAccuracy(intent);
    setFieldsConfiguration(intent);
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:17,代码来源:LocationServiceHelper.java

示例4: setAdvertisingIdClient

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
private void setAdvertisingIdClient() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            String aaid = "";
            if (AptoideUtils.GoogleServices.checkGooglePlayServices(context)) {
                try {
                    aaid = AdvertisingIdClient.getAdvertisingIdInfo(Aptoide.this).getId();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                byte[] data = new byte[16];
                String deviceId = android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
                SecureRandom secureRandom = new SecureRandom();
                secureRandom.setSeed(deviceId.hashCode());
                secureRandom.nextBytes(data);
                aaid = UUID.nameUUIDFromBytes(data).toString();
            }

            AptoideUtils.getSharedPreferences().edit().putString("advertisingIdClient", aaid).apply();
        }
    }).start();
}
 
开发者ID:Aptoide,项目名称:aptoide-client,代码行数:25,代码来源:Aptoide.java

示例5: getAdIdFromGoogleObservable

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
@NonNull
private Observable<String> getAdIdFromGoogleObservable() {
    return Observable.create(new Observable.OnSubscribe<String>() {
        @Override
        public void call(Subscriber<? super String> subscriber) {
            try {
                subscriber.onNext(AdvertisingIdClient.getAdvertisingIdInfo(context).getId());
            } catch (Exception e) {
                Timber.e(e, "Error getting google Advertising ID!");

                String diskValue = valueManager.getAdId();
                if (null == diskValue || diskValue.isEmpty())
                    subscriber.onError(e);
                else
                    subscriber.onNext(diskValue);
            }
        }
    })
            .doOnNext(adId -> this.adId = adId)
            .doOnNext(adId -> valueManager.setAdId(adId))
            .subscribeOn(scheduler.backgroundThread())
            .observeOn(scheduler.mainThread());
}
 
开发者ID:mirhoseini,项目名称:fyber_mobile_offers,代码行数:24,代码来源:AppGoogleAds.java

示例6: getAdIdEnabledFromGoogleObservable

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
@NonNull
private Observable<Boolean> getAdIdEnabledFromGoogleObservable() {
    return Observable.create(new Observable.OnSubscribe<Boolean>() {
        @Override
        public void call(Subscriber<? super Boolean> subscriber) {
            try {
                subscriber.onNext(AdvertisingIdClient.getAdvertisingIdInfo(context).isLimitAdTrackingEnabled());
            } catch (Exception e) {
                Timber.e(e, "Error getting google Tracking Enabled!");

                Boolean diskValue = valueManager.getAdIdEnabled();
                if (null == diskValue)
                    subscriber.onError(e);
                else
                    subscriber.onNext(diskValue);
            }
        }
    })
            .doOnNext(adIdEnabled -> this.adIdEnabled = adIdEnabled)
            .doOnNext(adIdEnabled -> valueManager.setAdIdEnabled(adIdEnabled))
            .subscribeOn(scheduler.backgroundThread())
            .observeOn(scheduler.mainThread());
}
 
开发者ID:mirhoseini,项目名称:fyber_mobile_offers,代码行数:24,代码来源:AppGoogleAds.java

示例7: zzCw

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
final Pair<String, Boolean> zzCw()
{
  checkOnWorkerThread();
  long l = getClock().elapsedRealtime();
  if ((this.zzbnx != null) && (l < this.zzbnz)) {
    return new Pair(this.zzbnx, Boolean.valueOf(this.zzbny));
  }
  this.zzbnz = (l + zzc.zzBG());
  AdvertisingIdClient.setShouldSkipGmsCoreVersionCheck(true);
  try
  {
    AdvertisingIdClient.Info localInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext());
    this.zzbnx = localInfo.zzpp;
    this.zzbny = localInfo.zzpq;
    AdvertisingIdClient.setShouldSkipGmsCoreVersionCheck(false);
    return new Pair(this.zzbnx, Boolean.valueOf(this.zzbny));
  }
  catch (Throwable localThrowable)
  {
    for (;;)
    {
      zzBh().zzbnd.zzm("Unable to get advertising id", localThrowable);
      this.zzbnx = "";
    }
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:27,代码来源:zzr.java

示例8: getDumpMap

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
@Override
public LinkedHashMap<String, String> getDumpMap(Context context) throws DumpException {
    LinkedHashMap<String, String> dumps = new LinkedHashMap<>();

    dumps.put(Settings.Secure.ANDROID_ID, getAndroidId(context));
    dumps.put("UUID", getUUID());

    String adIdKey = "AdvertisingId";
    String adOptoutKey = "isAdOptout";
    AdvertisingIdClient.Info adInfo = getAdInfo(context);
    if (adInfo == null) {
        dumps.put(adIdKey, "Getting AdvertisingId need a android.permission.INTERNET");
        dumps.put(adOptoutKey, "Getting AdvertisingId need a android.permission.INTERNET");
    } else {
        dumps.put(adIdKey, adInfo.getId());
        dumps.put(adOptoutKey, Boolean.toString(adInfo.isLimitAdTrackingEnabled()));
    }

    return dumps;
}
 
开发者ID:shikato,项目名称:info-dumper,代码行数:21,代码来源:IdsDumper.java

示例9: updateAdvertisingId

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
public void updateAdvertisingId() {

        new Thread(new Runnable() {
            @Override
            public void run() {
                AdvertisingIdClient.Info adInfo = null;
                try {
                    adInfo = AdvertisingIdClient.getAdvertisingIdInfo(TweetingActivity.this);

                } catch (IOException | GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException exception) {
                    // Unrecoverable error connecting to Google Play services (e.g.,
                    // the old version of the service doesn't support getting AdvertisingId).

                }
                if (adInfo != null) {
                    mAdversitingId = adInfo.getId();
                }
            }
        });
    }
 
开发者ID:HugoGresse,项目名称:TweetyHunting,代码行数:21,代码来源:TweetingActivity.java

示例10: OpenLocateLocation

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
OpenLocateLocation(
        Location location,
        AdvertisingIdClient.Info advertisingInfo, InformationFields informationFields) {
    this.location = new LocationInfo(location);
    this.advertisingInfo = advertisingInfo;
    this.informationFields = informationFields;
    this.created = new Date();
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:9,代码来源:OpenLocateLocation.java

示例11: onPermissionsGranted

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
void onPermissionsGranted() {

        FetchAdvertisingInfoTask task = new FetchAdvertisingInfoTask(context, new FetchAdvertisingInfoTaskCallback() {
            @Override
            public void onAdvertisingInfoTaskExecute(AdvertisingIdClient.Info info) {
                onFetchAdvertisingInfo(info);
            }
        });
        task.execute();
    }
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:11,代码来源:OpenLocate.java

示例12: onFetchAdvertisingInfo

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
private void onFetchAdvertisingInfo(AdvertisingIdClient.Info info) {
    Intent intent = new Intent(context, LocationService.class);

    intent.putParcelableArrayListExtra(Constants.ENDPOINTS_KEY, endpoints);

    updateLocationConfigurationInfo(intent);
    updateFieldsConfigurationInfo(intent);

    if (info != null) {
        updateAdvertisingInfo(intent, info.getId(), info.isLimitAdTrackingEnabled());
    }

    context.startService(intent);
    setStartedPreferences();
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:16,代码来源:OpenLocate.java

示例13: doInBackground

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
    try {
        info = AdvertisingIdClient.getAdvertisingIdInfo(context);
    } catch (IOException
            | GooglePlayServicesNotAvailableException
            | GooglePlayServicesRepairableException e) {
        Log.e(TAG, e.getMessage());
    }

    return null;
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:13,代码来源:FetchAdvertisingInfoTask.java

示例14: testFetchAdvertisingInfoTask

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
@Test
public void testFetchAdvertisingInfoTask() {

    // Given
    final Object syncObject = new Object();

    FetchAdvertisingInfoTaskCallback callback = new FetchAdvertisingInfoTaskCallback() {
        @Override
        public void onAdvertisingInfoTaskExecute(AdvertisingIdClient.Info advertisingInfo) {
            assertNotNull(advertisingInfo);
            synchronized (syncObject) {
                syncObject.notify();
            }
        }
    };

    FetchAdvertisingInfoTask task = new FetchAdvertisingInfoTask(InstrumentationRegistry.getTargetContext(), callback);

    // When
    task.execute();

    // Then
    synchronized (syncObject) {
        try {
            syncObject.wait();
        } catch (InterruptedException e) {
            assertTrue(false);
        }
    }
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:31,代码来源:FetchAdvertisingInfoTaskTests.java

示例15: testOpenLocateConstructor

import com.google.android.gms.ads.identifier.AdvertisingIdClient; //导入依赖的package包/类
@Test
public void testOpenLocateConstructor() {
    // Given
    double lat = 10.40;
    double lng = 10.234;
    double accuracy = 40.43;
    boolean adOptOut = true;
    String adId = "1234";

    Location location = new Location("");
    location.setLatitude(lat);
    location.setLongitude(lng);
    location.setAccuracy((float) accuracy);

    AdvertisingIdClient.Info info = new AdvertisingIdClient.Info(adId, adOptOut);

    OpenLocateLocation openLocateLocation = new OpenLocateLocation(location, info, null);

    // When
    JSONObject json = openLocateLocation.getJson();

    // Then
    assertNotNull(openLocateLocation);
    try {
        assertEquals(json.getDouble(OpenLocateLocation.Keys.LATITUDE), lat, 0.0d);
        assertEquals(json.getDouble(OpenLocateLocation.Keys.LONGITUDE), lng, 0.0d);
        assertEquals(json.getDouble(OpenLocateLocation.Keys.HORIZONTAL_ACCURACY), accuracy, 0.1);
        assertEquals(json.getBoolean(OpenLocateLocation.Keys.AD_OPT_OUT), adOptOut);
        assertEquals(json.getString(OpenLocateLocation.Keys.AD_ID), adId);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:34,代码来源:OpenLocateLocationTests.java


注:本文中的com.google.android.gms.ads.identifier.AdvertisingIdClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。