0

我正在使用 Firebase Cloud Messaging 在 Android 中实现推送通知,并且我也在实现 Facebook 推送通知和 Facebook 应用内通知。

我正在按照https://developers.facebook.com/docs/push-notifications/android上的说明为 Android 设置推送广告系列。我已经在https://firebase.google.com/docs/cloud-messaging/android/client完成了有关在 Android 上设置 Firebase 云消息传递客户端应用程序的说明。

这是我的MyFirebaseMessagingService.java文件的内容:

/**
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.[myapp];
import android.util.Log;

import com.facebook.notifications.internal.appevents.AppEventsLogger;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
    private static final String TAG = "MyFirebaseIIDService";
    /**
     * Called if InstanceID token is updated. This may occur if the security of
     * the previous token had been compromised. This call is initiated by the
     * InstanceID provider. Note that this is called when the InstanceID token
     * is initially generated so this is where you would retrieve the token.
     */
    // [START refresh_token]
    @Override
    public void onTokenRefresh() {
        try {
            // Get updated InstanceID token.
            String refreshedToken = FirebaseInstanceId.getInstance().getToken();
            AppEventsLogger.setPushNotificationsRegistrationId(refreshedToken);
            Log.d(TAG, "Refreshed token: " + refreshedToken);
            // If you want to send messages to this application instance or
            // manage this apps subscriptions on the server side, send the
            // Instance ID token to your app server.
            sendRegistrationToServer(refreshedToken);
            // TODO: Implement this method to send any registration to your app's servers.
            System.out.println("Registration.onTokenRefresh TOKEN: " + refreshedToken );
        } catch (Exception e) {
            Log.e("test", "Failed to complete token refresh", e);
        }
    }
    // [END refresh_token]
    /**
     * Persist token to third-party servers.
     *
     * Modify this method to associate the user's FCM InstanceID token with any server-side account
     * maintained by your application.
     *
     * @param token The new token.
     */
    private void sendRegistrationToServer(String token) {
        // TODO: Implement this method to send token to your app server.
    }
}

这是为我生成错误的行:

AppEventsLogger.setPushNotificationsRegistrationId(refreshedToken);

错误是:Cannot resolve method 'setPushNotificationsRegistrationId(java.lang.String)'您可以在下图中看到它:

在此处输入图像描述

我认为 Facebook 库应该已经负责导入该方法。我compile 'com.facebook.android:facebook-android-sdk:3.23.1'在我的依赖项和compile 'com.facebook.android:notifications:1.+'. 您对可能导致此错误的原因有任何想法吗?也许我需要更新版本的 Facebook SDK?我将不胜感激任何解决此错误的提示和想法。谢谢你。

编辑1:我已经尝试过使用compile 'com.facebook.android:facebook-android-sdk:4.20.0',但我仍然看到同样的错误。

编辑 2:我在https://developers.facebook.com/docs/android/change-log-4x找到了以下信息:

4.11.0 - 2016 年 4 月 12 日 Facebook SDK 添加了 AppEventsLogger.setPushNotificationsRegistrationId和 AppEventsLogger.logPush*。

这意味着AppEventsLogger.setPushNotificationsRegistrationId在 Facebook SDK 4.11.0 之前不存在,我使用的是 Facebook SDK 3.23.1。setPushNotificationsRegistrationId()无法识别该方法是有道理的。但是为什么即使我compile 'com.facebook.android:facebook-android-sdk:4.11.0'在依赖项中使用并尝试编译应用程序,我仍然会看到相同的错误?

编辑 3:我正在检查https://developers.facebook.com/docs/reference/android/current/class/AppEventsLogger/上的文档以了解有关 AppEventsLogger 类的更多信息,我可以看到该setPushNotificationsRegistrationId(String)方法与以下描述:Sets a registration id to register the current app installation for push notifications.我用来访问此类和方法的是:import com.facebook.notifications.internal.appevents.AppEventsLogger;. 我在https://developers.facebook.com/docs/reference/android/current/class/AppEventsLogger/上没有看到任何关于最低 Facebook SDK 的限制或文档或能够使用setPushNotificationsRegistrationId()我期望的方法的附加要求从AppEventsLogger我正在使用的课程中获得。

编辑4:为了使用AppEventsLogger.setPushNotificationsRegistrationId(refreshedToken);,我需要导入import com.facebook.notifications.internal.appevents.AppEventsLogger;还是import com.facebook.AppEventsLogger;?在我的代码的其他部分,我使用了例如AppEventsLogger logger = AppEventsLogger.newLogger(getApplication());with import com.facebook.AppEventsLogger;。usingimport com.facebook.notifications.internal.appevents.AppEventsLogger;和有什么区别import com.facebook.AppEventsLogger;?谢谢你。

4

1 回答 1

0

setPushNotificationsRegistrationId()Facebook SDK 3.23.1 中不存在该方法: https ://developers.facebook.com/docs/reference/android/3.23.1/class/AppEventsLogger/ 。它是从 Facebook SDK 4.11 引入的:https ://developers.facebook.com/docs/reference/android/4.11/class/AppEventsLogger/和https://developers.facebook.com/docs/android/change-log-4x .

于 2017-11-30T20:47:22.460 回答