Xamarin Mobile Development for Android Cookbook by 2015

Xamarin Mobile Development for Android Cookbook by 2015

Author:2015
Language: eng
Format: mobi
Publisher: Packt Publishing


The receiver will redirect any messages to a service for processing. The service inherits from GcmListenerService and has a specific intent filter. We can then process the message in the OnMessageReceived() method:[Service] [IntentFilter(new []{ "com.google.android.c2dm.intent.RECEIVE })] public class NotificationService : GcmListenerService { public override void OnMessageReceived( string from, Bundle data) { // process the data bundle var message = data.GetString("cookbook_message"); } }

Sometimes the token becomes invalid, for example if the server or Google decide to refresh the tokens. When this happens, our app will be notified:

To handle token refresh events, we create an interface that inherits from the InstanceIDListenerService type:[Service] [IntentFilter( new []{ "com.google.android.gms.iid.InstanceID" })] public class InstanceIdService : InstanceIDListenerService { public override void OnTokenRefresh() { var instanceId = InstanceID.GetInstance(this); var token = instanceId.GetToken( "PROJECT_NUMBER", GoogleCloudMessaging.InstanceIdScope); } }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.