Java Android 无法扩展 Firebase 消息服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39353857/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android can't extend Firebase Messaging Service
提问by Saleh Refaai
I am trying to implement Firebase Cloud Messaging in my application, I had implemented all settings to use this service, but when I try to extend FirebaseMessagingService
in my class it gives me error and it can't find it at all, I can't even import com.google.firebase.messaging.FirebaseMessagingService
as shown in the picture:
我正在尝试在我的应用程序中实现 Firebase Cloud Messaging,我已经实现了使用此服务的所有设置,但是当我尝试FirebaseMessagingService
在我的类中扩展时,它给了我错误并且它根本找不到它,我什至无法import com.google.firebase.messaging.FirebaseMessagingService
如图所示:
I had added all the code required: I added this to app gradle
我已经添加了所有需要的代码:我把它添加到了 app gradle
compile 'com.google.firebase:firebase-core:9.4.0'
apply plugin: 'com.google.gms.google-services'
and this to the module gradle:
这对模块gradle:
classpath 'com.google.gms:google-services:3.0.0'
this is the manifest code:
这是清单代码:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</application>
and I added the google json file to the app. So if anybody can help me please
我将 google json 文件添加到应用程序中。所以如果有人可以帮助我,请
采纳答案by ElDuderino
If you want to use messaging, you have to add the messaging module. Right now you only added the core module.
如果要使用消息传递,则必须添加消息传递模块。现在您只添加了核心模块。
So go ahead and include
所以继续并包括
compile 'com.google.firebase:firebase-messaging:9.4.0'
All the available modules can be found at the bottom of https://firebase.google.com/docs/android/setup
所有可用的模块都可以在https://firebase.google.com/docs/android/setup的底部找到