Installing User Hook for Android

Installing the User Hook SDK into your Android app is simple and quick. Once you follow the steps below you, your app will be connected to the User Hook platform.

Setup Application

Before integrating User Hook into your Android application, be sure you have logged into the User Hook Admin page and created your account. You will need to know your App Id and App Key while installing the iOS SDK.

Download SDK

The easiest way to install the Android SDK is through a gradle dependency.

In your project level build.gradle file, add:

allprojects {
 repositories {
    jcenter()
    maven { url "https://jitpack.io" }
 }
}

In your app level build.gradle file, add:

dependencies {
    compile 'com.github.cullaboration:userhook-sdk-android:1.3.1'
}

If you would like to view the code or need to manually install the SDK, you can download the project files from Github. If you install the User Hook source code manually, you will need to update your manifest with a few changes.

Update Manifest

There are two changes that are needed in your AndroidManifest.xml file if you installed the source manually. You will need to add the INTERNET and READ_EXTERNAL_STORAGE permissions and you will need to add an activity entry for UHHostedPageActivity.

<manifest>

    <!-- User Hook needs to access the network -->
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- used to allow users to upload images (ex. screenshots) from their device -->
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application>
        ...

        <!-- UserHook -->
        <activity android:name="com.userhook.view.UHHostedPageActivity"
            android:theme="@style/UserHook"
            />

    </application>

</manifest>

Include Styles

Customizing the look and feel of the User Hook prompts and page views is done using predefined styles. From the res/values/style.xml file of the demo application, copy the User Hook styles into your styles.xml file.


 <!-- User Hook -->
    <style name="UserHook" parent="Theme.AppCompat.NoActionBar">
        <item name="actionBarStyle">@style/UHActionBar</item>
    </style>

    <style name="UHActionBar" parent="@style/Widget.AppCompat.ActionBar">
        <item name="android:background">@color/colorPrimary</item>
        <item name="background">@color/colorPrimary</item>
        <item name="android:titleTextStyle">@style/UHActionBarText</item>
        <item name="titleTextStyle">@style/UHActionBarText</item>
    </style>


    <style name="UHActionBarText" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
    </style>

Initialize User Hook

To intialize User Hook, you will need to add a line to your Application class. In this step you will need your User Hook Application Id and Application Key from the admin webpage.


public void onCreate() {
        super.onCreate();

        UserHook.initialize(this, "YOUR_USERHOOK_APP_ID", "YOUR_USERHOOK_APP_KEY", true);

}

Done

That’s it. User Hook is now setup and will begin tracking user sessions.