Reputation:
I have been reading this tutorial about Xamarin Android Push notifications using GCM, I have created the client APK
and the asp.NET
Server, but there's something I'm not able to use in ASP Project in here :
public string SendNotification(string deviceId, string message)....
var GoogleAppID = "123456789ABCDEFGHIJKLMNOP";
var SENDER_ID = "123456789";
var value = message;
var webRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
webRequest.Method = "post";
webRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
webRequest.Headers.Add(string.Format("Authorization: key={0}", GoogleAppID));
webRequest.Headers.Add(string.Format("Sender: id={0}", SENDER_ID));
var postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message="
+ value + "®istration_id=" + deviceId + "";
I have the SENDER_ID
and GoogleAppID
, but what is the deviceId
? The tutorial doesn't mention how to get this property, Does anyone know how to get this property! Thanks!
Upvotes: 3
Views: 2350
Reputation: 9703
If you check the source of the tutorial here, it has a OnRegistered method in the client that creates the deviceId.
protected override void OnRegistered (Context context, string registrationId)
{
Console.WriteLine ("Device Id:" + registrationId);
var preferences = GetSharedPreferences("AppData", FileCreationMode.Private);
var deviceId = preferences.GetString("DeviceId","");
if (string.IsNullOrEmpty (deviceId)) {
var editor = preferences.Edit ();
editor.PutString ("DeviceId", registrationId);
editor.Commit ();
}
}
Also from the tutorial:
Once the device registration is successful, you will get the registration id in the OnRegistered event.
they have implemented the method like so:
protected override void OnRegistered (Context context, string registrationId)
{
Console.WriteLine ("Device Id:" + registrationId);
}
Which is different from the source and might have caused confusion. I would have a look through the source to see if any other bits are missing from your implementation.
Upvotes: 1