Skip to content Skip to sidebar Skip to footer

How To Setup Setcontenttitle And Setcontenttext For Push Notification From Json Data

I received the response from the server and I parsed that response in the android now I have to set the Notification Title and Text from that response. I means from that particular

Solution 1:

first your notification message must contains the values in different keys.

array( "title" => $title, "message" => $message )

the above code is php server side sample array data which is actually being added to 'data' key and then the data is sent to applications using the different servers. I have used GCM and while receiving data from server message get the above key data from bundle.

Notificationnotification=newNotification.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher)
            .setWhen(System.currentTimeMillis())
            .setContentTitle(title)
            .setContentText(message).setContentIntent(pIntent)
            .getNotification();

here you can check that setContentTitle is used to add "title" and setContentText is the "subTitle" or message

Solution 2:

You should use NotificationCompat.Builder to set the title, icon, content etc. for a notification. Here's an example:

private NotificationCompat.Builder mBuilder;
mBuilder = new NotificationCompat.Builder(
                    this).setSmallIcon(R.drawable.whitelogo)
                    .setLargeIcon(anImage)
                    .setContentTitle(title); //set smallIcon,largeIcon, contentTitle for your notification.

and to add the notification :

Notification.Buildernotification=newNotification.Builder(this)
                          .setSmallIcon(R.drawable.ic_launcher)
                          .setWhen(System.currentTimeMillis())
                          .setContentTitle(message)
                          .setContentText(message)
                          .setContentIntent(pIntent); 

notificationManager.notify(NOTIFICATION_ID_NOTIF, notification.build());

UPDATE

It's not working in your case because, there's no String with key name in your bundle, so this will return null :

message = data.getExtras().getString("name");

so move your notification code in the parseList method, as there you have already extracted all the values (id,name,photo,updates).

Post a Comment for "How To Setup Setcontenttitle And Setcontenttext For Push Notification From Json Data"