You're converting your string to byte array, using UTF-8 encoding. Then you create a stream writer, with UTF-16 encoding, convert the value of your bytes to string, and write them into the stream. I honestly don't see how it could work.
Try this instead:
String toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>" + name + "</wp:Text1>" +
"<wp:Text2>" + body + "</wp:Text2>" +
"<wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param>" +
"</wp:Toast> " +
"</wp:Notification>";
// Do your stuff, initialize the headers, and so on...
OutputStreamWriter writer = new OutputStreamWriter(uc.getOutputStream(), "utf-8");
writer.write(toastMessage, 0, toastMessage.length());
uc.connect();
If you can't pass a String to the write
method, then write directly in the output stream:
String toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<wp:Notification xmlns:wp=\"WPNotification\">" +
"<wp:Toast>" +
"<wp:Text1>" + name + "</wp:Text1>" +
"<wp:Text2>" + body + "</wp:Text2>" +
"<wp:Param>/Page2.xaml?NavigatedFrom=Toast Notification</wp:Param>" +
"</wp:Toast> " +
"</wp:Notification>";
byte[] mesg = toastMessage.getBytes("UTF-8");
uc.setDoOutput(true);
uc.setDoInput(true);
uc.getOutputStream().write(mesg, 0, mesg.length());
uc.connect();