My app receives push notifications from a WordPress plugin (Push Notifications for Posts - http://codecanyon.net/item/push-notif...).
However, the push notification message is blank. Just the name of the app appears.
How do I get the title from the push payload to display in notification?
The plugin developer kindly provided this hint:
[quote:]You can find the post's title in the data field of the notification payload, which in our case is something like:
code"data":{"id":"125", "title":"New Post Title"}/code
Here is an example:
In the class that extends BroadcastReceiver, implement the onReceive(Context context, Intent intent) method.
Here, to get the post's title call:
codeBundle extras = intent.getExtras();/code
codeid = extras.getString("id"); // "125" in our example/code
codetitle = extras.getString("title"); // "New Post Title" in our example/code
To show the alert box then call something like:
codeNotificationCompat.Builder builder = new NotificationCompat.Builder(context)/code
code .setSmallIcon(smallIconId)/code
code.setContentTitle(context.getString(context.getApplicationInfo().labelRes))/code
code .setAutoCancel(true)/code
Code: Select all
code.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))/code
code .setContentText(title)/code
code .setContentIntent(contentIntent);/code
code notificationManager.notify(id, builder.build());/code[/quote]