I have a Xamarin android application and I need to get Firebase Cloud Messaging Token.
I added a file with the following class in my Android Project :
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MyFirebaseIIDService : FirebaseMessagingService
{
const string TAG = "MyFirebaseMsgService";
public override void OnNewToken(string token)
{
base.OnNewToken(token); // << Breakpoint here
SendRegistrationToServer(token);
}
public void SendRegistrationToServer(string token)
{
// Do something with the token
}
}
and my AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="13" android:versionName="13.1" package="com.MyApp.app" android:installLocation="internalOnly">
<uses-sdk android:minSdkVersion="18" android:targetSdkVersion="30" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<application android:label="MyApp" android:icon="@mipmap/launcher_foreground" android:hardwareAccelerated="true" android:debuggable="true">
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
</application>
</manifest>
I deploy the application to an emulated device but the breakpoint is never reached. The app is deployed though and running.
I was wondering if this code is enough or whether this class has to be referenced somewhere else.
I'm aware that this code is run only once when the application is installed. So every time I uninstall the application before testing again.
Does anyone have an idea how to solve that please ?
Thanks. Cheers,