Not receiving push notifications in my Android app

1.5k views Asked by At

I'm using the Matrix SDK to build a chat app but I'm not receiving any push notifications. This is my code

fun addPushNotification(context: Context, token: String?) {

    val pushCallback = object : ApiCallback<Void> {
        override fun onSuccess(info: Void?) {

            try {
                (context as BaseActivity<*, *>).showToasty(
                    ToastyType.SUCCESS,
                    "registerToThirdPartyServer succeeded"
                )

            } catch (e: Exception) {
                (context as BaseActivity<*, *>).showToasty(ToastyType.ERROR, "registerToThirdPartyServer failed")

            }
        }

        override fun onUnexpectedError(e: Exception?) {
            e?.let {
                it.message?.let {
                    (context as BaseActivity<*, *>).showToasty(ToastyType.ERROR, it)
                }
            }
        }

        override fun onMatrixError(e: MatrixError?) {
            e?.let {
                it.message?.let {
                    (context as BaseActivity<*, *>).showToasty(ToastyType.ERROR, it)
                }
            }
        }

        override fun onNetworkError(e: Exception?) {

            e?.let {
                it.message?.let {
                    (context as BaseActivity<*, *>).showToasty(ToastyType.ERROR, it)
                }
            }
        }
    }


    var session = getSession(context)
    session.pushersRestClient.addHttpPusher(
        token, "im.vector.app.android", computePushTag(session),
        "en", "myapp", "ay 7aga", "https://mylink/_matrix/push/v1/notify",
        true, true, pushCallback
    )
}

I do not know what's wrong. Is there anything I should add in the server to allow push notifications?

When I try to chat from Android to Riot running in the web browser, I receive a notification, but when I try to chat from Riot to my Android app I don't receive anything.

0

There are 0 answers