Pushologies Android SDK Integration
This guide will walk you through getting our SDK integrated with your app. Please make sure you've already generated your Firebase credentials and have checked the prerequisites.
Prerequisites
-Minimum gradle version 7.4
-Target SDK level is 33
-Compile SDK version is 33
-Minimum SDK level is 21
Integration
- Add Pushologies sdk to your project. Add the Jitpack publishing url to the repositories block of your gradle file depending upon your needs,
- In
settings.gradle
- In
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
...
maven { url "https://jitpack.io" }
}
}
- In project level
build.gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
- In app level
build.gradle
repositories {
...
maven { url "https://jitpack.io" }
}
dependencies {
implementation 'com.pushologies:pushsdk-android:4.3.0'
}
Note: You need to add -keep class com.pushologies.** { *; }
to your ProGuard rules file in case you are using it.
-
Since this SDK uses Firebase Cloud Messaging (FCM) for push notifications, initialise the Firebase SDK if you have not already initialised. See Setup FCM Client Android App
-
Initialise the PushSDK
private fun initPushSDK() {
FirebaseApp.initializeApp(this)
PushSDK.init(
application = this,
PushConfig(
apiKey = <API KEY>,
apiSecret = <API SECRET>,
enableDebug = true,
appVersion = <APP VERSION>,(Optional field)
enableGeofence = true,
customerId = <YOUR CUSTOMER ID>,(Optional field)
trackLocation = true,
downloadConnectionType = ConnectionType.WIFI,
activeGeofenceLimit = 20 (Optional field)
),
//Optional
PushTheme(
largeIconRes = <LARGE NOTIFICATION ICON>,
smallIconRes = <SMALL NOTIFICATION ICON>,
color = R.color.black
)
)
appVersion(appVersion : String)
to set the current version of your app. This will be displayed in the dashboard for analytics.enableDebug(enable:Boolean)
to enable debug mode. This provides more logs on the console, disable this on production buildscolor(color: Int)
to customize the notification banner title text color based on your brandsmallIconRes(iconId: Int)
&largeIconRes(icon: Int)
can be used to configure small and large icon of notification bannerdownloadConnectionType(connectivityMode: ConnectivityMode)
is used to configure the SDK to use the connectivity type specified to download the content, if that connection is not available content will not be downloaded. You can use following enum valuescustomerId(customerId: String)
is to set the customer Id to know which client is using the apptrackLocation(enable:Boolean)
is to set to true if the user's location should be sent as part of metadata. Please make sure to request appropriate run time permissions to achieve this.
Use the below ENUMS to set the connection type while initialising the push SDK
enum class ConnectionType {
ALL,
WIFI,
MOBILE,
MOBILE_ROAMING,
MOBILE_NO_ROAMING
}
- Request geofence related location permissions if required
PushSDK.requestGeofencePermission(this)
- Set Firebase token in PushSDK
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
if (!task.isSuccessful) {
[email protected]
}
task.result?.let { token ->
PushSDK.setFCMToken(token)
}
}
- Add the service that extends
FirebaseMessagingService
as per Step 3 to your app. Add the following code to that service
class DemoFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if (PushSDK.isPushologiesMessage(remoteMessage.data)) {
PushSDK.handlePushMessage(remoteMessage.data)
}
}
override fun onNewToken(token: String) {
super.onNewToken(token)
PushSDK.setFCMToken(token)
}
}
Now you are all set to receive the Pushologies notifications
Additional APIs
- To work with tags, you need to use following APIs
- To create a tag use the API below, Note that a tag is created only if it doesn't exist on the portal already, if it exists it just subscribes your device to that tag. You can use tags to create segments, and target your devices subscribed to those tags. Note that currently we only support creating of one tag at time, so if you want to create multiple tags you will need to call this API multiple times
fun createTag(tag: String, apiCompletionHandler: APICompletionHandler = { _: String? -> })
- To delete the tag use the API below. Please note that it doesn't delete the tag on the portal, it just unsubscribes your device from that tag.
fun deleteTag(tag: String, apiCompletionHandler: APICompletionHandler = { _: String? -> })
- Example code
- To create a tag use the API below, Note that a tag is created only if it doesn't exist on the portal already, if it exists it just subscribes your device to that tag. You can use tags to create segments, and target your devices subscribed to those tags. Note that currently we only support creating of one tag at time, so if you want to create multiple tags you will need to call this API multiple times
PushSDK.createTag(tag) { error ->
showCreateTagResult(error)
}
PushSDK.deleteTag(tag) { error ->
showDeleteTagResult(error)
}
PushSDK.createTag("tag", error -> {
showCreateTagResult(error);
return;
});
PushSDK.deleteTag("tag", error -> {
showDeleteTagResult(error);
return;
});
Show In-App Notifications (custom triggered)
By calling this method and passing the custom event identifier string as parameter, the app will show any active in-app notification already received and stored in the app.
PushSDK.showInAppNotification("YourIdentifierHere", object : PushSDKResponse<String> {
override fun onSuccess(result: String) {
TODO("Not yet implemented")
}
override fun onError(throwable: Throwable) {
TODO("Not yet implemented")
}
})
PushSDK.INSTANCE.showInAppNotification("<CustomIdentifier>", new PushSDKResponse<String>() {
@Override
public void onSuccess(String result) {
...
}
@Override
public void onError(@NonNull Throwable throwable) {
...
}
});
Updated 5 days ago