Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Detect phone / tablet configuration

  • Loading branch information...
commit 575c8076b99a6885b108d7cdfaf1a103cf3c19bf 1 parent 60c491f
@daggerrz daggerrz authored
View
18 event-tracking/src/main/java/com/tapad/tracking/DeviceInfo.java
@@ -0,0 +1,18 @@
+package com.tapad.tracking;
+
+import android.content.Context;
+
+public class DeviceInfo {
+
+ /**
+ * Check if the screen configuration indicates that this is a tablet.
+ */
+ public static boolean isTablet(Context context) {
+ return context.getResources().getConfiguration().screenLayout == 4; // SCREENLAYOUT_SIZE_XLARGE
+ }
+
+ public static String getUserAgent(Context context) {
+ if (isTablet(context)) return "Android Tablet/TapadEventAPI/1.0";
+ else return "Android Mobile/TapadEventAPI/1.0";
+ }
+}
View
4 event-tracking/src/main/java/com/tapad/tracking/EventResource.java
@@ -36,10 +36,10 @@
* @param appId the application id to use
* @param deviceId the device id to use
*/
- EventResource(String appId, DeviceIdentifier deviceId) {
+ EventResource(String appId, DeviceIdentifier deviceId, String userAgent) {
this.appId = appId;
this.deviceId = deviceId;
- this.client = HttpClientUtil.createClient("Android/TapadEventAPI/1.0");
+ this.client = HttpClientUtil.createClient(userAgent);
}
protected void post(Event e) throws IOException {
View
5 event-tracking/src/main/java/com/tapad/tracking/Tracking.java
@@ -98,7 +98,10 @@ protected static void setupAPI(Context context, String appId) {
deviceId = getHashedDeviceId(context);
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(PREF_TAPAD_DEVICE_ID, deviceId).commit();
}
- service = new TrackingServiceImpl(new EventDispatcher(new EventResource(appId, deviceIdLocator)));
+
+ service = new TrackingServiceImpl(
+ new EventDispatcher(new EventResource(appId, deviceIdLocator, DeviceInfo.getUserAgent(context)))
+ );
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.