I am trying to do ChatApp. I can do talking people each other. But there is an issue. I want to use push notification when a message sended to any user. So i am adding these information. I have these classses on Parse. Intallation , Session , User, Chat. I am using User class for users , Chat class for each conversation for example someone senf a message another one , i am adding an object my chat class.
So I dont know how can i send push notification. I guess i should use User objectId to finding buddy. And here i am adding my sendMessage method:
private void sendMessage() {
if (txt.length()==0)
return;
InputMethodManager imm= (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(txt.getWindowToken(), 0);
String s=txt.getText().toString();
final Conversation c=new Conversation(s,new Date(),UserList.user.getUsername());
c.setStatus(Conversation.STATUS_SENDING);
convList.add(c);
adp.notifyDataSetChanged();
txt.setText(null);
ParseObject po=new ParseObject("Chat");
po.put("sender",UserList.user.getUsername());
po.put("receiver",buddy);
po.put("message",s);
po.saveEventually(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e == null){
c.setStatus(Conversation.STATUS_SENT);
}
else {
c.setStatus(Conversation.STATUS_FAILED);
}
adp.notifyDataSetChanged();
}
});
}
Use the below code to send the push notification:
Where buddyObjectId is buddy object id
chatObjectID is chat message object id after saving
type is type of message if any.
Also make sure to save user object id in owner column of the installation table when a user is created.