android - Firebase 推送通知(当我启动应用程序时,服务不会从 list 中调用)

标签 android firebase firebase-cloud-messaging

AndroidManifest.xml 中的 Firebase 服务:

 <service
     android:name="com.MyApp.app.services.MyFirebaseIDService"
        android:enabled="true">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>
    <service
        android:name="com.MyApp.app.services.MyFirebaseMessagingService">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

我的 Gradle 库:

dependencies {

compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':viewPagerIndicator')
compile 'com.viewpagerindicator:library:2.4.1@aar.jar'
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
compile 'com.squareup.okhttp3:okhttp:3.0.0-RC1'
compile 'com.squareup.retrofit2:converter-scalars:2.0.0-beta3'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.guava:guava:19.0'

compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'

compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.github.PhilJay:MPAndroidChart:v2.2.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile 'com.flaviofaria:kenburnsview:1.0.7'
compile 'devlight.io:navigationtabbar:1.2.5'
compile 'com.wdullaer:swipeactionadapter:2.0.0'}apply plugin: 'com.google.gms.google-services'

我在我的 firebase 类中添加了 onCreate :

   @Override
public void onCreate() {
    super.onCreate();
    Log.v("Test", "Service Created");
}

最佳答案

MyFirebaseMessagingServiceonMessageReceived 仅当设备收到来自 FCM 的推送通知时才会被调用。该服务始终在后台运行。

MyFirebaseIDService 只会在您首次启动应用程序时创建。它创建服务实例并通过 onTokenRefresh 方法创建 token 。所有后续启动都不会创建此服务。相反,只要在后台刷新 token ,就会调用 onTokenRefresh 方法。

因此您可能无法在这些服务的 onCreate 方法中看到日志消息。

如果您清除应用程序数据(从 Settings->Apps->AppName->Storage->clear data )然后启动应用程序,您可能会看到该消息。

关于android - Firebase 推送通知(当我启动应用程序时,服务不会从 list 中调用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42092045/

相关文章:

android - Android 中的 Skobbler map 自定义路线计算

android - 文档中文档的 Firebase Firestore 子集合

android - 导航组件似乎只使用短动态链接(firebase)

javascript - 从 Web 到移动设备的 Firebase 云消息传递

java - 如何在外部浏览器中打开 url 点击 android 推送通知?

android - 如何将编辑文本中的用户输入限制为数字以外的所有内容

android - 删除 View 上的 OnClickListener 删除后面 View 上的所有触摸事件

android - 如何使用for循环在android kotlin中制作多个对象

ios - Swift - 如何检查 JSQMessagesViewController 中是否存在两个用户?

android - 在 Android Oreo 中处理 App 关闭或暂停状态时的 FCM 通知