Read the first part of this article from the following link.

Introduction

One Signal notification is one hundred percent free and gives unlimited access for mobile and web applications. One Signal offers cross-platform support and is a secure and reliable push notification delivery service.
In this article, I will show you how to deliver push notifications using One Signal in Android application. Android is a kernel-based operating system in which users can modify the GUI components and source code.
Requirements
Steps to be followed
Carefully follow the below steps to enable push notification delivery using One Signal in your Android application. I have included the source code too for download.
Step 1
Go to app, open build.gradle, and add the below lines in your dependencies.
  1. compile 'com.android.support:appcompat-v7:25.3.1'
  2. compile 'com.android.support.constraint:constraint-layout:1.0.2'
  3. compile 'com.google.android.gms:play-services:8.1.0'
  4. compile 'com.google.android.gms:play-services-ads:8.1.0'
  5. compile 'com.google.android.gms:play-services-identity:8.1.0'
  6. compile 'com.google.android.gms:play-services-gcm:8.1.0'
  7. compile 'com.onesignal:OneSignal:2.+@aar'
  8. compile 'com.google.android.gms:play-services-analytics:8.1.0'
  9. compile 'com.google.android.gms:play-services-location:8.1.0'
  10. testCompile 'junit:junit:4.12'
Android
Step 2
Then, add the below lines to you defaultconfig in build.gradle below the versionName.
  1. manifestPlaceholders = [manifestApplicationId: "${applicationId}",
  2. onesignal_app_id: "OneSignal App ID",
  3. onesignal_google_project_number: "GCM Project ID"]
  4. estInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Android
Step 3
Go to the below link and click Login button.
Link: https://onesignal.com/#pricing
Android
Step 4
Login via your Gmail Id.
Android
Step 5
Type your app and click "Create".
Android
Step 6
Open your project, go to "App Settings", and click "Configure" in Google Android.
Android
Step 7
Copy your Google server and sender key from Firebase account and paste that key in One Signal Settings; then click "Save".
Android
Step 8
Copy your One Signal app id and paste that into the build.gradle file. After that, click on "Synchronize" the project.
Android
Step 9
In the MainActivity.java file, copy and paste the below code. Do not replace your package name otherwise, the app will not run.
MainActivity.java code
  1. package ganeshannt.onesignal;
  2. import android.os.Bundle;
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.util.Log;
  5. import com.onesignal.OneSignal;
  6. import org.json.JSONObject;
  7. public class MainActivity extends AppCompatActivity {
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. OneSignal.startInit(this).setNotificationOpenedHandler(new ExampleNotificationOpenedHandler())
  12. .init();
  13. setContentView(R.layout.activity_main);
  14. }
  15. // This fires when a notification is opened by tapping on it or one is received while the app is running.
  16. private class ExampleNotificationOpenedHandler implements OneSignal.NotificationOpenedHandler {
  17. @Override
  18. public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
  19. try {
  20. if (additionalData != null) {
  21. if (additionalData.has("actionSelected"))
  22. Log.d("OneSignalExample", "OneSignal notification button with id " + additionalData.getString("actionSelected") + " pressed");
  23. Log.d("OneSignalExample", "Full additionalData:\n" + additionalData.toString());
  24. }} catch (Throwable t) {
  25. t.printStackTrace();
  26. }
  27. }}}
Step 10
Click the "Make Project" option and run the app.
Android
Deliverables
Here, we have successfully created and executed the Push Notification Delivery, using One Signal in Android application.
Android
Android
Android
Android
Android
Thank you for reading my article.
Don’t forget to like and follow me. If you have any doubts, just comment below.