使用FireBase Android发送通知时出错

时间:2016-10-14 10:29:54

标签: php android mysql firebase

我尝试按照本教程http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

在名为MyFireBaseMessaging的类中使用此方法:

private void handleDataMessage(JSONObject json) {
        Log.e(TAG, "push json: " + json.toString());

        try {
            JSONObject data = json.getJSONObject("data");

            title = data.getString("title");
            message = data.getString("message");
            isBackground = data.getBoolean("is_background");
            imageUrl = data.getString("image");
            timestamp = data.getString("timestamp");
            payload = data.getJSONObject("payload");

            Log.e(TAG, "title: " + title);
            Log.e(TAG, "message: " + message);
            Log.e(TAG, "isBackground: " + isBackground);
            Log.e(TAG, "payload: " + payload.toString());
            Log.e(TAG, "imageUrl: " + imageUrl);
            Log.e(TAG, "timestamp: " + timestamp);


            if (!NotificationUtilities.isAppIsInBackground(getApplicationContext())) {
                // pusho il messaggio se l'app è in attiva
                Intent pushNotification = new Intent(Config.PUSH_NOTIFICATION);
                pushNotification.putExtra("message", message);
                LocalBroadcastManager.getInstance(this).sendBroadcast(pushNotification);

                // avvio il suono di notifica
                NotificationUtilities notificationUtilities =
                        new NotificationUtilities(getApplicationContext());
                notificationUtilities.playNotificationSound();
            } else {
                // se l'app è in background, visualizzo la notifica nello spazio notifiche
                Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
                resultIntent.putExtra("message", message);

                // verifico se ho un immagine da visualizzare
                if (TextUtils.isEmpty(imageUrl)) {
                    showNotificationMessage(getApplicationContext(), title, message, timestamp,
                            resultIntent);
                } else {
                    // se ho un immagine la visualizzo col messaggio
                    showNotificationMessageWithBigImage(getApplicationContext(), title, message,
                            timestamp, resultIntent, imageUrl);
                }
            }
        } catch (JSONException e) {
            Log.e(TAG, "Json Exception: " + e.getMessage());
        } catch (Exception e) {
            Log.e(TAG, "Handle Exception: " + e.getMessage());
        }
    }

当我的应用程序在后台时,我没有收到通知,但在日志中我可以看到此消息:“尝试在null上调用接口方法'boolean java.util.List.add(java.lang.Object)'对象参考“通过第二次捕获 我从PHP后端发送消息就像教程一样,我该如何解决? 谢谢你的帮助!

0 个答案:

没有答案