【发布时间】:2014-03-03 12:25:16
【问题描述】:
我们正在使用解析来存储聊天消息,并且我们正在使用解析通知。
对于 iOS,我们这样做是为了在 parse 的安装表中创建条目。它在 parse 的安装表中创建条目,我认为必须接收通知。
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation.deviceToken = user.notificationToken;
[currentInstallation saveInBackground];
但在 android 中,我无法在安装表中创建条目。
我没有收到来自 parse 的通知,我认为这是没有收到通知的原因..
是这样吗?
谁能引导我走向正确的道路?
更新
现在收到通知,但仍有一些疑问。 我在用户登录时执行此操作。如果未创建用户,则我已设置条件,否则仅创建不创建。我没有将它添加到此,因为这不是必需的
// 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);
}
}
});
}
发送通知
ParsePush push = new ParsePush();
if(object.get(k).has("channels"))
{
push.setChannel(object.get(k).getString(
"channels"));
}
push.setData(dataAndroid);
push.sendInBackground();
目前我正在做这一切来使用 Parse 发送/接收通知。有没有办法不使用通道直接使用 notification token 或其他使用 parse 的方法?因为我将拥有用户通知令牌。
【问题讨论】:
标签: android notifications push-notification parse-platform android-notifications