Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] Issue adding Xamarin.Android app in Firebase Console Project

Posted on November 14, 2022

Solution 1 :

I have added the nuget package “Xamarin.Firebase.Analytics” and it has worked. This package is necessary everytime we use a project with the Google Analytics set up during creation.

Problem :

I am trying for the first time to implement Firebase Cloud Messaging in my Xamarin Forms Android application.

When I run the application, the FirebaseApp initialization is successful, the parsing of json file is ok and the token is generated.

FirebaseApp initialization

ID

Token

The problem is the registration of the app in the Firebase webpage is not happening. The last view of the registration is the following:

Firebase webpage

And it never stops verifying if the app has connected to their servers.

I double-checked if the name of the package is the same in both projects. I added json file to project and change its Build Action to GoogleServicesJson. I uninstalled and reinstalled the app in the device to get the token again. I tried to close and reopen the Firebase page in the browser. And I tried so many times to run the application with the Firebase webpage scanning connection of my the app to the server but the result is always the same.

See the code:

MainActivity.cs

namespace App2.Droid
{
    [Activity(Label = "App2", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        static readonly string TAG = "MainActivity";

        internal static readonly string CHANNEL_ID = "my_notification_channel";
        internal static readonly int NOTIFICATION_ID = 100;

        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());

            if (Intent.Extras != null)
            {
                foreach (var key in Intent.Extras.KeySet())
                {
                    var value = Intent.Extras.GetString(key);
                    Log.Debug(TAG, "Key: {0} Value: {1}", key, value);
                }
            }

            Log.Debug(TAG, "google app id: " + GetString(Resource.String.google_app_id));

            IsPlayServicesAvailable();

            CreateNotificationChannel();
        }

        public bool IsPlayServicesAvailable()
        {
            int resultCode = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable(this);
            if (resultCode != ConnectionResult.Success)
            {
                if (GoogleApiAvailability.Instance.IsUserResolvableError(resultCode))
                    Log.Debug(TAG, GoogleApiAvailability.Instance.GetErrorString(resultCode));
                else
                {
                    Log.Debug(TAG, "This device is not supported");
                    Finish();
                }
                return false;
            }
            else
            {
                Log.Debug(TAG, "Google Play Services is available.");
                return true;
            }
        }

        void CreateNotificationChannel()
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                // Notification channels are new in API 26 (and not a part of the
                // support library). There is no need to create a notification
                // channel on older versions of Android.
                return;
            }

            var channel = new NotificationChannel(CHANNEL_ID,
                                                  "FCM Notifications",
                                                  NotificationImportance.Default)
            {

                Description = "Firebase Cloud Messages appear in this channel"
            };

            var notificationManager = (NotificationManager)GetSystemService(Android.Content.Context.NotificationService);
            notificationManager.CreateNotificationChannel(channel);
        }
    }
}

AndroidContent.cs

namespace App2.Droid
{
    [Service]
    [IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
    public class MyFirebaseMessagingService : FirebaseMessagingService
    {
        const string TAG = "MyFirebaseMsgService";

        public override void OnNewToken(string p0)
        {
            base.OnNewToken(p0);
            Log.Debug(TAG, p0);
        }

        public override void OnMessageReceived(RemoteMessage message)
        {
            Log.Debug(TAG, "From: " + message.From);
            Log.Debug(TAG, "Notification Message Body: " + message.GetNotification().Body);
        }
    }
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns_android="http://schemas.android.com/apk/res/android" android_versionCode="1" android_versionName="1.0" package="com.companyname.app2" android_installLocation="auto">
    <uses-sdk android_minSdkVersion="26" android_targetSdkVersion="28" />
    <application android_label="App2.Android">
        <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>
    <uses-permission android_name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android_name="android.permission.INTERNET" />
    <permission android_name="${applicationId}.permission.C2D_MESSAGE" android_protectionLevel="signature" />
    <uses-permission android_name="${applicationId}.permission.C2D_MESSAGE" />
    <uses-permission android_name="android.permission.READ_PHONE_STATE" />
</manifest>

Anybody have any idea to fix this?

READ  [ANSWERED] android - Running two Countdown Timers Sequentially
Powered by Inline Related Posts

I am using:

Visual Studio 2019

Xamarin.Forms v4.7.0.1080

Xamarin.GooglePlayServices.Base v71.1610.1

Xamarin.Firebase.Messaging v71.1740.1

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress