0

我可以使用设备令牌进行注册。但我没有收到来自服务器的消息。我已经在 GCM 中注册了我的项目并获得了项目 ID,服务器密钥。

在此处输入代码

public void onMessage(Event event) {
    String msg;
    msg = event.getPayload();
    System.out.println("#### Message from the Server :" + msg);
    String one="";
    AdfmfContainerUtilities.invokeContainerJavaScriptFunction(AdfmfJavaUtilities.getFeatureId(), "usercheck", new Object[]{msg});
    // Parse the payload of the push notification
    HashMap payload = null;
    String pushMsg = "No message received";
    try
    {
      payload = (HashMap)JSONBeanSerializationHelper.fromJSON(HashMap.class, msg);
      pushMsg = (String)payload.get("alert");
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    // Write the push message to app scope to display to the user        
    AdfmfJavaUtilities.setELValue("#{applicationScope.pushMessage}", pushMsg);
}

public void onError(AdfException adfException) {
    System.out.println("#### Error: " + adfException.toString());
    // Write the error into app scope        
    AdfmfJavaUtilities.setELValue("#{applicationScope.errorMessage}", adfException.toString());

}

public void onOpen(String token) {
    System.out.println("#### Registration token:" + token);
    // Clear error in app scope
    AdfmfJavaUtilities.setELValue("#{applicationScope.errorMessage}", null);

    // Write the token into app scope
    AdfmfJavaUtilities.setELValue("#{applicationScope.deviceToken}", token);
}

}

4

2 回答 2

0

既然你是deviceId 从服务器那里得到的,那么我认为问题不在于代码。你启用PushPluginmaf-application.xml吗?

于 2016-04-06T07:34:29.673 回答
0

我想这篇文章会对你有所帮助。我能够为 GCM 完成它们,但还不能为 APN 完成。

要注册 Google Cloud Messaging,请转到此链接,然后单击“获取配置”按钮。

在服务器应用程序中,正确设置您的设备令牌和发件人 ID。使用这些发送消息。

于 2016-03-10T13:17:46.830 回答