Free Push Notification using onesignal - Android Part 1

OneSignal

OneSignal is a high volume and reliable push notification service for websites and mobile applications.

Why should I use OneSignal?


  • EASY TO USE
  • FREE
  • PLATFORM SUPPORT
  • ADVANCED FUNCTIONALITY
  • AUTOMATED NOTIFICATIONS
  • UNLIMITED










Onesignal screenshots:








Android Setup:


This tutorial only for Android studio Projects.you can use amazon SDK also.
Before going to setup one signal SDK we need to get Google server API key.



 Gradle Setup :

Open your build.gradle (Module: app) file and add the following to your dependencies.

dependencies {
    // OneSignal SDK
    compile 'com.onesignal:OneSignal:[3.5.3,4.0.0)'
}
In the same build.gradle file, 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"]
    }
 }



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.startInit(this)
        .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
        .unsubscribeWhenNotificationsAreDisabled(true)
        .init();
     
      // Call syncHashedEmail anywhere in your app if you have the user's email.
      // This improves the effectiveness of OneSignal's "best-time" notification scheduling feature.
      // OneSignal.syncHashedEmail(userEmail);
   }
}

we will see how to send Push notification to particular device on next tutorial

Free Push Notification using onesignal - Android Part 2

Comments

Popular posts from this blog

Kotlin - The official language for android development.

Free Push Notification using onesignal - Android Part 2

Android DatePicker Example