我在这里使用了教程
用于实现从客户端推送,但不发送阿拉伯语通知我必须在此方法中更改什么以支持阿拉伯语
我也尝试了json.getBytes("UTF-8"(,但没有发送任何内容,因为(" Windows-1256"(发送的消息已发送,但错误编码了显示为"???"的字符
public void sendNotificationButtonOnClick(View v) {
EditText notificationText = (EditText) findViewById(R.id.editTextNotificationMessage);
final String json = "{"data":{"message":"" + notificationText.getText().toString() + ""}}";
new Thread()
{
public void run()
{
try
{
ParseConnectionString(NotificationSettings.HubFullAccess);
URL url = new URL(HubEndpoint + NotificationSettings.HubName +
"/messages/?api-version=2015-01");
HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();
try {
// POST request
urlConnection.setDoOutput(true);
// Authenticate the POST request with the SaS token
urlConnection.setRequestProperty("Authorization",
generateSasToken(url.toString()));
// Notification format should be GCM
urlConnection.setRequestProperty("ServiceBusNotification-Format", "gcm");
urlConnection.setRequestProperty("ServiceBusNotification-Tags",
// "tag1 || tag2 || tag3");
// Send notification message
urlConnection.setFixedLengthStreamingMode(json.length());
OutputStream bodyStream = new BufferedOutputStream(urlConnection.getOutputStream());
bodyStream.write(json.getBytes());
bodyStream.close();
// Get reponse
urlConnection.connect();
int responseCode = urlConnection.getResponseCode();
if ((responseCode != 200) && (responseCode != 201)) {
BufferedReader br = new BufferedReader(new InputStreamReader((urlConnection.getErrorStream())));
String line;
StringBuilder builder = new StringBuilder("Send Notification returned " +
responseCode + " : ") ;
while ((line = br.readLine()) != null) {
builder.append(line);
}
ToastNotify(builder.toString());
}
} finally {
urlConnection.disconnect();
}
}
catch(Exception e)
{
if (isVisible) {
ToastNotify("Exception Sending Notification : " + e.getMessage().toString());
}
}
}
}.start();
}
尝试这样的事情
var payload = new
{
to = fcm_token,
priority = "high",
content_available = true,
notification = new
{
body = data.body,
title = data.content,
badge = 1,
targetScreen = data.TargetScreen,
Id = data.Id
},
};
var msg = JsonConvert.SerializeObject(payload).ToString();
var buff = Encoding.UTF8.GetBytes(msg);
request.GetRequestStream().Write(buff, 0, buff.Length);
其中,有效负载是您将发送到 Firebase 的对象