Xamarin.Android.GCMClient 1.0.0

dotnet add package Xamarin.Android.GCMClient --version 1.0.0
                    
NuGet\Install-Package Xamarin.Android.GCMClient -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Xamarin.Android.GCMClient" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Xamarin.Android.GCMClient" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Xamarin.Android.GCMClient" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Xamarin.Android.GCMClient --version 1.0.0
                    
#r "nuget: Xamarin.Android.GCMClient, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Xamarin.Android.GCMClient@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Xamarin.Android.GCMClient&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Xamarin.Android.GCMClient&version=1.0.0
                    
Install as a Cake Tool

DEPRECATED

You should instead be using the Firebase Messaging Client for implementing push notifications on Android.

NuGet: https://www.nuget.org/packages/Xamarin.Firebase.Messaging/ Sample: https://github.com/xamarin/GooglePlayServicesComponents/tree/master/firebase-messaging/samples

Google Cloud Messaging Client

GCM (Google Cloud Messaging) is a component that makes getting your Xamarin.Android app setup to receive Push Notifications quickly and easily!

Registering for GCM Push Notifications

//Check to see that GCM is supported and that the manifest has the correct information
GcmClient.CheckDevice(this);
GcmClient.CheckManifest(this);

//Call to Register the device for Push Notifications
GcmClient.Register(this, GcmBroadcastReceiver.SENDER_IDS);

Service Implementation

Add these classes to your own project, and be sure to update the SENDER_IDS with your own Sender ID(s) from your Google API Console Project(s):

[BroadcastReceiver(Permission=Constants.PERMISSION_GCM_INTENTS)]
[IntentFilter(new string[] { Constants.INTENT_FROM_GCM_MESSAGE }, 
	Categories = new string[] { "@PACKAGE_NAME@" })]
[IntentFilter(new string[] { Constants.INTENT_FROM_GCM_REGISTRATION_CALLBACK }, 
	Categories = new string[] { "@PACKAGE_NAME@" })]
[IntentFilter(new string[] { Constants.INTENT_FROM_GCM_LIBRARY_RETRY }, 
	Categories = new string[] { "@PACKAGE_NAME@" })]
public class GcmBroadcastReceiver : GcmBroadcastReceiverBase<GcmService>
{
	//IMPORTANT: Change this to your own Sender ID!
	//The SENDER_ID is your Google API Console App Project Number
	public static string[] SENDER_IDS = new string[] {"697360970929"};
}

[Service] //Must use the service tag
public class GcmService : GcmServiceBase
{
	public GcmService() : base(GcmBroadcastReceiver.SENDER_IDS) { }

	protected override void OnRegistered (Context context, string registrationId)
	{
		//Receive registration Id for sending GCM Push Notifications to
	}

	protected override void OnUnRegistered (Context context, string registrationId)
	{
		//Receive notice that the app no longer wants notifications
	}

	protected override void OnMessage (Context context, Intent intent)
	{
		//Push Notification arrived - print out the keys/values
		if (intent != null && intent.Extras != null)
			foreach (var key in intent.Extras.KeySet())
				Console.WriteLine("Key: {0}, Value: {1}", key, intent.Extras.Get(key));
	}

	protected override bool OnRecoverableError (Context context, string errorId)
	{
		//Some recoverable error happened
	}

	protected override void OnError (Context context, string errorId)
	{
		//Some more serious error happened
	}
}

Changes

v1.0

  • First release
Product Compatible and additional computed target framework versions.
.NET net6.0-android was computed.  net7.0-android was computed.  net8.0-android was computed.  net9.0-android was computed.  net10.0-android was computed. 
MonoAndroid monoandroid is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Xamarin.Android.GCMClient:

Repository Stars
xamarin/mobile-samples
Version Downloads Last Updated
1.0.0 34,643 5/14/2018