author | ms.author | ms.service | ms.topic | ms.date |
---|---|---|---|---|
conceptdev |
crdun |
app-service-mobile |
include |
08/23/2018 |
-
In the Solution view (or Solution Explorer in Visual Studio), right-click the Components folder, click Get More Components..., search for the Google Cloud Messaging Client component and add it to the project.
-
Open the ToDoActivity.cs project file and add the following using statement to the class:
using Gcm.Client;
-
In the ToDoActivity class, add the following new code:
// Create a new instance field for this activity. static ToDoActivity instance = new ToDoActivity(); // Return the current activity instance. public static ToDoActivity CurrentActivity { get { return instance; } } // Return the Mobile Services client. public MobileServiceClient CurrentClient { get { return client; } }
This enables you to access the mobile client instance from the push handler service process.
-
Add the following code to the OnCreate method, after the MobileServiceClient is created:
// Set the current instance of TodoActivity. instance = this; // Make sure the GCM client is set up correctly. GcmClient.CheckDevice(this); GcmClient.CheckManifest(this); // Register the app for push notifications. GcmClient.Register(this, ToDoBroadcastReceiver.senderIDs);
Your ToDoActivity is now prepared for adding push notifications.