Codenameone 应用程序在前台时推送通知未到达
当应用程序在Android设备的前台时,我很难获得推送通知。只要我把应用程序放在后台,一切都很顺利 这是我用来发送de通知的java代码:Codenameone 应用程序在前台时推送通知未到达,codenameone,Codenameone,当应用程序在Android设备的前台时,我很难获得推送通知。只要我把应用程序放在后台,一切都很顺利 这是我用来发送de通知的java代码: HttpClient client = HttpClientBuilder.create().build(); HttpPost httpPost = new HttpPost(URL_SERVER); List<NameValuePair> arguments = new ArrayList<>();
HttpClient client = HttpClientBuilder.create().build();
HttpPost httpPost = new HttpPost(URL_SERVER);
List<NameValuePair> arguments = new ArrayList<>();
arguments.add(new BasicNameValuePair("token", TOKEN));
arguments.add(new BasicNameValuePair("device", codigoApp));
arguments.add(new BasicNameValuePair("type", "1"));
arguments.add(new BasicNameValuePair("body", ip));
arguments.add(new BasicNameValuePair("auth", GOOGLE_AUTH));
try {
httpPost.setEntity(new UrlEncodedFormEntity(arguments));
HttpResponse response = client.execute(httpPost);
String result = EntityUtils.toString(response.getEntity());
System.out.println(result);
} catch (IOException ex) {
Logger.getLogger(NotificaReview.class.getName()).log(Level.SEVERE, null, ex);
}
只有当我在后台接受推送后将应用程序带到前台时,ToastBar才会显示。如果应用程序处于活动状态,则不会调用推送回调
有什么想法吗?我需要回答我在这个问题上的评论,这可能有助于解释这个问题。我将根据问题的更新编辑此答案 与此同时,我在代码中看到了几个问题。请参阅下面我突出显示的注释/修复:
public void start() {
if(current != null){
current.show();
return;
}
// don't check the push key, always register the device and
// always do it in a callSerially as it might trigger a prompt
callSerially(() -> registerPush());
Form inicioGUI = new InicioGUI(Push.getPushKey());
inicioGUI.show();
}
@Override
public void push(String value) {
ToastBar.showMessage("Archivo recibido correctamente con IP" + value, FontImage.MATERIAL_INFO);
}
@Override
public void registeredForPush(String deviceId) {
// deviceId is the native push key you need to use the actual
// push key value never device ID
devicePush = Push.getPushKey();
}
@Override
public void pushRegistrationError(String error, int errorCode) {
// you might have gotten a push error which might have explained the
// cause of the problem
Log.p("Push error " + errorCode + ":" + error);
Log.sendLogAsync();
}
您使用的是GCM推送还是FCM推送?这是在哪个操作系统上?你测试过其他设备吗?您是否看到设备控制台上打印的内容?
public void start() {
if(current != null){
current.show();
return;
}
// don't check the push key, always register the device and
// always do it in a callSerially as it might trigger a prompt
callSerially(() -> registerPush());
Form inicioGUI = new InicioGUI(Push.getPushKey());
inicioGUI.show();
}
@Override
public void push(String value) {
ToastBar.showMessage("Archivo recibido correctamente con IP" + value, FontImage.MATERIAL_INFO);
}
@Override
public void registeredForPush(String deviceId) {
// deviceId is the native push key you need to use the actual
// push key value never device ID
devicePush = Push.getPushKey();
}
@Override
public void pushRegistrationError(String error, int errorCode) {
// you might have gotten a push error which might have explained the
// cause of the problem
Log.p("Push error " + errorCode + ":" + error);
Log.sendLogAsync();
}