我是android的新手。我想发送gcm通知作为印地文。每当我用英语发送通知时一切正常,但是当我用印地语发送通知时,在android应用程序中收到以下输出 的नमस्त&安培;#2375 我不知道为什么我会收到这个输出。请在我错的地方帮助我。
以下是我的PHP代码
<?php
//Checking http request we are using post here
//Getting api key
$api_key = "API key here";
require'connect_to_db.php';
$query="SELECT gcm_token FROM users";
if($row=mysqli_query($con,$query)){
$reg_token = array();
while($query_row = mysqli_fetch_assoc($row)) {
array_push($reg_token, $query_row['gcm_token']);
}
}
//Getting the message
$message = $_POST['message'];
$title = $_POST['title'];
$url = $_POST['url'];
//Creating a message array
$msg = array
(
'message' => $message,
'title' => $title,
'url' => $url,
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
//Creating a new array fileds and adding the msg array and registration token array here
$fields = array
(
'registration_ids' => $reg_token,
'data' => $msg,
'priority' =>'high'
);
//Adding the api key in one more array header
$headers = array
(
'Authorization: key=' . $api_key,
'Content-Type: application/json'
);
//Using curl to perform http request
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
//Getting the result
$result = curl_exec($ch );
curl_close( $ch );
//Decoding json from result
$res = json_decode($result);
//Getting value from success
$flag = $res->success;
//if success is 1 means message is sent
if($flag == 1){
echo $result;
}else{
echo $result;
}
mysqli_close($con);
?>
答案 0 :(得分:1)
我解决了问题。背后的原因是因为Android应用程序正在接收unicode字符因此我需要解码它.. 我简单地使用这个功能 的 Html.fromHtml(消息); 强> 它正在将文本转换为印地语