Sending push notification using Parse SDK on Android -
i trying chatapp. can talking people each other. there issue. want use push notification when message sended user. adding these information. have these classses on parse. intallation , session , user, chat. using user class users , chat class each conversation example senf message 1 , adding object chat class.
so dont know how can send push notification. guess should use user objectid finding buddy. , here adding 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 below code send push notification:
public void sendpushnotification(string buddyobjectid,string message,string type,string chatobjectid){ parsequery query = parseinstallation.getquery(); query.whereequalto("owner",owner); parsepush push = new parsepush(); push.setquery(query); try { jsonobject data = new jsonobject("{\"action\": \"{action name}\",\"alert\":\""+message+"\",\"mid\":\""+chatobjectid+"\",\"pid\":\""+chatobjectid+"\",\"t\": \""+type+"\"}"); push.setdata(data); } catch (jsonexception e1) { // todo auto-generated catch block e1.printstacktrace(); } push.sendinbackground(); }
where buddyobjectid buddy object id
chatobjectid chat message object id after saving
type type of message if any.
also make sure save user object id in owner column of installation table when user created.
Comments
Post a Comment