Enabling Android Push Notifications

You enable Android push notifications for an existing or a new push channel on the Channels page.

Before you continue with the setup, verify that you have the following:

An Android app with minSdk no earlier than 21 (Android 5) and targetSdk no later than 33 (Android 13)
The Sender ID and Server Key parameters from Firebase
The google-services.json file from Firebase
A device with Android 5.0 or higher or an Android emulator with the Google Play services
A current version of Android Studio

Note that the process that follows assumes that you have already completed the steps described in the Adding Push Channels article.

Step 1. Enter App Data from Firebase

  1. Register the app in Firebase.
  2. Obtain the Sender ID and Server Key parameters in Firebase.
  3. On the Settings > Channels > Setting Android Application page in the edna Pulse, enter the name of the app, the Firebase sender ID, and the Firebase API key.



    If you need to enable a Huawei app, refer to this article.
  4. Click Save and Continue.

Step 2. Add Dependencies to build.gradle File

  1. Add dependencies to the project’s build.gradle file — specify the edna repository address and add Google services to the list of dependencies.
  buildscript {  
      //...
    dependencies {
        //...
        classpath "com.google.gms:google-services:4.3.10"
    }
    //...
  allprojects {
    repositories {
       //...
        maven { url 'https://maven-pub.edna.ru/repository/maven-releases'}
    }
}
  1. To the build.gradle file of the app, apply the plugin, and add the edna library to the list of dependencies.
      apply plugin: 'com.google.gms.google-services'
      dependencies {
         //...
         implementation platform("com.edna.android:push-x-bom:2.0.0")
      }
  1. Specify the app unique access key for the edna push services in app manifest:
<meta-data android:name="com.pushserver.android.appId" 
android:value="unique edna access key from Step 2 App Settings" />
  1. Add the google-services.json file to the root of the app directory of your app in Android Studio.

  2. The edna library is initialized automatically. However, if Configuration.Provider is implemented in the app, you should use manual initialization.

Step 3. Add Code for Processing Notification Taps

If a client taps a notification or its action button, the app launches. The edna library processes the tap-through data and passes Intent to the app’s start Activity. You need to process the data received from the edna library in the app’s onCreate and onNewIntent methods. The edna library passes an action string you specified in the broadcast to Intent.

Following is an example of the code for processing a client’s notification tap-through:

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //...
        intent?.extras?.getParcelable<PushAction>(PUSH_ACTION_KEY)?.let {
        // Client navigation based on the passed string with PUSH_ACTION_KEY = "action"
            redirectUser(it.action)
        }
        //...
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        //...
        intent?.extras?.getParcelable<PushAction>(PUSH_ACTION_KEY)?.let {
        // Client navigation based on the passed string with PUSH_ACTION_KEY = "action"
            redirectUser(it.action)
        }
        //...
    }
}
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PushAction extraAction = getIntent().getExtras().getParcelable(PUSH_ACTION_KEY);
    // Client navigation based on the passed string with PUSH_ACTION_KEY = "action"
        redirectUser(extraAction);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        PushAction extraAction = getIntent().getExtras().getParcelable(PUSH_ACTION_KEY);
    // Client navigation based on the passed string with PUSH_ACTION_KEY = "action"
        redirectUser(extraAction);
    }
}

Step 4. Support Registration of Client Devices in edna

  1. Select the type of how the device is registered on the platform.

    A client’s device appears in edna after it is registered. Two methods – automatic or manual – are possible. For now, only the automatic registration is available, but the manual type will be added soon as well.
    • With automatic registration, the edna library registers the device in edna by itself. This method is simpler, it does not require you to manage the registration process, but it is not recommended for sending confidential data.
    • Once the manual type is available, your backend will be able to register the client’s device in edna using a specific API method.
  2. To register a client in edna, call the login library method specifying ID and SubscriberIdType of the client. Call the method only after the client is successfully authorized in your app.
PushX.login("79001002030", SubscriberIdType.PHONE_NUMBER)
PushX.login("79001002030", SubscriberIdType.PHONE_NUMBER.INSTANCE)

The following types of SubscriberIdType are available:

  • Phone number (PhoneNumber)
  • Email address (Email)
  • IDs in Facebook, Telegram, Google, Apple, Yandex (FacebookId, TelegramId, GoogleId, AppleId, YandexId)
  • Internal user IDs (ExtUserId, CookieId)
  • UTM tag (UTM)
  1. When the user is deauthorizing, call the logout library method to log out the device from edna:
PushX.logout()

Step 5. Compile and Launch App

  1. Connect the device to the Internet to check the integration.
  2. Compile and launch the app.
  3. After the app is launched, on the Settings > Channels > Setting Android Application page in the edna Pulse, click Save and continue. A page with step 6 will open, you need to wait until the registration process is completed.

Step 6. Check Device Connection and Test Receiving Push Notifications

In this step, edna helps you verify the integration has been completed correctly. If it has, you will see the name of your test device and the button to send a test push notification. Note that if you launched the app on several devices, you will only see the last connected one.

  1. Click Test push notifications.
  2. Verify the push notification is delivered and displayed on your test device.
  3. If yes, confirm receiving the push by clicking Yes.

All done! You can now create a cascade and set up a broadcast using this push channel.