C2dm - sending data in multiple lines

I have a problem with multi-line data (data containing a new line \ n). This data is encoded to call the URL:

collapse_key=<my-collapse_key>&registration_id=<my-registrationd> &data.text=Line1%0ALine2&data.group=This+is+a+test 

I have no problem sending c2dm messages. But when I try to return my string from intent, der is not a newline character.

  text = (String) intent.getStringExtra("text"); 

I assume that within the C2DM Framework there was some decoding of the urlstring string and all special characters removed?

It would be nice if someone can help me or confirm my assumptions.

+4
source share
2 answers

I found another way by modifying C2DMReceiver.java as a documented user view for the notification bar.

enter image description here

 protected void sendnotification (String title, String message) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.icon100; RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout); contentView.setImageViewResource(R.id.image, R.drawable.icon100); contentView.setTextViewText(R.id.text, message); CharSequence tickerText = message; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.contentView = contentView; Intent notificationIntent = new Intent(this, Startup.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.flags = Notification.FLAG_AUTO_CANCEL; notification.contentIntent = contentIntent; Random randInt = new Random(); int id = randInt.nextInt(100) - 1; mNotificationManager.notify(id, notification); } 

and create a custom_notification_layout.xml layout like this

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="3dp" > <ImageView android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_marginRight="10dp" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textColor="#000" /> </LinearLayout> 

Hope this helps.

Link: Android SDK Doc

+5
source

I'm going to assume that you are not double-coding the form parameters.

On the Android side, are there any characters (s) between Line1 and Line2 ?

I think the problem may be that you include the URL-encoded form of the string string %0a , but this is not a new string in terms of Java String. Did you try to send \n instead?

Also, on the device side, you may need unescape incoming data to return the escape sequence to the actual Java newline string. For example, using code similar to Apache Commons StringEscapeUtils.unescapeJava () (not part of Android AFAIK, but source is available)

+1
source

All Articles