VisualStudio 2019 Xamarin forms のデバッグ版でAndroid実機に接続して
(最初に)起動すると正しく Token が取得できますが、
Google Play Console のオープンテストから実機にインストールして起動すると、
OnNewToken イベントが起きず Token が取得できないで困っています。
試したこと
強制的に初期化して実施してみたけれど OnNewToke イベントは起きませんでした。
FirebasePushNotificationManager.Initialize(this, true); /MainActivity.cs:
ソースコード
FirebaseIDService.cs
class FirebaseIDService
{
[Service]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
public class FirebaseInstanceIDService : FirebaseMessagingService
{
public override void OnNewToken(string token)
{
base.OnNewToken(token);
//token write to server.
}
:
MainActivity.cs
using Plugin.FirebasePushNotification;
:
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
//Set the default notification channel for your app when running Android Oreo
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
//Change for your default notification channel id here
FirebasePushNotificationManager.DefaultNotificationChannelId = "FirebasePushNotificationChannel";
//Change for your default notification channel name here
FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
}
#if DEBUG
FirebasePushNotificationManager.Initialize(this, true);
#else
FirebasePushNotificationManager.Initialize(this,false);
#endif
//Handle notification when app is closed here
CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
{
//Console.WriteLine("Handle notification when app is closed here") ;
};
}
AndroidManifest.xml
<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>
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_stat_ic_notification" />
実行環境:
Microsoft Visual Studio Professional 2019 Version 16.8.3
Xamarin.Forms 5.0.0.1874
Xamarin.Firebase.Messaging 121.0.1
Plugin.FirebasePushNotification 3.3.10