We are using parse to store chat messages and we are using notification of parse.
For iOS we are doing this to create entry in installation table of parse.. It's creating entry in installation table of parse, which i think is must to receive notification.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation.deviceToken = user.notificationToken;
[currentInstallation saveInBackground];
But in android I am not able to create entry in installation table.
I am not receiving notification from parse and I think this is the reason behind not getting notification..
Is this the case?
Can any one guild me to the right path ?
UPDATE
Now receiving notification but still having some doubts. I am doing this when user logs in. I have put conditions if user is not created then only create otherwise don't. I haven't added it to this because that's not necessary
// setting up parse installation
private void setUpParseInstallation()
{
ParseInstallation currentInstallation = ParseInstallation
.getCurrentInstallation();
currentInstallation.saveInBackground(new SaveCallback()
{
@Override
public void done(com.parse.ParseException e)
{
if (e != null)
{
Log.e(TAG, "Error saving parse installation");
}
}
});
}
// add user to parse it it doesn't exist otherwise handle the cases
private void addUserToParseIfNotExisting()
{
// if user doesn't exist create a new user
ParseObject newuser = new ParseObject("user");
newuser.put("name", email);
newuser.put("userId", id);
newuser.saveInBackground();
}
private void setChannel()
{
channel = "abdf";
RS_User user = new RS_User(this);
ParseQuery<ParseObject> pquery = ParseQuery.getQuery("user");
pquery.whereEqualTo("userId", user.getUserId());
// see if user exists in user table on parse
pquery.findInBackground(new FindCallback<ParseObject>()
{
@Override
public void done(List<ParseObject> list,
com.parse.ParseException error)
{
if (list.size() > 0)
{
list.get(i).put("channels", channel);
list.get(i).saveInBackground();
PushService.subscribe(getApplicationContext(),channel, RS_HelpActivity.class);
}
}
});
}
Sending a notification
ParsePush push = new ParsePush();
if(object.get(k).has("channels"))
{
push.setChannel(object.get(k).getString(
"channels"));
}
push.setData(dataAndroid);
push.sendInBackground();
Currently I am doing all this to send/receive notification using Parse. Is there a way to do without using channel and directly using notification token or something else using parse ? Because I will be having user notification token.