I know there are a few other posts similar to mine but I've gone through the list of solutions with no results. My Android app has a very simple firebase implementation that is supposed to retrieve the token on startup and pass it via callback to the main activity for use later. I've heard that the token is supposed to be generated on startup, but during the first app install, I never receive it and my app crashes. If I install my app again (without removing it first), everything works normally and I get my token.
I've tried:
- Updating and consolidating my firebase dependencies the app's build.gradle file
- Confirming that my Manifest is using the correct firebase services / internet permissions
- Deleting my instance id with FirebaseInstanceId.getInstance().deleteInstanceId() before manually calling getToken()
- Testing on multiple devices
Looking at my logcat during first install, I get these two firebase errors:
E/FA: Discarding data. Failed to send app launch
E/FA: Failed to get app instance id
My InstanceIdService:
public class InstanceIDService extends FirebaseInstanceIdService {
TokenCallback callback;
public void initInstanceIDService(TokenCallback cb) {
this.callback = cb;
}
@Override
public void onTokenRefresh() {
super.onTokenRefresh();
// Get updated token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
if (refreshedToken != null) {
callback.onTokenReceived(refreshedToken);
}
//pass token to manager for use during authentication
Log.d("Firebase", "Refreshed token: " + refreshedToken);
}
public interface TokenCallback {
void onTokenReceived(String token);
}
}
My Manifest:
<service
android:name="com.projectname.network.MessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.projectname.network.InstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
My Gradle dependencies:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.firebase:firebase-core:11.0.4'
compile 'com.google.firebase:firebase-messaging:11.0.4'
compile 'com.android.support:appcompat-v7:+'
}
apply plugin: 'com.google.gms.google-services'
I'm testing on physical devices and all return the same behavior.
If anyone has had experience with this problem, any suggestions or solutions would be greatly appreciated.