【问题标题】:Failed to retrieve Firebase Instance Id (No firebase service is working)无法检索 Firebase 实例 ID(没有 Firebase 服务正在运行)
【发布时间】:2021-08-09 09:29:25
【问题描述】:

我在使用 android studio 将 Firebase 服务添加到我的应用程序时遇到了问题 这是logcat:

2021-08-09 12:17:24.764 6480-6480/com.nanosoft.fawwalet D/ActivityThread: ActivityThread::handleMakeApplication() 数据=AppBindData{appInfo=ApplicationInfo{13e94c8 com.nanosoft.fawwalet}} appContext=android.app.ContextImpl@3aa7961 appContext.mOpPackageName=com.nanosoft.fawwalet appContext.mBasePackageName=com.nanosoft.fawwalet appContext.mPackageInfo=android.app.LoadedApk@2976c86 data.restrictedBackupMode= false data.providers= [ContentProviderInfo{name=com.nanosoft.fawwalet.mobileadsinitprovider className=com.google.android.gms.ads.MobileAdsInitProvider}, ContentProviderInfo{name=com.nanosoft.fawwalet.firebaseinitprovider className=com.google.firebase.provider.FirebaseInitProvider}, ContentProviderInfo{name=com.nanosoft.fawwalet.workmanager-init className=androidx.work.impl.WorkManagerInitializer}, ContentProviderInfo{name=com.nanosoft.fawwalet.lifecycle-process className=androidx.lifecycle.ProcessLifecycleOwnerInitializer}, ContentProviderInfo{name=com.nanosoft.fawwalet className=com.nanosoft.fawwalet.data.PlaceDetailProvider}] 调用者=android.app.ActivityThread.handleBindApplication:7446 android.app.ActivityThread.access$1500:301 android.app.ActivityThread$H.handleMessage:2148 android.os.Handler.dispatchMessage:106 android.os.Looper.loop:246 2021-08-09 12:17:24.946 6480-6480/com.nanosoft.fawwalet I/FirebaseApp: 设备解锁:初始化应用程序的所有 Firebase API [DEFAULT] 2021-08-09 12:17:25.161 6480-6480/com.nanosoft.fawwalet I/FirebaseInitProvider:FirebaseApp 初始化成功 2021-08-09 12:17:25.583 6480-10717/com.nanosoft.fawwalet W/FA:无法检索 Firebase 实例 ID

任何帮助将不胜感激

这是我的清单文件

 <service android:name=".utils.PushNotificationService" android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

我按照 Firebase 教程建立了我的 FCM,但仍然没有运气

这是java类

    public class PushNotificationService extends FirebaseMessagingService {

    private static final String TAG = "PushNotification";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        // ...

        Log.d(TAG, "From: " + remoteMessage.getFrom());

        // Check if message contains a data payload.
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());

            if (/* Check if data needs to be processed by long running job */ true) {
                // For long-running tasks (10 seconds or more) use Firebase Job Dispatcher.

            } else {
                // Handle message within 10 seconds

            }

        }

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
        }

        // Also if you intend on generating your own notifications as a result of a received FCM
        // message, here is where that should be initiated. See sendNotification method below.
    }

    @Override
    public void onNewToken(@NonNull String s) {
        super.onNewToken(s);
    }
}

【问题讨论】:

  • 发布您期望使用 Firebase 实例 ID 的代码。
  • 我正在为我的 FCM 应用做准备
  • 那么您是否编写了代码来获取 Firebase 实例 ID?
  • 不,先生,唯一的代码我将提供我写的唯一代码我不记得要求提供 ID,但 FCM 根本不起作用,谢谢您的时间
  • PushNotificationService 中你是否重写了onNewToken 方法?这将在令牌更新时为您提供新令牌。

标签: android firebase android-studio


【解决方案1】:

在 PushNotificationService 中,您需要重写 onNewToken 方法,这将在更新令牌时为您提供新令牌。

【讨论】:

    【解决方案2】:

    通过以下方式解决:

    1. 将 google play 服务降级到 “com.google.gms:google-services:4.3.8”是 4.3.9

    2.使用 mavenCentral()

    1. 将 minSdkVersion 18 提高为 16

    我在尝试重现该问题时认为自己是这样,因此它与 Fire Base 实例 ID 无关,因为我没有调用它。 Firebase 服务已启动并正在运行

    【讨论】:

      猜你喜欢
      • 2018-07-27
      • 1970-01-01
      • 2020-11-30
      • 2023-03-07
      • 1970-01-01
      • 2018-03-21
      • 2017-07-22
      • 1970-01-01
      • 2023-03-24
      相关资源
      最近更新 更多