Forum Xamarin.Android

GCM Subscription Intent

cbravocbravo BOMember

Hello there,

I was just going over this tutorial: and notice it uses an Android Intent to generate a token using GCM. As per my basic understanding, an Intent is a thread started to do an activity. My question is, why do I need to do it in an Intent? Can't I just use a button "generate token" to get my token and send it to the server?

Thank you in advance.





    No, While registration It does not uses Intent to send and receive token, You just send senderId to GCM which gives you the registration Token. Here is a code

    var instanceID = InstanceID.GetInstance (this);
    var token = instanceID.GetToken (
    "YOUR_SENDER_ID", GoogleCloudMessaging.InstanceIdScope, null);

    However An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity , broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service .

    So, If you receive a Notification then if you want to go to an activity after clicking on a notification you basically uses PendingIntent to go to an Activity by clicking on a Notification.

    Here is a code for that PendingIntent pendingIntent =
    PendingIntent.GetActivity (this, pendingIntentId, intent, PendingIntentFlags.OneShot);

    // Instantiate the builder and set notification elements, including pending intent:
    Notification.Builder builder = new Notification.Builder(this)
    .SetContentIntent (pendingIntent)
    .SetContentTitle ("Sample Notification")
    .SetContentText ("Hello World! This is my first action notification!")
    .SetSmallIcon (Resource.Drawable.ic_notification);

    // Build the notification:
    Notification notification = builder.Build();

Sign In or Register to comment.