Skip to content

Latest commit

 

History

History
54 lines (45 loc) · 1.56 KB

mobile-services-xamarin-android-push-configure-project.md

File metadata and controls

54 lines (45 loc) · 1.56 KB
author ms.author ms.service ms.topic ms.date
conceptdev
crdun
app-service-mobile
include
08/23/2018
  1. 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.

  2. Open the ToDoActivity.cs project file and add the following using statement to the class:

    using Gcm.Client;
  3. 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.

  4. 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.