gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 14:44:32 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com