Notifications (Android SDK - Kotlin)

Clicks Tracking

Add click tracking to the activity creation method.

if (intent.extras != null) {
    sdk.notificationClicked(intent.extras)
}


How To Use

Example show notification with download icon:

object : AsyncTask<String?, Void?, Bitmap?>() {
    override fun doInBackground(vararg params: String?): Bitmap? {
        try {
            val inputStream = URL(params[0]).openStream()
            return BitmapFactory.decodeStream(inputStream)
        } catch (e: IOException) {
            e.printStackTrace()
        }
        return null
    }

    override fun onPostExecute(result: Bitmap?) {
        super.onPostExecute(result)

        val intent = Intent(applicationContext, MainActivity::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)

        //REQUIRED! For tracking click notification
        intent.putExtra(PersonaClick.NOTIFICATION_TYPE, data["type"])
        intent.putExtra(PersonaClick.NOTIFICATION_ID, data["id"])

        val pendingIntent = PendingIntent.getActivity(applicationContext, 0, intent,
            PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE)

        val notificationBuilder = NotificationCompat.Builder(applicationContext, getString(R.string.notification_channel_id))
            .setSmallIcon(R.mipmap.ic_launcher)
            .setLargeIcon(result)
            .setStyle(NotificationCompat.BigTextStyle().bigText(data["body"]))
            .setContentTitle(data["title"])
            .setContentText(data["body"])
            .setAutoCancel(true)
            .setContentIntent(pendingIntent)

        val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
        notificationManager.notify(0, notificationBuilder.build())
    }
}.execute(data["icon"])



Token Send

Method Objective

The method allows manually sending an Android push notification token to the system.

The SDK sends a token to the system automatically. You can use this method if you need to send the token forcibly yourself.

Syntax and parameters

sdk.registerManager.setPushTokenNotification(token, callback);
NameTypeRequirementDescription
tokenstringrequired

Android push notification token

callbackfunctionoptionallyThe callback function to which the API response will be passed

Example of use

sdk.registerManager.setPushTokenNotification(
    token = "93b033a394da31b3160b8e0a35b80b6c16eb99a22ed34e88afe2a117dd4bc601",
    listener = object : OnApiCallbackListener() {
        override fun onSuccess(msg: JSONObject?) {
            // API response processing functionality
        }
    }
)



Payloads

The Payloads structures are available under Push Payloads (Mobile SDKs).

Copyright 2018-2024 PersonaClick