I have been trying to implement Firebase messaging in my app for a while now. I have followed different kinds of tutorial, including the official one by Firebase, adding it both manually and automatic with Firebase Assistant.
For some reason, the following statements are true:
MyFirebaseInstanceIDService:
class MyFirebaseInstanceIDService : FirebaseInstanceIdService() {
val TAG = javaClass?.simpleName
override fun onTokenRefresh() {
super.onTokenRefresh()
val refreshedToken = FirebaseInstanceId.getInstance().token
System.out.println("firebasedebug (" + TAG + "): onTokenRefresh(): " + refreshedToken)
}
}
MyFirebaseMessagingService
class : FirebaseMessagingService() {
val TAG = javaClass?.simpleName
override fun onMessageReceived(remoteMessage: RemoteMessage?) {
super.onMessageReceived(remoteMessage)
System.out.println("firebasedebug (" + TAG + "): onMessageReceived(remoteMessage: " + remoteMessage+")")
}
}
I have added the following to my Manifest:
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
<service
android:name="dk.myapp.service.firebase.MyFirebaseMessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name="dk.myapp.service.firebase.MyFirebaseInstanceIDService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
(Note that I have tried setting exported to true and false and also with and without the metatag for setting the channel)
I have also added the following to my Application class:
FirebaseApp.initializeApp(this);
Apparently this was required when I tried to use the method "getToken()" through Firebase. A have also tried with and without these methods.
In my main activity I have tried placing the "getToken()" method through Firebase to attempt to trigger the initialization of the token, but still without any luck.
FirebaseInstanceId.getInstance().token
I have of course added the messaging library (and google play service modules) to my app module gradle:
compile 'com.google.firebase:firebase-messaging:15.0.0'
compile 'com.google.android.gms:play-services-ads:15.0.0'
compile 'com.google.android.gms:play-services-maps:15.0.0'
compile 'com.google.android.gms:play-services-base:15.0.0'
compile 'com.google.android.gms:play-services-location:15.0.0'
An also added this line to the bottom of the gradle file:
apply plugin: 'com.google.gms.google-services'
And these to my project gradle:
buildscript {
ext.kotlin_version = '1.1.4-2'
ext.anko_version = '0.10.2'
repositories {
mavenCentral()
jcenter()
google()
}
dependencies {
...
classpath 'com.google.gms:google-services:3.2.1' // google-services plugin
...
}
allprojects {
tasks.withType(JavaCompile) {
sourceCompatibility = "1.7"
targetCompatibility = "1.7"
}
}
}
allprojects {
repositories {
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
EDIT: I have of course also added the google-services.json to the project
When sending the messages through the Firebase dashboard I have tried: - Entering the channel - Setting target as User segment - Setting target as Single device (the token from the app) - ...
I have also tried things like: - uninstalling and reinstalling the app whenever I tried a new approach - deleting instanceid and calling getToken again - Trying in both debug and non-debug mode - ...
Here is how my list of send messages looks like in the dashboard:
If any more details are needed, please let me know and I will of course supply them (if possible).
EDIT I tried out the REST API and made some observations.
I have finally found the solution to my particular situation.
The solution for me was to remove the following lines from my manifest file in the application tag:
android:label="@string/app_name"
tools:node="replace"
tools:replace="android:icon,android:label"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With