Xamrin Android Push Notification using Firebase Cloud Messaging


  1. Create a New Project. Select  Single-View App (Android) under Installed > Visual > C# >Android


  2. Open AndroidManifest.xml file under your Android project's Properties


  3. Copy value of package attribute in manifest tag


  4. Open your browser and goto https://console.firebase.google.com . Sign-in with your Google acoount create a new one


  5. Click on Add Project. Choose a project name. Here, the name is PushNotificationGCM


  6. Click on Add Firebase to your Android App


  7. Paste the package name copied in Step 3 and click Register App


  8. Click on Download google-services.json and click continue

  9. Copy google-services.json file into Android project


  10. Include google-services.json file into Project's Solution by clicking View All Files in Solution Explorer tab, Right-click google-services.json file and click Include In Project


  11. Right-click Android project and click Manage Nuget Packages


  12. Click on Browse tab, search for Xamarin.GooglePlayServices.Base and install the package


  13. Search for another Nuget package Xamarin.Firebase.Messaging and install the package


  14. Right-click project to Build Solution. Now Close and re-open Visual studio

  15. Right-click on google-services.json file and click Properties


  16. Select Build Action to be GoogleServiceJson


  17. Open AndroidManifest.xml under Android project's Properties


  18. Right-click Android project and click Properties. Goto Android Manifest tag and check INTERNET checkbox under Required permissions


  19. Add a new C# Code File. Name it according to your project. Here it's name is DemoFirebaseIdServices.cs . Include the following code


  20. Build the Solution and Run the project in debug mode on Android device.Make sure that the  device is connected to Internet and Google Play Services are installed on device


  21. Once the project is running watch the Output Window in Visual Studio where refresh token will appear. Copy the token.


  22. Open your Firebase project in browser that you created in Step 5. Click onNotification menu in Navigation bar on the right and click on Send Your First Message


  23. On the Compose message page, add message text, add message label, select Single device under Target section and add registration token copied in Step 22 and click Send Message


  24. The notification will then be sent to Single device and the next page shows status of sent Notification Message


  25. Completed status of notification message shows that the notification has successfully reached the target device

Comments

Post a Comment

Popular posts from this blog

Implementing Basic and JWT Token authentication with C# .NET

.NET Core 3 officially comes to Windows IoT Core

Setting up Free Custom Domain on Microsoft Azure Web App Service

Setting up CI and CD pipeline in Azure DevOps for ASP.NET Core and Azure Web Apps

Microsoft Azure DevOps : A Complete CI & CD solution in the cloud

Securing Powershell Scripts with Code-Signing Certificate

Understanding Powershell ExecutionPolicy and securing Powershell CmdLets/Scripts with Code-Signing Certificate

Microsoft Azure Blob Storage - Managing Blobs and storage containers from C#

Fundamental of Powershell Scripting