()是因为FirebaseMessagingService类本身并没有提供getApplicationContext()方法。FirebaseMessagingService是Firebase Cloud Messaging(FCM)库中的一个类,用于处理接收和处理来自FCM的消息。
要获取ApplicationContext,可以通过以下方式之一来解决这个问题:
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private Context context;
@Override
public void onCreate() {
super.onCreate();
context = getApplicationContext();
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// 使用context进行操作
}
}
以上是解决在从FirebaseMessagingService扩展的类中找不到getApplicationContext()方法的几种常见方法。根据具体情况选择适合的方法来获取ApplicationContext,并在需要的地方使用它进行操作。
Elastic Meetup
云+社区技术沙龙[第17期]
云+社区技术沙龙 [第30期]
云+社区开发者大会(苏州站)
高校公开课
第四期Techo TVP开发者峰会
Elastic 中国开发者大会
领取专属 10元无门槛券
手把手带您无忧上云