Mobile App Sensor Documentation (English Version)
Version: | 1.2.21 |
---|---|
Date: | 2015-09-25 |
Author: | Kantar Media Audiences (DE) |
eMail: |
...
In case of any questions concerning this, please contact our support team under support@spring.de.under KA_DE_support@kantarmedia.com
Integration of Libraries
Include Page | ||||
---|---|---|---|---|
|
...
Should you encounter any issues or problems during the implementation, please send an email to our support team under support@spring.de KA_DE_support@kantarmedia.com with the following information:
...
you can edit it in any editor, if you do so, please insert the following code:
Code Block <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>***</string> //please change *** to your URL name, not so important <key>CFBundleURLSchemes</key> <array> <string>***</string> //very important, please replace </array> </dict> </array>
Or you can edit this in xcode, add an item into
Info.plist
, named "URL types", expand "Item 0" under "URL types", and add two items: "URL identifier", "URL Schemes".For "URL identifier", assign your identifier, and for "URL Schemes", add a new item within it named "Item0", REGISTER A UNIQUE URL SCHEME FOR YOUR APP, VERY IMPORTANT!
It should be like the following:
Implementation Android
The following example shows the basic installation for the Android platform. When generating the class SpringMobile
a site identifier (<site>) has to be indicated, which is shipped together with this documentation and the libraries.
Example
Code Block | ||
---|---|---|
| ||
/**
* Importing SpringMobile
*/
import de.spring.mobile.SpringMobile;
/**
* Generating SpringMobile entity with site id and
* application name
*/
SpringMobile spring = new SpringMobile("<site>", "Application Name", getApplicationContext());
/**
* Sending the start of the application to the measurement system
*/
Map<String, Object> map = new HashMap<String, Object>();
map.put(SpringMobile.VAR_ACTION, SpringMobile.APP_STARTED);
spring.commit(map);
/*
* Sending the action spring.BACKGROUND
*/
Map<String, Object> map = new HashMap<String, Object>();
map.put(SpringMobile.VAR_ACTION, SpringMobile.APP_BACKGROUND);
spring.commit(map);
|
Managing Lifecycle Events in Android Apps
A helper class for the Activities can be used instead of SpringMobil.
Link: http://developer.android.com/reference/android/app/Activity.html
...
How to use the different Files in the Library Package
File | Description |
---|---|
spring-appsensor-device.a | This is the version that has been compiled with ARM support and which is intended for execution on iOS devices |
spring-appsensor-simulator.a | This is the version that has been compiled with x86 support and which is intended for execution on iOS simulator |
spring-appsensor-fat.a | This is a combined version of the two libraries above, which can be executed on both, iOS devices and iOS simulator because it contains code for ARM and x86 execution. This file is called "fat" as it is roughly double the size (because it combines both versions). |
Note |
---|
If size does not matter for the app, the "fat" version is the carefree option to be used for execution on simulator and real devices. |
Include Page | ||||
---|---|---|---|---|
|
Implementation Android
The following example shows the basic installation for the Android platform. When generating the class SpringMobile
a site identifier (<site>) has to be indicated, which is shipped together with this documentation and the libraries.
Example
Code Block | ||
---|---|---|
| ||
/**
* Importing SpringMobile
*/
import de.spring.mobile.SpringMobile;
/**
* Generating SpringMobile entity with site id and
* application name
*/
SpringMobile spring = new SpringMobile("<site>", "Application Name", getApplicationContext());
/**
* Sending the start of the application to the measurement system
*/
Map<String, Object> map = new HashMap<String, Object>();
map.put(SpringMobile.VAR_ACTION, SpringMobile.APP_STARTED);
spring.commit(map);
/*
* Sending the action spring.BACKGROUND
*/
Map<String, Object> map = new HashMap<String, Object>();
map.put(SpringMobile.VAR_ACTION, SpringMobile.APP_BACKGROUND);
spring.commit(map);
|
Managing Lifecycle Events in Android Apps
A helper class for the Activities can be used instead of SpringMobile.
Link: http://developer.android.com/reference/android/app/Activity.html
Code Block |
---|
Example Activity: import android.app.Activity; import android.os.Bundle; public class TestActivity extends Activity { private SpringMobileHelper springHelper; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); springHelper = SpringMobileHelper.getInstance(getApplicationContext()); } @Override protected void onStart() { super.onStart(); springHelper.start(); } @Override protected void onResume() { super.onResume(); springHelper.resume(); } @Override protected void onPause() { super.onPause(); springHelper.pause(); } @Override protected void onDestroy() { super.onDestroy(); springHelper.destroy(); } } Helper Class: import java.lang.Thread.State; import java.util.HashMap; import java.util.Map; import android.content.Context; import de.spring.mobile.SpringMobile; /** This class will help to manage more than one Activity. The Class holds the SpringMobile object and managed the events to it. */ public class SpringMobileHelper { private static SpringMobileHelper singelton = null; private SpringMobile spring = null; private boolean isStarted = false; private int foregroundCounter = 0; private final Thread sendBackground = new Thread() { @Override public void run() { super.run(); while(true) { synchronized(sendBackground) { try { wait(); } catch (InterruptedException e) { continue; } try { sleep(1000); Map<String, Object> map = new HashMap<String, Object>(); map.put(SpringMobile.VAR_ACTION, SpringMobile.APP_BACKGROUND); spring.commit(map); } catch (InterruptedException e) {} } } } }; {sendBackground.start();} private SpringMobileHelper() { } /** * @param the context @return SpringMobileHelper */ public static SpringMobileHelper getInstance(Context context) Unknown macro: { if(singelton == null) { singelton = new SpringMobileHelper(); singelton.spring = new SpringMobile("app", "MoreActivities", context); } return singelton; } /** call by start of activity */ public staticvoid SpringMobileHelper getInstance(Context contextstart() Unknown macro: { if(singelton == null!isStarted) { singeltonisStarted = new SpringMobileHelper()true; Map<String, Object> map singelton.spring = new SpringMobile("app"HashMap<String, "MoreActivities", contextObject>(); spring.commit(map); } return singelton; } /** call by startresume of activity */ public void startresume() Unknown macro: { foregroundCounter++; if(sendBackground != null && sendBackground.getState(!isStarted) != State.WAITING) { isStarted = true; sendBackground.interrupt(); } else { Map<String, Object> map = new HashMap<String, Object>( HashMap<String, Object>(); map.put(SpringMobile.VAR_ACTION, SpringMobile.APP_FOREGROUND); spring.commit(map); } } /** * call by resumepause of activity */ public void resumepause() { foregroundCounter--; Unknown macro: { foregroundCounter++; if(sendBackground != null && sendBackground.getState() != State.WAITING) { sendBackground.interrupt(); } } else { Map<String, Object> map = new HashMap<String, Object>(); map.put(SpringMobile.VAR_ACTION, SpringMobile.APP_FOREGROUND); spring.commit(map synchronized(sendBackground) { sendBackground.notify(); } } /** * call by pausedestroy of activity */ public void pausedestroy() { foregroundCounter--; if(foregroundCounter == 0) { if(sendBackground != nulltry &&{ sendBackground.getStatejoin(1000) != State.WAITING) { sendBackground.interrupt(); } ; Map<String, Object> map = new HashMap<String, Object>(); map.put(SpringMobile.VAR_ACTION, SpringMobile.APP_CLOSED); spring.commit(map); } catch (InterruptedException e) {} } } synchronized(sendBackground) { sendBackground.notify(); } }} |
Example: Implementation of an app page request via the action variable (ac)
Code Block | ||
---|---|---|
| ||
/** * Example AC */ import de.spring.mobile.SpringMobile; /** * Generating SpringMobile entity call by destroy of activity with site id and application name */ SpringMobile spring = new public void destroy() { if(foregroundCounter == 0) { try { sendBackground.join(1000);SpringMobile("<site>", "Application Name", getApplicationContext()); /** * Sending AC to the measurement system */ Map<String, Object> map = new HashMap<String, Object>(); mapmap.put(SpringMobile.VAR_ACTION, SpringMobile.APP_CLOSED"ac", "Mainpage"); spring.commit(map); } catch (InterruptedException e) {} } } } |
Example: Implementation of an app page request via the action variable (ac)
Code Block | ||
---|---|---|
| ||
/**
* Example AC
*/
import de.spring.mobile.SpringMobile;
/**
* Generating SpringMobile entity with site id and application name
*/
SpringMobile spring = new SpringMobile("<site>", "Application Name", getApplicationContext());
/**
* Sending AC to the measurement system
*/
Map<String, Object> map = new HashMap<String, Object>();
map.put("ac", "Mainpage");
spring.commit(map);
|
Android Permissions
The following settings need to be conducted in the file AndroidManifest.xml AndroidManifest.xml
:
Code Block | ||
---|---|---|
| ||
<uses-permission android:name="android.permission.READ_PHONE_STATE">
</uses-permission>
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> |
Info |
---|
The setting of the permission through the user is not mandatory, but highly recommended. If the permission If the permission is not set, only the Android ID is used. The last one item above is for the registration of google-play-services, which is precondition for retrieving Google Advertising ID. Two aspects are crucial: There is a bug in the Android version 2.2, which only occurs in connection with certain providers, where for all affected devices the same Android ID will be delivered. For the study, this would mean that the user identification would become much more difficult. |
Timeout
With this value, a timeout (in seconds) for each HTTP request can be configured within the library.
Code Block | ||
---|---|---|
| ||
SpringMobile spring = new ("app","TestApp",getApplicationContext());
spring.setTimeout(30); // in seconds
|
Advise for Implementation when using Android 3.0 and higher Versions
Note |
---|
Note: Starting from Android 3.0Since Android 3.0 network accesses are not allowed from the main thread anymore. Thus, the Spring.commit () method is achieved in a background thread. For this reason, please keep the initialization and usage of Spring lib in your main UI thread, Spring lib will not block your GUI display. Otherwise background thread conflicts might pop up. |
...
|
Android Permissions
The following settings need to be conducted in the file AndroidManifest.xml AndroidManifest.xml
:
Code Block | ||
---|---|---|
| ||
<uses-permission android:name="android.permission.READ_PHONE_STATE">
</uses-permission>
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> |
Info |
---|
The setting of the permission through the user is not mandatory, but highly recommended. If the permission If the permission is not set, only the Android ID is used. The last one item above is for the registration of google-play-services, which is precondition for retrieving Google Advertising ID. Two aspects are crucial: There is a bug in the Android version 2.2, which only occurs in connection with certain providers, where for all affected devices the same Android ID will be delivered. For the study, this would mean that the user identification would become much more difficult. |
Timeout
With this value, a timeout (in seconds) for each HTTP request can be configured within the library.
Code Block | ||
---|---|---|
| ||
SpringMobile spring = new ("app","TestApp",getApplicationContext());
spring.setTimeout(30); // in seconds
|
Advise for Implementation when using Android 3.0 and higher Versions
Note |
---|
Note: Starting from Android 3.0Since Android 3.0 network accesses are not allowed from the main thread anymore. Thus, the Spring.commit () method is achieved in a background thread. For this reason, please keep the initialization and usage of Spring lib in your main UI thread, Spring lib will not block your GUI display. Otherwise background thread conflicts might pop up. |
ProGuard
Therefore it is necessary to add the following lines into the ProGuard configuration file:
-keep class de.spring.** { *; }
-keep class de.spring.** { *; }
-keep class org.apache.** { *; }
If you want to suppress the warnings regarding library-program-class-dependencies , please add to the configuration file
-dontwarn android.webkit.WebView
-dontwarn android.webkit.WebViewClient
Implementation Blackberry
The following example shows the basic installation for the Blackberry platform. When generating the class SpringMobile
a site identifier (<site>) has to be indicated, which is shipped together with this documentation and the libraries.
Code Block | ||
---|---|---|
| ||
/**
* Importing SpringMobile
*/
import de.spring.mobile.SpringMobile;
/**
* Generating SpringMobile entity with site id and
* application name
*/
SpringMobile spring = new SpringMobile("<site>", "myApplication1");
/**
* Sending the start of the application to the measurement system
*/
Hashtable target = new Hashtable();
target.put(SpringMobile.VAR_ACTION, SpringMobile.APP_STARTED);
try {
// ...
spring.commit(target);
} catch (ParamNotSupportedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
/**
* Sending the action spring.BACKGROUND
*/
Hashtable target = new Hashtable();
target.put(SpringMobile.VAR_ACTION, SpringMobile.APP_BACKGROUND);
try {
spring.commit(target);
} catch (ParamNotSupportedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
 |
Code Block | ||
---|---|---|
| ||
/**
* Alternative method
* Sending the action spring.BACKGROUND with own
* connection parameters
*/
Hashtable target = new Hashtable();
target.put(SpringMobile.VAR_ACTION, SpringMobile.APP_BACKGROUND);
Hashtable bbprops = new Hashtable();
bbprops.put("deviceside", "true");
try {
spring.commit(bbprops,target);
} catch (ParamNotSupportedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
|
Example: Implementation of an app page request via the action variable (ac)
Code Block | ||
---|---|---|
| ||
/**
* example AC
*/
Hashtable target = new Hashtable();
target.put("ac", "Mainpage");
try {
// ...
spring.commit(target);
} catch (ParamNotSupportedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
|
Info |
---|
Although the library provides the possiblity of using connection parameters, it is highly recommended to use "spring.commit(Hashtable target)". While using connection parameters that are not supported a respective exception is thrown. |
Implementation Windows Phone
The following example shows the basic installation for the Windows Phone 7 platform. When generating the class SpringMobile
a site identifier (<site>) has to be indicated, which is shipped together with this documentation and the libraries.
Code Block | ||
---|---|---|
| ||
/*
* Importing SpringMobile
*/
using spring_mobile_wp7;
/*
* Generating SpringMobile entity with site id and
* application name
*/
SpringMobile spring = new SpringMobile("<site>", "myApplication1");
/*
* Sending the start of the application to the measurement system
*/
Dictionary<String, String> target = new Dictionary<string, string>();
target.Add(SpringMobile.VAR_ACTION, SpringMobile.APP_STARTED);
spring.commit(target);
...
/*
* Sending the action spring.BACKGROUND
*/
Dictionary<String, String> target = new Dictionary<string, string>();
target.Add(SpringMobile.VAR_ACTION, SpringMobile.APP_BACKGROUND);
spring.commit(target);
|
Example: Implementation of an app page request via the action variable (ac)
Code Block | ||
---|---|---|
| ||
/*
* Example AC
*/
using spring_mobile_wp7;
/*
* Generating SpringMobile entity with site id and application name
*/
SpringMobile spring = new SpringMobile("<site>", "myApplication1");
/*
* Sending AC to the measurement system
*/
Dictionary<String, String> target = new Dictionary<string, string>();
target.Add("ac", "Mainpage");
spring.commit(target);
...
/*
|
Info | |||||
---|---|---|---|---|---|
For the measurement we need the device ID. Please set the right for reading the device ID into a config file (WMAppManifest.xml).
|
Implementation Titanium (not supported at the moment)
Include Page | ||||
---|---|---|---|---|
|