【发布时间】:2023-03-11 17:17:01
【问题描述】:
我正在使用本教程使用 Firebase 实现推送通知,但我似乎无法弄清楚。一直报错:
FirebaseInstanceId: background sync failed: SERVICE_NOT_AVAILABLE, retry in 40s
我创建了一个扩展FirebaseMessagingService 和onMessageReceived(..) 的类。我收到数据。我在清单中注册了该服务,例如:
<!-- [START firebase_service] -->
<service android:name="notifications.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- [END firebase_service] -->
我在我的应用程序的根文件夹中添加了最新的 google-services.json。不过,我什么也没记录。
当然,我搜索 StackOverflow 来检查类似的问题。显然不是很多。找到this,但没有太大帮助,因为我仍然收到相同的消息。有什么我可能会错过的想法吗?
我尝试检查我的设备是否正在运行 PlayStore 服务,并且确实有:
public boolean isGooglePlayServicesAvailable() {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int status = googleApiAvailability.isGooglePlayServicesAvailable(getApplicationContext());
if (status != ConnectionResult.SUCCESS) {
if (googleApiAvailability.isUserResolvableError(status)) {
googleApiAvailability.getErrorDialog(MainActivity.this, status, 2404).show();
}
return false;
}
return true;
}
【问题讨论】:
-
试试这个墨水,它可能对你有帮助stackoverflow.com/questions/40561289/…
-
如果您在模拟器上运行它,那么 Firebase 将无法在没有 Google Play 服务的情况下运行,因此请检查它是否可用。
-
@HarshitDwivedi 我没有在模拟器上运行,请查看我的编辑
-
嗨史蒂夫。 SERVICE_NOT_AVAILABLE 不是真正由 Firebase 引起的错误。这通常是设备连接的问题,通常无法连接到 FCM 服务。您是否尝试过使用模拟器或连接到稳定连接的其他设备进行测试?看看它是否仍然显示相同的错误?
-
@SteveKamau 您的设备品牌、型号和安装在您设备上的 Google Play 服务的版本是什么?为了让 firebase 正常工作,它需要在后台运行 google play 服务。因此,请确保它已安装并正在运行。
标签: android firebase firebase-cloud-messaging