close
The Wayback Machine - https://web.archive.org/web/20211010215855/https://documentation.onesignal.com/docs/android-sdk-setup

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

Instructions for adding the OneSignal Android Mobile App SDK to your Android or Amazon Kindle Fire Apps using Android Studio.

Step 1. Requirements

Step 2. Add OneSignal Gradle Plugin and SDK

2.1 Open your root build.gradle (Project: name) file, add the following.

  • Under buildscript > repositories add (before jcenter)
    • mavenCentral()
    • gradlePluginPortal()
  • Under buildscript > dependencies add
    • classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
  • Under allprojects > repositories add (before jcenter)
    • mavenCentral()
buildscript {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
        jcenter()
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10, 0.99.99]'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
}
BERJAYABERJAYA

2.2 Open your App build.gradle (Module: app) file, add the following under buildscript {...} and above 'com.android.application'.

plugins {
    id 'com.onesignal.androidsdk.onesignal-gradle-plugin'
    // Other plugins here if pre-existing
}

2.3 Add the following to your dependencies section.

dependencies {
    implementation 'com.onesignal:OneSignal:[4.0.0, 4.99.99]'
}
BERJAYABERJAYA

πŸ‘

Sync Gradle

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

Step 3. Add Required Code

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

If you don't have an Application class follow our Create Application Class Guide.

Note: The ONESIGNAL_APP_ID can be found in the dashboard Settings > Keys & IDs

import com.onesignal.OneSignal;

public class MainApplication extends Application {
    private static final String ONESIGNAL_APP_ID = "########-####-####-####-############";
  
    @Override
    public void onCreate() {
        super.onCreate();
        
        // Enable verbose OneSignal logging to debug issues if needed.
        OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE);
        
        // OneSignal Initialization
        OneSignal.initWithContext(this);
        OneSignal.setAppId(ONESIGNAL_APP_ID);
    }
}
import com.onesignal.OneSignal

const val ONESIGNAL_APP_ID = "########-####-####-####-############"
  
class MainApplication : Application() {
   override fun onCreate() {
      super.onCreate()
        
      // Logging set to help debug issues, remove before releasing your app.
      OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE)
      
      // OneSignal Initialization
      OneSignal.initWithContext(this)
      OneSignal.setAppId(ONESIGNAL_APP_ID)
   }
}

Step 4. Customize the default notification icons ( strongly recommended )

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

BERJAYABERJAYA

Step 5. Run Your App and Send Yourself a Notification

Run your app on a physical device to make sure it builds correctly.

Your Android device should already be subscribed to push notifications. Check your OneSignal Dashboard Audience > All Users to see your Device Record.

Then head over to Messages > New Push to Send your first Push Notification from OneSignal.

πŸ“˜

Troubleshooting

If running into issues, see our Android troubleshooting guide.

Try the example project on Github.

If stuck, contact support directly or email [email protected] for help.

For faster assistance, please provide:

  • Your OneSignal App Id
  • Details, logs, and/or screenshots of the issue.
  • Steps to reproduce

πŸ‘

Setup Complete!

Visit Mobile Push Tutorials for next steps.

BERJAYA Updated about a month ago



Android SDK Setup


Instructions for adding the OneSignal Android Mobile App SDK to your Android or Amazon Kindle Fire Apps using Android Studio.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.