GCM and Special characters

笑着哭i 提交于 2019-12-07 10:49:07

问题


I recently changed my c2dm push aaplucation to GCM. A new problem appeared. Its now receiving '?' instead of 'ö','ï', ...

My server logs correct Strings, but the application receives '?' insteads.

Do you think it could have something to do with GCM?

My code is the following:

public static void displayMessage(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras != null) {
        String message = (String) extras.get("message");
        Log.v("extras", extras.toString());
        Util.generateNotification(context, message, intent);
    }
}

and the log is then:

10-02 22:18:23.671: V/intent(29809): Bundle[{message={"name":"j?rg"},
message_id=8bb60eee-3a93-4075-b606-40495511a4da, collapse_key=do_not_collapse, from=160085429222}]

Best regards!


回答1:


I dont think so there is problem in GCM. Try to use UTFEncoding for your message.

String output = new String(name.getBytes("8859_1"), "utf-8");


来源:https://stackoverflow.com/questions/12704567/gcm-and-special-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!