I need to convert a string to UTF-8(Bangla) I am making an android app with FCM. I am using this code to send the data. I am using a html from to do this and there is two fildes.
$title = $_POST['title'];
$message = $_POST['message'];
$image_url = $_POST['img'];
public function setTitle($title) {
$this->title = $title;
}
public function setMessage($message) {
$this->message = $message;
}
public function setImage($imageUrl) {
$this->image = $imageUrl;
}
public function setIsBackground($is_background) {
$this->is_background = $is_background;
}
public function getPush() {
$res = array();
$res['data']['title'] = $this->title;
$res['data']['is_background'] = $this->is_background;
$res['data']['message'] = $this->message;
$res['data']['image'] = $this->image;
$res['data']['timestamp'] = date('Y-m-d G:i:s');
return $res;
}
$headers = array(
'Authorization: key=' . FIREBASE_API_KEY,
'Content-Type: application/json',
'charset=UTF-8'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
Java code for my app:
private void handleDataMessage(JSONObject json) {
Log.e(TAG, "push json: " + json.toString());
System.out.println("Data Message: "+json);
try {
JSONObject data = json.getJSONObject("data");
String ptitle = data.getString("title");
String message = data.getString("message");
boolean isBackground = data.getBoolean("is_background");
String imageUrl = data.getString("image");
String timestamp = data.getString("timestamp");
JSONObject payload = data.getJSONObject("payload");
String title = URLDecoder.decode(ptitle, "utf-8");
//Send notification data to MessageShowActivity class for showing
Intent resultIntent = new Intent(getApplicationContext(), MessageShowActivity.class);
resultIntent.putExtra("title", title);
resultIntent.putExtra("timestamp", timestamp);
resultIntent.putExtra("image", imageUrl);
showNotificationMessage(getApplicationContext(), title, message, timestamp, resultIntent);
} catch (JSONException e) {
Log.e(TAG, "Json Exception: " + e.getMessage());
System.out.println("in 1st CATCH");
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
System.out.println("in 2nd CATCH");
}
}
private void showNotificationMessage(Context context, String title, String message, String timeStamp, Intent intent) {
notificationUtils = new NotificationUtils(context);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
notificationUtils.showNotificationMessage(title, message, timeStamp, intent);
}
When I write in UTF-8(Bangla) only message text shows it, But title are like the ones in the picture below.
Any guidance would be deeply appreciated!