无法为Facebook推送通知解析方法'setPushNotificationsRegistrationId(java.lang.String)' [英] Cannot resolve method 'setPushNotificationsRegistrationId(java.lang.String)' for Facebook Push Notifications

本文介绍了无法为Facebook推送通知解析方法'setPushNotificationsRegistrationId(java.lang.String)'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase Cloud Messaging在Android中实现推送通知,我也在实现Facebook Push Notifications和Facebook In-App Notifications。



我正在按照说明进行操作在



我认为Facebook库应该已经在注意导入该方法了。我在依赖项中使用 compile'c​​om.facebook.android:facebook-android-sdk:3.23.1',还使用 compile'c​​om.facebook .android:notifications:1。+'。您是否对导致此错误的原因有任何想法?也许我需要更新版本的Facebook SDK?我将感谢您提供任何提示和想法来修复此错误。谢谢。



编辑1:我已经尝试使用编译'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'c​​om.facebook.android:facebook-android-sdk:4.11.0'并尝试编译应用程序,我仍然看到相同的错误吗?



编辑3:我正在检查 https://developers.facebook.com/docs/reference/android/current/class/AppEventsLogger/ 了解有关AppEventsLogger类的更多信息,并且我可以看到 setPushNotificationsRegistrationId(String)方法列出了以下说明:设置注册ID以注册当前应用程序安装的推送通知。我用来访问此类和方法的方法是: 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()); import com.facebook.AppEventsLogger ; 。使用 import com.facebook.notifications.internal.appevents.AppEventsLogger; import com.facebook.AppEventsLogger; ?谢谢。

解决方案

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


I am implementing push notifications in Android with Firebase Cloud Messaging, and I am implementing Facebook Push Notifications and Facebook In-App Notifications too.

I am following the instructions at https://developers.facebook.com/docs/push-notifications/android to set up Push Campaigns for Android. I already completed the instructions at https://firebase.google.com/docs/cloud-messaging/android/client for setting up a Firebase Cloud Messaging Client App on Android.

This is the content of my MyFirebaseMessagingService.java file:

/**
 * 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.
    }
}

This is the line that is generating an error for me:

AppEventsLogger.setPushNotificationsRegistrationId(refreshedToken);

The error is: Cannot resolve method 'setPushNotificationsRegistrationId(java.lang.String)' and you can see it in the following image:

I thought the Facebook libraries should already be taking care of importing that method. I am using compile 'com.facebook.android:facebook-android-sdk:3.23.1' in my dependencies and also compile 'com.facebook.android:notifications:1.+'. Do you have any ideas about what may be causing this error? Maybe I need a newer version of the Facebook SDK? I will appreciate any hints and ideas to fix this error. Thank you.

EDIT 1: I already tried using compile 'com.facebook.android:facebook-android-sdk:4.20.0', but I still see the same error.

EDIT 2: I found the following information at https://developers.facebook.com/docs/android/change-log-4x:

4.11.0 - April 12, 2016 Facebook SDK Added AppEventsLogger.setPushNotificationsRegistrationId and AppEventsLogger.logPush*.

That means that AppEventsLogger.setPushNotificationsRegistrationId did not exist before Facebook SDK 4.11.0, and I am using Facebook SDK 3.23.1. It makes sense that the method setPushNotificationsRegistrationId() is not recognized. But why is it that even when I use compile 'com.facebook.android:facebook-android-sdk:4.11.0' in my dependencies and try to compile the app, I still see the same error?

EDIT 3: I am examining the documentation at https://developers.facebook.com/docs/reference/android/current/class/AppEventsLogger/ to learn more about the AppEventsLogger class, and I can see that the setPushNotificationsRegistrationId(String) method is listed with the following description: Sets a registration id to register the current app installation for push notifications. What I am using to have access to this class and method is: import com.facebook.notifications.internal.appevents.AppEventsLogger;. I do not see at https://developers.facebook.com/docs/reference/android/current/class/AppEventsLogger/ any restrictions or documentation about a minimum Facebook SDK or additional requirements to be able to use the setPushNotificationsRegistrationId() method that I was expecting to have available from the class AppEventsLogger that I am using.

EDIT 4: In order to use AppEventsLogger.setPushNotificationsRegistrationId(refreshedToken);, do I need to import import com.facebook.notifications.internal.appevents.AppEventsLogger; or import com.facebook.AppEventsLogger;? In other portions of my code, I have used for example AppEventsLogger logger = AppEventsLogger.newLogger(getApplication()); with import com.facebook.AppEventsLogger;. What would be the difference between using import com.facebook.notifications.internal.appevents.AppEventsLogger; versus import com.facebook.AppEventsLogger;? Thank you.

解决方案

The setPushNotificationsRegistrationId() method did not exist in Facebook SDK 3.23.1: https://developers.facebook.com/docs/reference/android/3.23.1/class/AppEventsLogger/. It was introduced from Facebook SDK 4.11: https://developers.facebook.com/docs/reference/android/4.11/class/AppEventsLogger/ and https://developers.facebook.com/docs/android/change-log-4x.

这篇关于无法为Facebook推送通知解析方法'setPushNotificationsRegistrationId(java.lang.String)'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆