I created a google-services.json file and added to my android project but when I tried to get a token I received this exception:
{
Java.IO.IOException: java.util.concurrent.ExecutionException: java.io.IOException: INVALID_SENDER ---> Java.Util.Concurrent.ExecutionException: java.io.IOException: INVALID_SENDER ---> Java.IO.IOException: INVALID_SENDER
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at VTInRoomApp.Droid.XamarinForms.MainActivityXam.OnComplete (Android.Gms.Tasks.Task task) [0x00039] in T:\Work\VT\Dev\Mobile\Xamarin\VTInRoomApp\VTInRoomApp\VTInRoomApp.Android\XamarinForms\MainActivityXam.cs:157
--- End of managed Java.IO.IOException stack trace ---
java.io.IOException: java.util.concurrent.ExecutionException: java.io.IOException: INVALID_SENDER
at com.google.firebase.messaging.FirebaseMessaging.blockingGetToken(com.google.firebase:firebase-messaging@@22.0.0:14)
at com.google.firebase.messaging.FirebaseMessaging.lambda$getToken$2$FirebaseMessaging(com.google.firebase:firebase-messaging@@22.0.0:1)
at com.google.firebase.messaging.FirebaseMessaging$$Lambda$3.run(com.google.firebase:firebase-messaging@@22.0.0)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.6.0:2)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.util.concurrent.ExecutionException: java.io.IOException: INVALID_SENDER
at com.google.android.gms.tasks.Tasks.zza(com.google.android.gms:play-services-tasks@@17.2.1:5)
at com.google.android.gms.tasks.Tasks.await(com.google.android.gms:play-services-tasks@@17.2.1:8)
at com.google.firebase.messaging.FirebaseMessaging.blockingGetToken(com.google.firebase:firebase-messaging@@22.0.0:10)
... 9 more
Caused by: java.io.IOException: INVALID_SENDER
at com.google.firebase.messaging.GmsRpc.handleResponse(com.google.firebase:firebase-messaging@@22.0.0:7)
at com.google.firebase.messaging.GmsRpc.lambda$extractResponseWhenComplete$0$GmsRpc(com.google.firebase:firebase-messaging@@22.0.0:1)
at com.google.firebase.messaging.GmsRpc$$Lambda$1.then(com.google.firebase:firebase-messaging@@22.0.0)
at com.google.android.gms.tasks.zzc.run(com.google.android.gms:play-services-tasks@@17.2.1:3)
at com.google.firebase.messaging.GmsRpc$$Lambda$0.execute(com.google.firebase:firebase-messaging@@22.0.0)
at com.google.android.gms.tasks.zzd.zza(com.google.android.gms:play-services-tasks@@17.2.1:1)
at com.google.android.gms.tasks.zzr.zzb(com.google.android.gms:play-services-tasks@@17.2.1:5)
at com.google.android.gms.tasks.zzw.zza(com.google.android.gms:play-services-tasks@@17.2.1:3)
at com.google.android.gms.tasks.zzc.run(com.google.android.gms:play-services-tasks@@17.2.1:8)
at com.google.android.gms.cloudmessaging.zzz.execute(com.google.android.gms:play-services-cloud-messaging@@17.0.0)
at com.google.android.gms.tasks.zzd.zza(com.google.android.gms:play-services-tasks@@17.2.1:1)
at com.google.android.gms.tasks.zzr.zzb(com.google.android.gms:play-services-tasks@@17.2.1:5)
at com.google.android.gms.tasks.zzw.zza(com.google.android.gms:play-services-tasks@@17.2.1:3)
at com.google.android.gms.tasks.TaskCompletionSource.setResult(com.google.android.gms:play-services-tasks@@17.2.1:1)
at com.google.android.gms.cloudmessaging.zzp.zzd(com.google.android.gms:play-services-cloud-messaging@@17.0.0:3)
at com.google.android.gms.cloudmessaging.zzr.zza(com.google.android.gms:play-services-cloud-messaging@@17.0.0:2)
at com.google.android.gms.cloudmessaging.zzf.handleMessage(com.google.android.gms:play-services-cloud-messaging@@17.0.0:14)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6157)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
}
Did I mess up when I created the google-servies.json or is it something in my code?
Thank you very much
CodePudding user response:
Normally, this error caused by the json file. Check the information below to confirm.
- Check that you have copied your file in correct project folder and have set the Build Action to
GoogleServicesJson
. - Check the file is correct and matches with latest downloaded google-services.json file in FCM.
- Check that is there any duplicate file of google-services.json present in your project.
- Please note when
google-services.json
is added to the project (and theGoogleServicesJson
build action is set), the build process extracts theclient ID
andAPI
key and then adds these credentials to the merged/generatedAndroidManifest.xml
that resides atobj/Debug/android/AndroidManifest.xml
. If you could confirm everything is correect, delete the bin and obj to clean and rebuild and reopen the project may helpful. - If you still have this issue, create a new project to follow the steps in the MS docs. https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=windows
CodePudding user response:
Try this
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "Fetching FCM registration token failed", task.getException());
return;
}
// Get new FCM registration token
String token = task.getResult();
// Log and toast
String msg = getString(R.string.msg_token_fmt, token);
Log.d(TAG, msg);
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});