[英]Sending push notification via postman to xamarin android
I am using azure push notifications.我正在使用 azure 推送通知。 Its successfully send test message from azure to xamarin.forms app.它成功地将测试消息从 azure 发送到 xamarin.forms 应用程序。 But when i use postman to send this its status showing 200 OK .但是当我使用 postman 发送它时,它的状态显示200 OK 。 But xamarin.android is not receiving push notification.但是 xamarin.android 没有收到推送通知。 this is my AndroidManifest file这是我的 AndroidManifest 文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="addovation.android.mobileaction" android:allowBackup="false" android:installLocation="auto">
<uses-sdk android:minSdkVersion="24" android:targetSdkVersion="29" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<application android:label="PushDemo.Android">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
</application>
</manifest>
I have modified(added new tags) my payload also.我也修改了(添加了新标签)我的有效载荷。 But API worked well.但是 API 运行良好。 so i think my xamarin app have the issue.所以我认为我的 xamarin 应用程序有问题。
i have register with firebase and added the GoogleJson file.我已经注册了 firebase 并添加了 GoogleJson 文件。 And my Device registered to azure successfully.我的设备成功注册到 azure。
This is Azure Test Message这是 Azure 测试消息
{
"notification":{
"title":"Notification Hub Test Notification",
"body":"This is a sample notification delivered by Azure Notification Hubs."
},
"data":{
"property1":"value1",
"property2":42
}
} }
This is my Modified Payload.这是我修改后的有效载荷。
{ \"notification\": { \"title\" : \"Mobile Action\", \"body\" : \"$(alertMessage)\"}, \"data\" : { \"action\" : \"$(alertMessage)\" , \"NotificationMessage\" : $(NotificationMessage) } }"
This is my API POST request这是我的 API POST 请求
[HttpPost]
[Route("requests")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.UnprocessableEntity)]
public async Task<IActionResult> RequestPush(
[Required] NotificationRequest notificationRequest)
{
if (notificationRequest.Silent &&
string.IsNullOrWhiteSpace(notificationRequest?.NotificationMessage[0].ToString()))
return new BadRequestResult();
var success = await _notificationService
.RequestNotificationAsync(notificationRequest, HttpContext.RequestAborted);
if (!success)
return new UnprocessableEntityResult();
return new OkResult();
}
}
Return value返回值
"{
"TextMessage": "Confirm this Order",
"Tags": [
"MyTab"
],
"AppName": "Test",
"Notification": [
{
"PageName": "OrderPage",
"PageParameters": [
{
"ORDER_NO": "05"
}
]
}
]
}"
This is my Postman Code.这是我的 Postman 代码。 This also sent successfully.这样也发送成功。
{
"NotificationMessage": [
{
"TextMessage": "Confirm this Order",
"Tags": [
"MyTab"
],
"AppName": "Test",
"Notification": [
{
"PageName": "OrderPage",
"PageParameters": [
{
"ORDER_NO": "05"
}
]
}
]
}
]
}
From Firebase Cloud Messaging HTTP protocol , set POST Method
and send your notification to following address从Firebase Cloud Messaging HTTP 协议,设置POST Method
并将您的通知发送到以下地址
https://fcm.googleapis.com/fcm/send https://fcm.googleapis.com/fcm/send
Sent your notification to following address you need to add Add below headers in postman for FCM将您的通知发送到以下地址,您需要在 postman 中为 FCM 添加 Add below headers
Content-Type
: application/json Content-Type
:应用程序/json
Authorization
: key= ******your server key from firebase console **** Authorization
: key= ****** 来自 firebase 控制台的服务器密钥 ****
Go to firebase console with your credentials then go to your app setting, get your Server key . Go 到 firebase 控制台,然后使用您的凭据 go 到您的应用程序设置,获取您的服务器密钥。
Go to postman Body->Raw->JSON,sent your notification as JSON format Go 到 postman Body->Raw->JSON,以 JSON 格式发送您的通知
Now, I can push notification by postman successfully.现在,我可以成功通过postman推送通知了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.