Documentation: Push Notifications Onsite Messaging REST API
  1. Documentation
  2. Android App Push Notification
  3. Android SDK Setup

Android SDK Setup

Instructions for adding the PushAlert Android Mobile App SDK to your Android Apps using Android Studio.

Requirements - Before You Begin

Step 1: Add PushAlert Android SDK

  • In your app-level gradle file (usually <project>/app/build.gradle), add the following to the dependencies section.
    dependencies {
        ...
        implementation 'co.pushalert:android-sdk:1.0.0'
        
        //Required
        implementation platform('com.google.firebase:firebase-bom:30.1.0')
        implementation 'com.google.firebase:firebase-messaging'
        
        //Optional, required if you enable firebase analytics events logging
        //implementation 'com.google.firebase:firebase-analytics'
        
        //Optional, required if you enable location related functionality
        //implementation 'com.google.android.gms:play-services-location:21.0.0'
    }
    Copy
  • Click "Sync Now".

Step 2: Initialize PushAlert

  • Add the following code to the onCreate method in your Application class. If you don't have an Application class, you can follow steps available at Create Application Class for Android App.
    import co.pushalert.PushAlert;
    import android.os.Build;
    
    public class MyApplication extends Application {
    
        @Override
        public void onCreate() {
            super.onCreate();
            
            // Enable logging to debug issues if required. Disable on production.
            PushAlert.enableDebug(true);
            
            // PushAlert Initialization, you can get App ID from PushAlert Dashboard, Settings->App
            PushAlert.init("PUSHALERT_APP_ID", getApplicationContext());
            
            // Set Opt-in Mode for Android permission prompt
            // From Android 13 and above, request permission is required to send push notifications. We recommend TWO_STEP opt-in mode for Android 13 and above; otherwise AUTO opt-in mode.
            if (Build.VERSION.SDK_INT >= 33){
                PushAlert.setOptInMode(PushAlert.PAOptInMode.TWO_STEP);
            }
            else{
                PushAlert.setOptInMode(PushAlert.PAOptInMode.AUTO);
            }
        }
    }
    Copy

Step 3: Run Your App and Send Your First Notification

Run your app on an Android 4.4+ device or emulator with "Google Play Store (Services)" installed.

If setup correctly, you will get subscribed to push notifications on alowing permission. You can check from Analytics > Subscriber Information to see your Device Details. Also total numbers of subscribers on dashboard will increase by one.

Head to Send Notification > Send/Schedule and send your first notification.

Initial Troubleshooting

If subscriber count doesn't increase. Then check logcat with tag "PALogs".

  • ERR-PA9001: It seems dependencies are missing. Make sure that you have followed Step 1 correctly.
  • ERR-PA9002: It means Firebase configuration file (google-services.json) is missing or com.google.gms:google-services was not applied to your gradle project. Follow this guide.