kee*_*een 3 notifications android push-notification android-notifications parse-platform
我们使用解析来存储聊天消息,我们正在使用解析通知.
对于iOS,我们这样做是为了在解析的安装表中创建条目..它在解析的安装表中创建条目,我认为必须接收通知.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation.deviceToken = user.notificationToken;
[currentInstallation saveInBackground];
Run Code Online (Sandbox Code Playgroud)
但在android中我无法在安装表中创建条目.
我没有收到解析通知,我认为这是没有收到通知的原因.
是这样的吗?
任何人都能把我引向正确的道路吗?
UPDATE
现在收到通知但仍有疑虑. 当用户登录时,我正在这样做.如果没有创建用户,我已经设置了条件,否则只创建否则.我没有添加它,因为没有必要
// 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);
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
发送通知
ParsePush push = new ParsePush();
if(object.get(k).has("channels"))
{
push.setChannel(object.get(k).getString(
"channels"));
}
push.setData(dataAndroid);
push.sendInBackground();
Run Code Online (Sandbox Code Playgroud)
目前我正在做这一切,使用Parse发送/接收通知.有没有办法不使用频道并直接使用通知令牌或其他使用解析?因为我将拥有用户通知令牌.
我希望这段代码可以帮到你
Application.java
public class Application extends android.app.Application {
public Application() {
}
@Override
public void onCreate() {
super.onCreate();
// Initialize the Parse SDK.
Parse.initialize(this, "your applicationId", "your clientKey");
// Specify an Activity to handle all pushes by default.
PushService.setDefaultPushCallback(this, MainActivity.class);
}
}
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml
<application
android:name="<Your Package Name>.Application"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
Run Code Online (Sandbox Code Playgroud)