I follow the wiki of the PushSharp project and i write this code to send a notification to my device.
Imports PushSharp
Imports PushSharp.Android
Imports PushSharp.Core
Module Module1
Sub Main()
Console.WriteLine("Start notification : ")
Dim push As New PushBroker()
AddHandler push.OnDeviceSubscriptionExpired, AddressOf DeviceSubscriptionChanged
AddHandler push.OnChannelException, AddressOf ChannelException
AddHandler push.OnServiceException, AddressOf ServiceException
AddHandler push.OnNotificationFailed, AddressOf NotificationFailed
AddHandler push.OnDeviceSubscriptionExpired, AddressOf DeviceSubscriptionExpired
AddHandler push.OnDeviceSubscriptionChanged, AddressOf DeviceSubscriptionChanged
AddHandler push.OnChannelCreated, AddressOf ChannelCreated
AddHandler push.OnChannelDestroyed, AddressOf ChannelDestroyed
push.RegisterGcmService(New GcmPushChannelSettings("AIzaSyCcyNj2Q8bHJqJ-gFR6N3CFtM_VJpv9lIE"))
push.QueueNotification(New GcmNotification().ForDeviceRegistrationId("APA91bGPD7eT7_MEqnL5D23BxihL3-4JkpFGpKy_2A2MNIJHFyEqhSM0iFVMRortNg_394VjsXqyuP0vbPbTQcWL-3ab_4mp-rUn4ypfkntqXfgurBeXOc6M5j25ewuclXuhezhV5yULQzpiJWoOlhYFn28Yx8iJRTA5jup4lKYBo7uVObSsLzs").WithJson("{""alert"":""Hello World2!"",""badge"":6,""sound"":""sound.caf""}"))
Console.WriteLine("Waiting for Queue to Finish...")
'Stop and wait for the queues to drains
push.StopAllServices(True)
Console.WriteLine("Queue Finished, press return to exit...")
Console.ReadLine()
End Sub
Sub DeviceSubscriptionChanged(sender As Object, oldSubscriptionId As String, newSubscriptionId As String, notification As INotification)
'Currently this event will only ever happen for Android GCM
Console.WriteLine("Device Registration Changed: Old-> " & oldSubscriptionId & " New-> " & newSubscriptionId & " -> " & Convert.ToString(notification))
End Sub
Sub NotificationSent(sender As Object, notification As INotification)
Console.WriteLine("Sent: " & Convert.ToString(sender) & " -> " & Convert.ToString(notification))
End Sub
Sub NotificationFailed(sender As Object, notification As INotification, notificationFailureException As Exception)
Console.WriteLine("Failure: " & Convert.ToString(sender) & " -> " & Convert.ToString(notificationFailureException.Message) & " -> " & Convert.ToString(notification))
End Sub
Sub ChannelException(sender As Object, channel As IPushChannel, exception As Exception)
Console.WriteLine("Channel Exception: " & Convert.ToString(sender) & " -> " & Convert.ToString(exception))
End Sub
Sub ServiceException(sender As Object, exception As Exception)
Console.WriteLine("Channel Exception: " & Convert.ToString(sender) & " -> " & Convert.ToString(exception))
End Sub
Sub DeviceSubscriptionExpired(sender As Object, expiredDeviceSubscriptionId As String, timestamp As DateTime, notification As INotification)
Console.WriteLine("Device Subscription Expired: " & Convert.ToString(sender) & " -> " & expiredDeviceSubscriptionId)
End Sub
Sub ChannelDestroyed(sender As Object)
Console.WriteLine("Channel Destroyed for: " & Convert.ToString(sender))
End Sub
Sub ChannelCreated(sender As Object, pushChannel As IPushChannel)
Console.WriteLine("Channel Created for: " & Convert.ToString(sender))
End Sub
End Module
i have a good api key and i get my registration id with a phonegap plugin. I have already test my api key and my registration id with a little npm module to send notification. When i lunch this code, nothing appened (no event match) and no notification on my phone.
Plz help me i really need this code.