Skip to content

pushbots/Huawei-sample

Repository files navigation

pblogo

Android SDK Setup

PushBots Android SDK setup guide.

What we do?

PushBots is a push notification service that help you manage notifications on all platforms (Android, iOS, Web, react-native, cordova) efficiently and easily.

Required For Setup:-

client id

Setup PushBots

1. Adding PushBots Dependencies

build.gradle(project)
allprojects {
    repositories {
        maven { url 'http://developer.huawei.com/repo/' }
    }
}
build.gradle
implementation 'com.pushbots:pushbots-lib:3.3.0@aar'
implementation 'com.huawei.hms:push:4.0.0.300'
implementation 'com.google.android.gms:play-services-location:17.0.0' // optional

2. Integrate with PushBots dashboard

Add to defaultConfig section, then replace PUSHBOTS_APP_ID and HUAWEI_CLIENT_ID

build.gradle
defaultConfig {
        // Add PushBots integration data
        manifestPlaceholders = [
                pushbots_app_id               : "YOUR_APP_ID",
                pushbots_loglevel             : "DEBUG",
                google_sender_id              : "YOUR_CLIENT_ID"
        ]

    }

Set your app-id that you get from HMS console in your manifest:

Manifest.xml
 <meta-data
            android:name="com.huawei.hms.client.appid"
            android:value="appid=YOUR_HMS_APP_ID" />

3. Initialize PushBots

PushBots should be initialized when app just started, one of the existing ways is to initialize it in our application.

MyApplication.kt
import android.app.Application
import com.pushbots.push.Pushbots

class MyApplication : Application() {
   override fun onCreate() {
        super.onCreate()
        // Initialize Pushbots Library
        Pushbots.sharedInstance().init(this)
   }
}

Now add your Application to Manifest.xml

AndroidManifest.xml
 <application
     android:name=".MyApplication">
 </application>

Now you have initialized PushBots successfully, BUT there is one more step to be able to receive notifications.

You need to register for it (You may register for it inside you MyApplication.class or MainActivity.class):

MainActivity.kt
//Register for Push Notifications
Pushbots.sharedInstance().registerForRemoteNotifications()

Things you can do using PushBots:-

  • You can set device info so you can recognize/manage users on dashboard easily i.e:

MainActivity.kt
Pushbots.setEmail("abc@pushbots.com")
Pushbots.setName("PUSH BOTS")
Pushbots.setAlias("PUSHER")

Now you can manage users easily on dashboard.

alias

Use our plugin to fix dependencies conflicts

plugins {
  id "com.pushbots.android.plugin.pushbots-gradle-plugin" version "1.0-SNAPSHOT"
}
buildscript {
  repositories {
   maven { url "https://plugins.gradle.org/m2/" }
  }

// Inside your app.build.gradle
dependencies {
   classpath "gradle.plugin.com.pushbots:pushbots-gradle-plugin:1.0-SNAPSHOT"
  }
}


apply plugin: "com.pushbots.android.plugin.pushbots-gradle-plugin"

AndroidX Migration

If your project is using AndroidX you will need to make sure Jetifier is enabled to be compatible with PushBots. In your gradle.properties file, set the following two flags to true

gradle.properties
android.useAndroidX=true
android.enableJetifier=true