如何根据 android 应用程序上的微调器值发送通知?
How to send a notification based on spinner value on android app?
我正在做关于洪水推送通知的最后一年项目。以前,每当数据库中的值从 0 变为 1 时,用户都会检索通知。但是现在,在我的应用程序中,用户可以选择他把车停在哪里,他可以根据公园的位置检索状态和通知,无论是零个或一个。例如,用户 A 在 Mid Valley 中设置他的微调器值,而用户 B 在 KPS 中设置他的微调器值。当 FLOOD_STATUS_MID_VALLEY 为 1 时,用户 A 将收到通知,而用户 B 未收到任何通知,因为 FLOOD_STATUS_KPS 仍为 0。任何人都可以帮助我了解如何根据应用程序中的微调器值发送通知?
我的应用截图
Screenshot
下面是 运行 服务器上的 python 代码,用于根据 firebase 数据库
中名为 "FLOOD_STATUS" 的值发送通知
from pusher_push_notifications import PushNotifications
config = {
'apiKey': "APIKEY",
'authDomain': "car-app-push-notification.firebaseapp.com",
'databaseURL': "https://car-app-push-notification.firebaseio.com",
'projectId': "car-app-push-notification",
'storageBucket': "car-app-push-notification.appspot.com",
'messagingSenderId': "596729642105",
'appId': "APPID",
'measurementId': "G-9LMJGS1BDW"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
beams_client = PushNotifications(
instance_id='49f62b05-bd81-4040-ab57-80afa56a8680',
secret_key='SECRET KEY',
)
def stream_handler(message):
print(message)
if(message['data'] is 1):
response = beams_client.publish_to_interests(
interests=['hello'],
publish_body={
'apns': {
'aps': {
'alert': 'Hello!',
},
},
'fcm': {
'notification': {
'title': 'Alert!',
'body': 'It is starting to flood, please remove your car immediately!',
},
},
},
)
print(response['publishId'])
my_stream = db.child("FLOOD_STATUS").stream(stream_handler,None)
由于这是你的 FYP,我不会为此提供任何代码。
当用户改变他们停车的地方[=23=]时,您需要改变他们的设备兴趣以匹配相关位置。
当FLOOD_STATUS
更新为1
给定位置时,您发送通知匹配兴趣.
我建议,当用户A select MID_VALLEY
在Spinner
你发送selected 值到服务器。我建议您查看 this tutorial 以了解如何从 Spinner
获取 selected 值
在服务器端,当 FLOOD_STATUS_MID_VALLEY
为 1 时,您只向用户 A 发送通知(因为您知道用户 A 的 FCM token
)。
如果你想自定义 Spinner 的项目,你可以观看 this tutorial。
我正在做关于洪水推送通知的最后一年项目。以前,每当数据库中的值从 0 变为 1 时,用户都会检索通知。但是现在,在我的应用程序中,用户可以选择他把车停在哪里,他可以根据公园的位置检索状态和通知,无论是零个或一个。例如,用户 A 在 Mid Valley 中设置他的微调器值,而用户 B 在 KPS 中设置他的微调器值。当 FLOOD_STATUS_MID_VALLEY 为 1 时,用户 A 将收到通知,而用户 B 未收到任何通知,因为 FLOOD_STATUS_KPS 仍为 0。任何人都可以帮助我了解如何根据应用程序中的微调器值发送通知?
我的应用截图 Screenshot
下面是 运行 服务器上的 python 代码,用于根据 firebase 数据库
中名为 "FLOOD_STATUS" 的值发送通知from pusher_push_notifications import PushNotifications
config = {
'apiKey': "APIKEY",
'authDomain': "car-app-push-notification.firebaseapp.com",
'databaseURL': "https://car-app-push-notification.firebaseio.com",
'projectId': "car-app-push-notification",
'storageBucket': "car-app-push-notification.appspot.com",
'messagingSenderId': "596729642105",
'appId': "APPID",
'measurementId': "G-9LMJGS1BDW"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
beams_client = PushNotifications(
instance_id='49f62b05-bd81-4040-ab57-80afa56a8680',
secret_key='SECRET KEY',
)
def stream_handler(message):
print(message)
if(message['data'] is 1):
response = beams_client.publish_to_interests(
interests=['hello'],
publish_body={
'apns': {
'aps': {
'alert': 'Hello!',
},
},
'fcm': {
'notification': {
'title': 'Alert!',
'body': 'It is starting to flood, please remove your car immediately!',
},
},
},
)
print(response['publishId'])
my_stream = db.child("FLOOD_STATUS").stream(stream_handler,None)
由于这是你的 FYP,我不会为此提供任何代码。
当用户改变他们停车的地方[=23=]时,您需要改变他们的设备兴趣以匹配相关位置。
当FLOOD_STATUS
更新为1
给定位置时,您发送通知匹配兴趣.
我建议,当用户A select MID_VALLEY
在Spinner
你发送selected 值到服务器。我建议您查看 this tutorial 以了解如何从 Spinner
获取 selected 值
在服务器端,当 FLOOD_STATUS_MID_VALLEY
为 1 时,您只向用户 A 发送通知(因为您知道用户 A 的 FCM token
)。
如果你想自定义 Spinner 的项目,你可以观看 this tutorial。