Connecting the AppMetrica Push SDK

The Push SDK for Android is a library in the AAR format. The library is available in the Maven repository.

Since the AppMetrica Push SDK version 1.0.0, it uses the Firebase Cloud Messaging (FCM) service to send push notifications.

This section describes the steps to enable and initialize AppMetrica Push SDK:

  1. Step 1. Prepare your app
  2. Step 2. Enable the library
  3. Step 3. Initialize the library
  4. Step 4. Configuring Silent Push Notifications
  5. Step 5. (Optional) Enable push tokens update
  6. Sending additional information
  7. Detecting the application launch via push notification
  8. Setting the default icon

Step 2. Enable the library

Since version 1.4.0 to the Push SDK added the OKHttp library. The SDK uses it for caching images that are displayed in push notifications. Caching rules are taken from the cache-control HTTP header. If you do not want the images to be cached, connect the library without caching.

  1. In the build.gradle file add the following dependencies in the dependencies block:
    dependencies {
        ...
        implementation "com.yandex.android:mobmetricapushlib:1.5.1"
        implementation "com.google.firebase:firebase-messaging:19.0.1"
        implementation "com.google.android.gms:play-services-base:16.1.0"
        implementation "com.android.support:support-compat:28.0.0"
        ...
    }
    Copied to clipboard
    Note. The minimum version of support-compat is 26.0.0.
  2. Initialize Firebase using one of the following methods:

    Using Google Services Plugin
    1. Download the configuration file google-services.json and put it in the project module's directory (such as app).
    2. In order to work with the file correctly, enable the Google Services plugin in the project by adding the following lines to the build.gradle file:

      project
      buildscript{
          ...
          dependencies {
              ...
              classpath 'com.google.gms:google-services:4.3.0'
              ...
          }
          ...
      }
      Copied to clipboard
      application (module)
      // In the end of the file.
      apply plugin: 'com.google.gms.google-services'
      Copied to clipboard