-
Obtain a Pathsense SDK Client ID and API Key from here. Click “GET STARTED” and enter your email address.
-
In AndroidManifest.xml, add the following elements as children of the <application> element, by inserting them just before the closing </application> tag:
<meta-data android:name="com.pathsense.android.sdk.CLIENT_ID" android:value="YOUR_PATHSENSE_SDK_CLIENT_ID" /> <meta-data android:name="com.pathsense.android.sdk.API_KEY" android:value="YOUR_PATHSENSE_SDK_API_KEY" />
-
Substitute your CLIENT_ID key for YOUR_PATHSENSE_SDK_CLIENT_ID in the value attribute. This element sets the key com.pathsense.android.sdk.CLIENT_ID to the value of your Pathsense SDK Client ID.
-
Substitute your API_KEY key for YOUR_PATHSENSE_SDK_API_KEY in the value attribute. This element sets the key com.pathsense.android.sdk.API_KEY to the value of your Pathsense SDK API key.
-
-
Save AndroidManifest.xml.
-
In build.gradle, add the following:
- to the dependencies element:
compile project(':pathsense-android-sdk')
-
Save build.gradle.
-
Re-build application.
-
Create a Broadcast Receiver that will receive activity updates.
- For convenience, you can extend PathsenseActivityRecognitionReceiver
public class PathsenseActivityUpdateBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { PathsenseDetectedActivities detectedActivities = PathsenseDetectedActivities.fromIntent(intent); if (detectedActivities != null) { // do something } } }
-
In AndroidManifest.xml, add the following element as a child of the <application> element, by inserting it just before the closing </application> tag:
<receiver android:name=".PathsenseActivityUpdateBroadcastReceiver" />
-
In MainActivity (or any other context object), instantiate the PathsenseLocationProviderApi:
PathsenseLocationProviderApi api = PathsenseLocationProviderApi.getInstance(context);
-
Request activity updates by calling requestActivityUpdates with the receiver created in step #1:
api.requestActivityUpdates(PathsenseActivityUpdateBroadcastReceiver.class);
- until removeActivityUpdates is called, the receiver will be notified whenever an activity update occurs.