Add and integrate our Android SDK

This guide will walk you through getting our SDK integrated with your app. Please make sure you've already generated your Firebase credentials and have checked the prerequisites.

Step 1 - Adding the PushSDK to your app

Add the JitPack repository to your build file, it should go in the root build.gradle at the end of repositories:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

Then, to your module (app-level) Gradle file (usually app/build.gradle), add the dependencies for the Pushologies SDK.

    dependencies {  
        // ... Your existing dependencies
         **// 
        //Add the dependencies for the Pushologies SDK
        implementation 'com.pushologies:PushSDK:1.+'
    }

Step 2 - Create your application class

To initialize Pushologies SDK, you need to have an base Application class file. Starter projects don't normally come with one, and if you don't have one, complete this step to create a new one, otherwise you can skip to step 3.

Have a read of the docs on the Android Developer site to understand what you're doing, but don't worry, we can guide you through too.

Create a new class (not file) and call it MainApplication. Don't add anything to it yet, we'll cover that in the next step.

Before you're finished here though, you need to edit your AndroidManifest.xml. In the <application> tag, add the following

    android:name="com.example.mypushapp.MainApplication"

so it probably ends up looking something like :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mypushapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.MyPushApp"
        android:name="com.example.mypushapp.MainApplication">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name"
            android:theme="@style/Theme.MyPushApp.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Step 3 - Initialise the SDK

Now, add the following imports to your Application class:

import com.pushologies.pushsdk.PushSDK
import com.pushologies.pushsdk.utils.PushSDKApplication

Then add the PushSDKApplication to your Application class

        class MainApplication : PushSDKApplication() {
        ....

Now, within onCreate() in main application class, initalize the sdk like below,

    override fun onCreate()
    {
        super.onCreate()
        PushSDK.init(context = this,gcmSenderId = "GCM_SENDER_ID")
        .setServerKey(YOUR SDK API KEY)
        .setSecretKey(YOUR SDK API SECRET)  
        .build()
    }

PushSDK.init() will throw PushSDKException if secret key and API key is not set. Replace the placeholders with the keys you got from the Pushologies portal in the previous guide and the sender ID from Firebase.

Step 4 (Optional) : Additional Parameters to configure the SDK

You can configure the behaviour of SDK by setting these optional parameters,

  • Disable Location Checks
    To disable location checks, initialize the SDK by passing the optional parameter disableUserLocationTracking. By default this is enabled to allow accurate location information to be sent to the API. If you disable it, you will be limited to just the country of the device. To disable, you can set:

        PushSDK.init(context = this, disableUserLocationTracking = true)
                .setSecretKey(PUSH_SDK_SERVER_SECRET_KEY)  
                .setServerKey(PUSH_SDK_SERVER_API_KEY)  
                .build()
    
  • Specify content download option
    This option will configure the SDK to use the connectivity type specified to download the content. If that connection is not available, content will not be downloaded and the notification will be ignored.

        .setDownloadOption(ConnectivityMode.ALL)
    

    You can set different modes as below,

        enum class ConnectivityMode {  
            ALL,  
            WIFI,  
            MOBILE,  
            MOBILE_ROAMING,  
            MOBILE_NO_ROAMING  
        }
    
  • App version
    Optionally you can pass the current version of your app, this will be displayed in the dashboard for analytics purposes.

        .setAppVersion(BuildConfig.VERSION_NAME)
    
  • Notification banner icons
    These are small and large icons that can be configured to use your app icons:

        .setSmallIcon(R.mipmap.ic_launcher)   
        .setLargeIcon(R.mipmap.ic_launcher)
    
  • Notification title text color
    Customize the notification banner title text color based on your brand:

        .setColor(R.color.colorPrimary)
    

Step 5 - Extend PushSDKActivity on your launcher activity

Open your application root activity normally called as MainActivity and update it to extend PushPollActivity:

    class MainActivity : PushSDKActivity() {
     .. your code goes here
      }

Display the last recieved video content
The content that was attached to the most recent notification can be replayed using this call,

PushSDK.launchVideo(Activity activity)

Display the content in your own embeded player
Optionally you can retrieve the last attached content and any metadata associated with it from the with

    PushSDK.getContents { filePath, name, expiry, metadata ->  
      //Your code goes here
    }
    PushSDK.getContents((filePath, name, expiry, metadata) -> {  
        //Youc an process the parameters here
     return Unit.INSTANCE;  
    }  
    );

And that's it. If you build and run, you will get prompted to allow notifications and the device will register to our API and you can start pushing!