Back to project page android-sdk.
The source code is released under:
Copyright (c) 2013 Adcash OU. All rights reserved under Creative Commons Attribution 3.0 Unported http://creativecommons.org/licenses/by/3.0/ Redistribution and use in source and binary forms, with or...
If you think the Android project android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.adcash.mobileads; //from w w w.j ava 2 s .c o m import android.content.Context; import android.content.res.Configuration; import android.location.Location; import android.net.ConnectivityManager; import android.net.wifi.WifiManager; import android.os.AsyncTask; import android.telephony.TelephonyManager; import com.adcash.mobileads.util.DateAndTime; import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Locale; import android.os.Build; import static android.Manifest.permission.ACCESS_NETWORK_STATE; import static android.content.Context.MODE_PRIVATE; import static android.content.pm.PackageManager.PERMISSION_GRANTED; import static android.net.ConnectivityManager.*; import static com.adcash.mobileads.BaseUrlGenerator.AdcashNetworkType.ETHERNET; import static com.adcash.mobileads.BaseUrlGenerator.AdcashNetworkType.MOBILE; import static com.adcash.mobileads.BaseUrlGenerator.AdcashNetworkType.UNKNOWN; import static com.adcash.mobileads.BaseUrlGenerator.AdcashNetworkType.WIFI; public class AdUrlGenerator extends BaseUrlGenerator { public AdUrlGenerator(Context context) { mContext = context; mTelephonyManager = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE); mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE); mSharedPreferences = mContext.getSharedPreferences(AdcashConversionTracker.PREFERENCE_NAME, MODE_PRIVATE); } public AdUrlGenerator withAdUnitId(String adUnitId) { mAdUnitId = adUnitId; return this; } public AdUrlGenerator withKeywords(String keywords) { mKeywords = keywords; return this; } public AdUrlGenerator withFacebookSupported(boolean enabled) { mFacebookSupportEnabled = enabled; return this; } public AdUrlGenerator withLocation(Location location) { mLocation = location; return this; } @Override public String generateUrlString(String serverHostname) { initUrlString(serverHostname, AdcashView.AD_HANDLER); setApiVersion("6"); setAdUnitId(mAdUnitId); setSdkVersion(Adcash.SDK_VERSION); setDeviceInfo(Build.MANUFACTURER, Build.MODEL, Build.PRODUCT); Log.i("Adcash: isGPS", GpsHelper.isGpsAvailable(mContext) + ""); //new TestAdvertiserID().execute(); setLocation(mLocation); setTimezone(getTimeZoneOffsetString()); setOrientation(mContext.getResources().getConfiguration().orientation); setDensity(mContext.getResources().getDisplayMetrics().density); setWidth(mContext.getResources().getDisplayMetrics().widthPixels); setHeight(mContext.getResources().getDisplayMetrics().heightPixels); setMraidFlag(detectIsMraidSupported()); String networkOperator = getNetworkOperator(); setMccCode(networkOperator); setMncCode(networkOperator); setIsoCountryCode(mTelephonyManager.getNetworkCountryIso()); setCarrierName(mTelephonyManager.getNetworkOperatorName()); setNetworkType(getActiveNetworkType()); setAppVersion(getAppVersionFromContext(mContext)); setLocale(Locale.getDefault().toString()); setManufacturer(android.os.Build.MANUFACTURER); setModel(android.os.Build.MODEL); setAndroidVersion(android.os.Build.VERSION.RELEASE); setUdid(getUdidFromContext(mContext)); setDoNotTrack(GpsHelper.isLimitAdTrackingEnabled(mContext)); String keywords = AdUrlGenerator.addKeyword(mKeywords, AdUrlGenerator.getFacebookKeyword(mContext, mFacebookSupportEnabled)); setKeywords(keywords); return getFinalUrlString(); } private boolean detectIsMraidSupported() { boolean mraid = true; try { Class.forName("com.adcash.mobileads.MraidView"); } catch (ClassNotFoundException e) { mraid = false; } return mraid; } private static String getFacebookKeyword(Context context, final boolean enabled) { if (!enabled) { return null; } try { Class<?> facebookKeywordProviderClass = Class.forName("com.adcash.mobileads.FacebookKeywordProvider"); Method getKeywordMethod = facebookKeywordProviderClass.getMethod("getKeyword", Context.class); return (String) getKeywordMethod.invoke(facebookKeywordProviderClass, context); } catch (Exception exception) { return null; } } private static String addKeyword(String keywords, String addition) { if (addition == null || addition.length() == 0) { return keywords; } else if (keywords == null || keywords.length() == 0) { return addition; } else { return keywords + "," + addition; } } }