通过Firebase从python后端发送到Android应用程序的通知无法到达手机

2024-05-23 20:02:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经构建了一个安卓Android应用程序,可以从Firebase控制台接收通知,但现在我想让它通过Firebase从Python后端接收通知。所以我实际上想做的是从python发送到firebase,再从firebase发送到电话

这就是我用python编写的代码

    import firebase_admin
    from firebase_admin import credentials, messaging

    cred = credentials.Certificate(r'path/to/file')


    default_app = firebase_admin.initialize_app(cred)

    registration_token = "xxx"

    message = messaging.Message(
    notification=messaging.Notification(
        title="This is a notification",
        body="This is sent from python"
    ),
    data={
        'score': '850',
        'time': '2:45',
    },
    token=registration_token
    )

    response = messaging.send(message)

    print("Succesfully sent message", response)

我还从Firebase ajson生成了一个文件,该文件是我添加到变量'cred'中的项目中的

当我运行脚本时,我得到:

Succesfully sent message projects/test1-80ea2/messages/0:158...

但是android studio模拟器在手机上没有显示任何内容。你能帮我怎么做吗

提前谢谢


Tags: fromimporttokenappmessageadminnotificationregistration