I am receiving a String from GCM in JSON Format . I want to Parse that String and then generate notification.i want that it should generate notification on the basis of tag for Example if tag is "comment" then it should generate the notification for comment. I am new to Android. the String that i received is {"tag":"comment","sender":null,"content":null} my Code is
public void categorizNotifications(String msg){
try {
JSONObject json=new JSONObject(msg);
String Tag=json.getString(TAG);
if(Tag=="comment"){
String Content=json.getString(CONTENT);
String Sender=json.getString(SENDER);
generateNotificationForComment(Content,Sender);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void generateNotificationForComment(String content2, String sender2) {
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, Comments.class), 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.ic_action_event)
.setContentTitle(sender2+" add a comment")
.setStyle(new NotificationCompat.BigTextStyle().bigText(content2))
.setContentText(content2);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
//Log.d(TAG, "Notification sent successfully.");
}