chat Push Notification webview in android studio

Viewed 33

I build WebView app using android studio. we can chat feature in my website. I want to get push notification for chat messages. How can I get? Please help me. Thank you!

1 Answers

Setup Firebase Cloud Messaging in App

Get a Firebase device token and associate it with a user on the server.

Get your-app-firebase-adminsdk-aaaa-aaaaaaaaaa.json from Firebase Console and upload to your website

Python Example for sending message by Firebase Device Token

import firebase_admin  # pip3 install firebase-admin
from firebase_admin import credentials, messaging

firebase_admin.initialize_app(credentials.Certificate(
    "./your-app-firebase-adminsdk-aaaa-aaaaaaaaaa.json"))


def send_notification(token, title, message):
    msg = messaging.Message(token=token, notification=messaging.Notification(title, message),
                            data={"title": title, "message": message})
    print('Done:', messaging.send(msg))


if __name__ == "__main__":
    token = "qwertyuiopasdfghjklzxc:Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-aaaaaaaaaaaaaaaaaaaaaaaaaaaaa-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    send_notification(token, "Title", "Body")

don't forget to add access to notifications in the app

Related