Android SDK integration
Add BNotify to any Android app with JitPack, the Gradle config plugin, and a few lifecycle hooks. After setup, devices register automatically and can receive pushes plus in-app campaigns.
Before Gradle setup, create a project, add an Android app, and download bnotify-config.json. Place that file at app/bnotify-config.json, then continue below.
What you get after integration
| Capability | Result |
|---|---|
| Device registration | Device appears in the BNotify dashboard after init |
| Push receive | System tray notifications |
| System notification UI | Shown automatically by the SDK (default) |
| Click / dismiss analytics | Reported to BNotify |
| Token callback | OnTokenListener.onNewToken |
| In-app campaigns | Shown in-app when a campaign is due |
The Android SDK does not send notifications. Create and send campaigns from the BNotify dashboard. The SDK registers the device, displays messages, and reports engagement.
Prerequisites
| Requirement | Notes |
|---|---|
| Android Studio + Kotlin DSL | Examples use .kts |
minSdk ≥ 24 | Matches SDK |
| Internet on device | Required for registration and delivery |
| BNotify credentials | Download bnotify-config.json after you register the Android app in Console |
| Config fields | Use the values provided in the dashboard download |
| Physical device | Recommended for notification testing |
Integration checklist
- 1Add JitPack to
settings.gradle.kts - 2Add plugin classpath in project
build.gradle.kts - 3
implementationSDK +applyplugin in app module - 4Add
app/bnotify-config.json(downloaded from Console) - 5Sync Gradle → confirm
GeneratedConfig - 6Call
BNotifyApp.initializeBaseinApplication - 7Register custom
Applicationin manifest - 8
handleIntent+ token listener in launcher Activity - 9Subclass
BNotifyMessagingService(recommended) - 10Handle
screenextras for multi-screen routing
Step 1 — Repositories (settings.gradle.kts)
Add JitPack so Gradle can resolve the SDK and plugin. Merge into existing blocks if present.
pluginManagement {
repositories {
google {
content {
includeGroupByRegex("com\\.android.*")
includeGroupByRegex("com\\.google.*")
includeGroupByRegex("androidx.*")
}
}
mavenCentral()
gradlePluginPortal()
maven { url = uri("https://jitpack.io") }
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Step 2 — Plugin classpath (project build.gradle.kts)
plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
}
buildscript {
repositories {
maven(url = "https://jitpack.io")
}
dependencies {
classpath("com.github.bnotify.bnotifysdk:bnotifyplugin:1.0.5")
}
}
Library: com.github.bnotify.bnotifysdk:bnotifysdk:1.0.5
Plugin apply id: com.github.bnotifysdk.bnotifyplugin
Confirm on JitPack.
Step 3 — Dependency + plugin (app module)
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
}
android {
namespace = "com.example.yourapp"
compileSdk = 36
defaultConfig {
applicationId = "com.example.yourapp"
minSdk = 24
targetSdk = 36
}
}
dependencies {
implementation("com.github.bnotify.bnotifysdk:bnotifysdk:1.0.5")
}
apply(plugin = "com.github.bnotifysdk.bnotifyplugin")
On sync, the plugin reads app/bnotify-config.json and generates GeneratedConfig.kt under your applicationId package. Missing JSON fails the build with a clear error.
Step 4 — Add app/bnotify-config.json
Download this file from the Console after you register the Android app (see Create a project). Path required by the plugin: {projectRoot}/app/bnotify-config.json.
{
"projectId": "your-project-id",
"packageName": "com.example.yourapp",
"apiKey": "your-api-key",
"authDomain": "",
"databaseURL": "",
"storageBucket": "",
"messagingSenderId": "",
"appId": "your-app-id",
"measurementId": "",
"fcmAppId": "1:1234567890:android:abcdef",
"fcmProjectId": "your-firebase-project-id",
"fcmApiKey": "AIzaSy...",
"fcmSenderId": "1234567890"
}
| Field | Required | Used for |
|---|---|---|
projectId, appId, apiKey, packageName | Yes | Project / app identity |
fcmAppId, fcmProjectId, fcmApiKey, fcmSenderId | Yes | Included in the dashboard config file |
| Other fields | Optional | Reserved / future |
Step 5 — Application class
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
BNotifyApp.initializeBase(
this,
MainActivity::class.java,
GeneratedConfig.JSON.toString()
)
}
}
Call this once in Application.onCreate. It registers the device, enables notifications, and starts in-app messaging. If your SDK version exposes a four-argument overload (app, context, activity, json), pass applicationContext as the second argument.
Step 6 — Manifest
<application
android:name=".MyApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.YourApp">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyNotificationService"
android:exported="false" />
</application>
Use singleTop or singleTask on the click Activity so onNewIntent runs when the app is already open.
Step 7 — MainActivity wiring
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
BNotifyApp.handleIntent(applicationContext, intent)
BNotifyApp.setOnTokenListener(object : BNotifyApp.OnTokenListener {
override fun onNewToken(token: String?) {
Log.d("BNotify_Token", "BNotify Token: $token")
}
})
intent.getStringExtra("screen")?.let { screen ->
if (screen.equals("Test", true)) {
BNotifyApp.setActivityToOpenOnClick(TestActivity::class.java)
startActivity(Intent(this, TestActivity::class.java))
finish()
}
}
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(intent)
BNotifyApp.handleIntent(applicationContext, intent)
}
| Call | Why |
|---|---|
handleIntent | Permission path, click extras, service restart |
setOnTokenListener | Receives the BNotify device token after registration |
setActivityToOpenOnClick | Which Activity future taps should open |
onNewIntent | Required when app is already in memory |
Step 8 — Custom MessagingService
class MyNotificationService : BNotifyMessagingService() {
override fun activityToOpenOnClick(): Class<out Activity> {
return MainActivity::class.java
}
override fun onMessageReceived(remoteMessage: NotificationModel?) {
Log.i("BNotify", "title: ${remoteMessage?.title}")
// Custom UI when auto-notifications are disabled
}
}
Notification permission (Android 13+)
The SDK declares POST_NOTIFICATIONS. For better UX, also request from your Activity:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ActivityCompat.requestPermissions(
this,
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
1001
)
}
Screen / deep routing
Send a screen field in the notification payload. The SDK places it in click Intent extras — your app decides navigation (home, Test, or any custom route).
In-app messaging
In-app campaigns appear inside the app (modal, card, top banner, fullscreen, and image). They can still show if the user denied system notification permission, as long as initializeBase has run and the device is online.
Verification
- Install on a physical device with network access.
- Confirm logs show the BNotify token callback.
- Send a test push from the BNotify dashboard.
- Tap the notification → Activity opens → click event tracked.
- Bring the app to the foreground and confirm an in-app campaign appears if one is scheduled.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| Gradle cannot resolve artifact | Missing JitPack repo | Add maven { url = uri("https://jitpack.io") } to both management blocks |
No bnotify-config.json | Wrong path | File must be app/bnotify-config.json |
| No tray notification on API 33+ | Permission denied | Request POST_NOTIFICATIONS |
| Tap does nothing when app open | Missing onNewIntent | Forward intent + use singleTop |
| No device on dashboard | Bad credentials / network | Verify the config JSON and that the device is online |
See the FAQ or contact support at bnotify93@gmail.com.