Giter Site home page Giter Site logo

gcm.client's Introduction

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

gcm.client's People

Contributors

redth avatar wilka avatar

Watchers

Branko Vukmirovic avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.