【发布时间】:2016-05-26 13:24:50
【问题描述】:
我能够使用设备令牌进行注册。但我没有收到来自服务器的消息。我已经在 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);
}
}
【问题讨论】:
-
你能告诉我你从哪里调用这些 onOpen , onError 方法吗??
-
来自 LifeCycleListenerImpl.java public void start() { EventSource evtSource = EventSourceFactory.getEventSource(EventSourceFactory.NATIVE_PUSH_NOTIFICATION_REMOTE_EVENT_SOURCE_NAME); evtSource.addListener(new NativePushNotificationListener()); }
-
以上代码sn-p来自NativePushNotificationListener?
-
是的......但是当我从服务器发送消息时,我收到一个警告......
-
你收到了什么信息?请提供完整信息
标签: oracle-maf