android - 没有收到通知

标签 android notifications push-notification parse-platform android-notifications

我们正在使用解析来存储聊天消息,我们正在使用解析通知。

对于 iOS,我们这样做是为了在解析的安装表中创建条目。它在解析的安装表中创建条目,我认为这是接收通知所必需的。

 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 发送/接收通知。有没有办法不使用 channel 而直接使用 notification token 或其他使用 parse 的方法?因为我将拥有用户通知 token 。

最佳答案

希望这段代码能帮到你

应用程序.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);
  }
}

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" >

关于android - 没有收到通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22146756/

相关文章:

javascript - Laravel Pusher 前端未接收数据

java - 解析简单的 JSON

android - 从 SD 卡获取图像 - android

android - 如何在android中使用 Volley 发送ArrayList?

java - 每 x 秒检查一次 html 页面

android - 收到重复的 FCM 通知

ios - iOS 7 在后台接收电池状态变化通知

flutter - 如何在没有 firebase 或一个信号的情况下用 flutter 从后端推送通知?

facebook - Windows Phone 中其他应用程序使用的推送通知机制

android - 方向改变时键盘隐藏