Kotlin

PushExpress -- SDK Kotlin

You will need to integrate your Push.Express account with Firebase.

Setup Firebase

  1. Go to Firebase Console and create a new project (or use existing one)

    You can use one project for all your apps.

  2. Open Project Settings -> General

  3. Create new Android app or just download google-services.json from existing app

If you need to create new app, just:

  • Register it

  • Download google-services.json

  • Press next-next-next =)

  1. Put google-services.json to your app dir (like <project>/app/google-services.json)

  2. Add the plugin as a dependency to your project-level build.gradle.kts file: Root-level (project-level) Gradle file (/build.gradle.kts)::

  3. In your module (app-level) Gradle file (<project>/<app-module>/build.gradle.kts), add the Firebase Cloud Messaging dependency:

Full official instructions can be found in Firebase Cloud Messaging Android guide.

Setup Push.Express

Get Firebase Private key

  1. Go to Firebase Console and create a new project (or use existing one)

    You can use one project for all your apps.

  2. Open Project Settings

  3. Go to Service accounts, press Generate new private key and save it to file private-key.json (you can use same key for all apps)

Integrate your Push.Express App with Firebase

  1. Go to your Push.Express account

  2. Open existing App settings or create a new App

  3. Switch type application Firebase

  4. Paste private-key.json file to Firebase Admin SDK private key textbox

Add sdk in your application

Before proceeding with the integration, make sure you have already installed the Firebase SDK in your application. If not, follow steps 4-6 in the Firebase Cloud Messaging integration guide

Add the JitPack repository to your build file

Ensure you have the latest Android Studio and Android Gradle Plugin!

In your settings.gradle.kts, add the Jitpack repo to repositories list (only if you use Gradle Centralized Repository Declaration feature, default for new projects since Android Studio Electric Eel):

Alternatively, if you use old `allprojects` style

In your root-level (project-level) Gradle file (<project>/build.gradle), add the Jitpack repo to repositories list:

Add Push.Express SDK dependency

In your module (app-level) Gradle file (<project>/<app-module>/build.gradle), add the pushexpress-android-sdk dependency:

Add AndroidManifest.xml

To correctly open links from push notifications in the app, add an Intent filter:

You can also set the default values for small icon and large icon in AndroidManifest.xml:

Add required code

  1. Get your PUSHEXPRESS_APP_ID from Push.Express account page

  2. Create MyFirebaseMessagingService.kt

  1. Add code SDK Initialization in MainActivity

  1. Login logout functionality

    To create different accounts on the same device, use the sdk activation and decoding functionality. To log out of your account, use SdkPushExpress.deactivate(). To log in to another account, create a new setExternalId - SdkPushExpress.setExternalId("new_ext_id") run SdkPushExpress.activate(). Example of the implementation of login logout functions in MainActivity.kt:

  1. Example processing links from push notifications in MainActivity.kt

  1. Example MainActivity.kt

Last updated