com.google.android.gms.ads.identifier.AdvertisingIdClient Java Examples
The following examples show how to use
com.google.android.gms.ads.identifier.AdvertisingIdClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocationUpdatesBroadcastReceiver.java From openlocate-android with MIT License | 6 votes |
private void processLocations(List<Location> locations, Context context, OpenLocate.Configuration configuration, AdvertisingIdClient.Info advertisingIdInfo) { LocationDatabase locationsDatabase = new LocationDatabase(DatabaseHelper.getInstance(context)); try { for (Location location : locations) { Log.v(TAG, location.toString()); OpenLocateLocation olLocation = OpenLocateLocation.from( location, advertisingIdInfo, InformationFieldsFactory.collectInformationFields(context, configuration) ); locationsDatabase.add(olLocation); } } catch (SQLiteFullException exception) { Log.w(TAG, "Database is full. Cannot add data."); } finally { locationsDatabase.close(); } }
Example #2
Source File: AppGoogleAds.java From fyber_mobile_offers with MIT License | 6 votes |
@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()); }
Example #3
Source File: AppGoogleAds.java From fyber_mobile_offers with MIT License | 6 votes |
@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()); }
Example #4
Source File: IDFA.java From react-native-idfa with MIT License | 6 votes |
@ReactMethod public void getIDFA(Promise promise) { try { AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(this.getReactApplicationContext()); String adId = null; if (adInfo.isLimitAdTrackingEnabled()) { adId = ""; } else { adId = adInfo != null ? adInfo.getId() : ""; } promise.resolve(adId); } catch (Exception e) { promise.reject(e); } }
Example #5
Source File: Aptoide.java From aptoide-client with GNU General Public License v2.0 | 6 votes |
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(); }
Example #6
Source File: IdsRepository.java From aptoide-client-v8 with GNU General Public License v3.0 | 5 votes |
@WorkerThread public synchronized Single<String> getGoogleAdvertisingId() { return Single.just(sharedPreferences.getString(GOOGLE_ADVERTISING_ID_CLIENT, null)) .map(id -> { if (!TextUtils.isEmpty(id)) { return id; } else if (AptoideUtils.ThreadU.isUiThread()) { throw new IllegalStateException("You cannot run this method from the main thread"); } else if (!AdNetworkUtils.isGooglePlayServicesAvailable(context)) { return ""; } else { try { return AdvertisingIdClient.getAdvertisingIdInfo(context) .getId(); } catch (Exception e) { throw new IllegalStateException(e); } } }) .doOnSuccess(id -> { if (!id.equals("")) { sharedPreferences.edit() .putString(GOOGLE_ADVERTISING_ID_CLIENT, id) .apply(); sharedPreferences.edit() .putBoolean(GOOGLE_ADVERTISING_ID_CLIENT_SET, true) .apply(); } }) .subscribeOn(Schedulers.newThread()); }
Example #7
Source File: OpenLocateLocation.java From openlocate-android with MIT License | 5 votes |
OpenLocateLocation( Location location, AdvertisingIdClient.Info advertisingInfo, InformationFields informationFields) { this.location = new LocationInfo(location); this.advertisingInfo = advertisingInfo; this.informationFields = informationFields; this.created = new Date(); }
Example #8
Source File: OpenLocate.java From openlocate-android with MIT License | 5 votes |
private void onPermissionsGranted() { FetchAdvertisingInfoTask task = new FetchAdvertisingInfoTask(context, new FetchAdvertisingInfoTaskCallback() { @Override public void onAdvertisingInfoTaskExecute(AdvertisingIdClient.Info info) { advertisingIdInfo = info; openLocateHelper.startTracking(); } }); task.execute(); }
Example #9
Source File: UpdatesService.java From aptoide-client with GNU General Public License v2.0 | 5 votes |
private String getAdvertisementId() { try { return AdvertisingIdClient.getAdvertisingIdInfo(Aptoide.getContext()).getId(); } catch (IOException | GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) { Logger.printException(e); } return null; }
Example #10
Source File: FetchAdvertisingInfoTask.java From openlocate-android with MIT License | 5 votes |
@Override protected Void doInBackground(Void... params) { try { info = AdvertisingIdClient.getAdvertisingIdInfo(context); } catch (IOException | GooglePlayServicesNotAvailableException | GooglePlayServicesRepairableException e) { Log.e(TAG, e.getMessage() != null ? e.getMessage() : "Failed to get ad id."); } return null; }
Example #11
Source File: FetchAdvertisingInfoTaskTests.java From openlocate-android with MIT License | 5 votes |
@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); } } }
Example #12
Source File: OpenLocateLocationTests.java From openlocate-android with MIT License | 5 votes |
@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(); } }
Example #13
Source File: hb.java From letv with Apache License 2.0 | 5 votes |
private Info n() { Info info = null; try { info = AdvertisingIdClient.getAdvertisingIdInfo(hn.a().c()); } catch (Exception e) { ib.b(a, "GOOGLE PLAY SERVICES ERROR: " + e.getMessage()); ib.b(a, "There is a problem with the Google Play Services library, which is required for Android Advertising ID support. The Google Play Services library should be integrated in any app shipping in the Play Store that uses analytics or advertising."); } return info; }
Example #14
Source File: AptoideUtils.java From aptoide-client with GNU General Public License v2.0 | 5 votes |
private static String replaceAdvertisementId(String clickUrl, Context context) throws IOException, GooglePlayServicesNotAvailableException, GooglePlayServicesRepairableException { String aaId = ""; if (GoogleServices.checkGooglePlayServices(context)) { if (AptoideUtils.getSharedPreferences().contains("advertisingIdClient")) { aaId = AptoideUtils.getSharedPreferences().getString("advertisingIdClient", ""); } else { try { aaId = AdvertisingIdClient.getAdvertisingIdInfo(context).getId(); } catch (Exception e) { // In case we try to do this from a Broadcast Receiver, exception will be thrown. Logger.w("AptoideUtils", e.getMessage()); } } } 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(); } clickUrl = clickUrl.replace("[USER_AAID]", aaId); return clickUrl; }
Example #15
Source File: DemoActivity.java From android-sdk with MIT License | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.ACCESS_FINE_LOCATION)) { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Functionality limited"); builder.setMessage("Since location access has not been granted, " + "this app will not be able to discover beacons when in the background."); builder.setPositiveButton(android.R.string.ok, null); if (Build.VERSION.SDK_INT >= 17) { builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { ActivityCompat.requestPermissions(DemoActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSION_REQUEST_LOCATION_SERVICES); } }); } builder.show(); } else { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSION_REQUEST_LOCATION_SERVICES); } } textView = new TextView(this); StringBuilder infoText = new StringBuilder("This is an app that exposes some SDK APIs to the user").append('\n'); if (Build.VERSION.SDK_INT < 18){ infoText.append('\n').append("BLE NOT SUPPORTED, NO BEACONS WILL BE SCANNED").append('\n'); } infoText.append('\n').append("API Key: ").append(DemoApplication.API_KEY); infoText.append('\n').append("SDK Version: ").append(com.sensorberg.sdk.BuildConfig.VERSION_NAME); infoText.append('\n').append("Demo Version: ").append(BuildConfig.VERSION_NAME); textView.setText(infoText.toString()); setContentView(textView); ((DemoApplication) getApplication()).setActivityContext(this); processIntent(getIntent()); AsyncTask<String, Integer, Pair<String, Long>> task = new AsyncTask<String, Integer, Pair<String, Long>>() { @Override protected Pair<String, Long> doInBackground(String... params) { long timeBefore = System.currentTimeMillis(); String advertiserIdentifier = "not-found"; try { advertiserIdentifier = "google:" + AdvertisingIdClient.getAdvertisingIdInfo(DemoActivity.this).getId(); } catch (Exception e) { //not logging anything because it's already logged in the Application } long timeItTook = System.currentTimeMillis() - timeBefore; Logger.log.verbose("foreground fetching the advertising identifier took " + timeItTook + " millis"); return Pair.create(advertiserIdentifier, timeItTook); } @Override protected void onPostExecute(Pair<String, Long> o) { textView.append("\nGoogle Advertising ID: " + o.first); textView.append("\nGoogle ID took: " + o.second + " milliseconds"); } }; task.execute(); }
Example #16
Source File: OpenLocate.java From openlocate-android with MIT License | 4 votes |
protected AdvertisingIdClient.Info getAdvertisingIdInfo() { return advertisingIdInfo; }
Example #17
Source File: OpenLocateLocation.java From openlocate-android with MIT License | 4 votes |
OpenLocateLocation(Date created, String jsonString) { this.created = created; try { JSONObject json = new JSONObject(jsonString); location = new LocationInfo(); location.setLatitude(json.getDouble(Keys.LATITUDE)); location.setLongitude(json.getDouble(Keys.LONGITUDE)); location.setHorizontalAccuracy(Float.parseFloat(json.getString(Keys.HORIZONTAL_ACCURACY))); location.setTimeStampSecs(json.getLong(Keys.TIMESTAMP)); location.setAltitude(json.getDouble(Keys.ALTITUDE)); location.setCourse(Float.parseFloat(json.getString(Keys.COURSE))); location.setSpeed(Float.parseFloat(json.getString(Keys.SPEED))); try { location.setVerticalAccuracy(Float.parseFloat(json.getString(Keys.VERTICAL_ACCURACY))); } catch (JSONException e) { location.setVerticalAccuracy(0); } String deviceManufacturer = ""; if (json.has(Keys.DEVICE_MANUFACTURER)) { deviceManufacturer = json.getString(Keys.DEVICE_MANUFACTURER); } String deviceModel = ""; if (json.has(Keys.DEVICE_MODEL)) { deviceModel = json.getString(Keys.DEVICE_MODEL); } String chargingState = ""; if (json.has(Keys.IS_CHARGING)) { chargingState = json.getString(Keys.IS_CHARGING); } String operatingSystem = ""; if (json.has(Keys.OPERATING_SYSTEM)) { operatingSystem = json.getString(Keys.OPERATING_SYSTEM); } String carrierName = ""; if (json.has(Keys.CARRIER_NAME)) { carrierName = json.getString(Keys.CARRIER_NAME); } String wifiSSID = ""; if (json.has(Keys.WIFI_SSID)) { wifiSSID = json.getString(Keys.WIFI_SSID); } String wifiBSSID = ""; if (json.has(Keys.WIFI_BSSID)) { wifiBSSID = json.getString(Keys.WIFI_BSSID); } String connectionType = ""; if (json.has(Keys.CONNECTION_TYPE)) { connectionType = json.getString(Keys.CONNECTION_TYPE); } String locationMethod = ""; if (json.has(Keys.LOCATION_METHOD)) { locationMethod = json.getString(Keys.LOCATION_METHOD); } String locationContext = ""; if (json.has(Keys.LOCATION_CONTEXT)) { locationContext = json.getString(Keys.LOCATION_CONTEXT); } informationFields = InformationFieldsFactory.getInformationFields(deviceManufacturer, deviceModel, chargingState, operatingSystem, carrierName, wifiSSID, wifiBSSID, connectionType, locationMethod, locationContext); advertisingInfo = new AdvertisingIdClient.Info( json.getString(Keys.AD_ID), json.getBoolean(Keys.AD_OPT_OUT) ); } catch (JSONException exception) { exception.printStackTrace(); } }
Example #18
Source File: OpenLocateLocation.java From openlocate-android with MIT License | 4 votes |
public static OpenLocateLocation from(Location location, AdvertisingIdClient.Info advertisingInfo, InformationFields informationFields) { return new OpenLocateLocation(location, advertisingInfo, informationFields); }
Example #19
Source File: OpenLocateLocation.java From openlocate-android with MIT License | 4 votes |
public void setAdvertisingInfo(AdvertisingIdClient.Info advertisingInfo) { this.advertisingInfo = advertisingInfo; }
Example #20
Source File: OpenLocateLocation.java From openlocate-android with MIT License | 4 votes |
public AdvertisingIdClient.Info getAdvertisingInfo() { return advertisingInfo; }
Example #21
Source File: FetchAdvertisingInfoTaskCallback.java From openlocate-android with MIT License | votes |
void onAdvertisingInfoTaskExecute(AdvertisingIdClient.Info advertisingInfo);