OneSignal Help & Documentation

Welcome to the OneSignal New IA developer hub. You'll find comprehensive guides and documentation to help you start working with OneSignal New IA as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Discussions

Android SDK Setup

OneSignal Android SDK Setup Guide. Also for Amazon apps using Android Studio.

For Developers

Required For Setup


1. Gradle Setup

1.1 Open your app/build.gradle (Module: app) file, add the following to the very top.

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.11.0, 0.99.99]'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven { url 'https://maven.google.com' }
}

1.2 Add the following to your dependencies section.

dependencies {
    implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'
}

1.3 Add the following in your android > defaultConfig section.

  • Update PUT YOUR ONESIGNAL APP ID HERE with your OneSignal app id
android {
   defaultConfig {
      manifestPlaceholders = [
          onesignal_app_id: 'PUT YOUR ONESIGNAL APP ID HERE',
          // Project number pulled from dashboard, local value is ignored.
          onesignal_google_project_number: 'REMOTE'
      ]
    }
 }

Sync Gradle

Make sure to press "Sync Now" on the banner that pops up after saving!


2. Add Required Code

2.1 Add the following to the onCreate method in your Application class.

import com.onesignal.OneSignal;

public class YourAppClass extends Application {
   @Override
   public void onCreate() {
      super.onCreate();
     
      // OneSignal Initialization
      OneSignal.startInit(this)
        .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
        .unsubscribeWhenNotificationsAreDisabled(true)
        .init();
   }
}
import com.onesignal.OneSignal

class YourAppClass : Application() {
   override fun onCreate() {
      super.onCreate()
      
      // OneSignal Initialization
      OneSignal.startInit(this)
         .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
         .unsubscribeWhenNotificationsAreDisabled(true)
         .init()
   }
}

3. Create a custom default notification icon

3.1 By default, notifications will be shown with a bell icon in the notification shade. Follow the Customize Notification Icons guide to create a your own small notification icon for your app.


Troubleshooting

If run into any issues please see our Android troubleshooting guide, or our general Troubleshooting section.


4. Add Email

Recommended

Next, if you collect emails from users, you can set a user's email with the setEmail method. This enables OneSignal Email Messaging, which allows you to send emails in addition to push.

OneSignal.setEmail("example@domain.com");

If you have a backend server, we strongly recommend using Identity Verification with your users. Your backend can generate an email authentication token and send it to your app or website. The following code also includes callbacks:

String email = "example@domain.com";
String emailAuthHash = "..."; // Email auth hash generated from your server
OneSignal.setEmail(email, emailAuthHash, new OneSignal.EmailUpdateHandler() {
  @Override
  public void onSuccess() {
    // Email successfully synced with OneSignal
  }

  @Override
  public void onFailure(OneSignal.EmailUpdateError error) {
    // Error syncing email, check error.getType() and error.getMessage() for details
  }
});

Additional email methods are available in the Android Native SDK

You're Done!

Next up: Send your first push notification via the OneSignal Dashboard


Notification Features

To configure notifications features, go to Features Setup.

Notification Handlers

NotificationOpenedHandler - This will be called when a notification is tapped on.
See our setNotificationOpenedHandler documentation to add one.

NotificationReceivedHandler - This will be called when a notification is received.
See our setNotificationReceivedHandler documentation to add one.

NotificationExtenderService - This service can be setup to receive notifications no matter if your app is running or not. It can be used override how notifications are shown in the notification shade or to process data silently without showing a notification. See the Background Data and Notification Overriding section to set this up.