Search code examples
androidasp.net-mvcpush-notificationtitaniumpushsharp

PushSharp - MismatchSenderID on android


I am trying to implement push notifications on Android devices. I have created a Google project and generated a server api key there.The server app is asp.net mvc. The client app is Titanium based and we set the sender id in the config file there. However I got a MismatchSenderId exception. Here is my code:

public void Notification()
        {
            var objPush = new PushBroker();

            objPush.OnNotificationSent += NotificationSent;
            objPush.OnChannelException += ChannelException;
            objPush.OnServiceException += ServiceException;
            objPush.OnNotificationFailed += NotificationFailed;
            objPush.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
            objPush.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
            objPush.OnChannelCreated += ChannelCreated;
            objPush.OnChannelDestroyed += ChannelDestroyed;

            objPush.RegisterGcmService(new GcmPushChannelSettings(ConfigurationManager.AppSettings["GoogleApiKey"]));

            string registrationId = "APA91bFKeXCvPi7f61N0zIp9wMWPUYk_-hxAlg7jApbskPhHrxH3CKYMQjUPdkqmy-_caNsO1cbKvsSUFi0cN2JcIEjg1-rX30AIW7lR8hjnvjwHI_tSyueXDUBJVuAQme9Lh5lWYd01";

            objPush.QueueNotification(new GcmNotification().ForDeviceRegistrationId(registrationId)
                                  .WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}"));

            objPush.StopAllServices(waitForQueuesToFinish: true);
        }

        static void DeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, INotification notification)
        {
            //Currently this event will only ever happen for Android GCM
            Trace.WriteLine("Device Registration Changed:  Old-> " + oldSubscriptionId + "  New-> " + newSubscriptionId + " -> " + notification);
        }

        static void NotificationSent(object sender, INotification notification)
        {
            Trace.WriteLine("Sent: " + sender + " -> " + notification);
        }

        static void NotificationFailed(object sender, INotification notification, Exception notificationFailureException)
        {
            Trace.WriteLine("Failure: " + sender + " -> " + notificationFailureException.Message + " -> " + notification);
        }

        static void ChannelException(object sender, IPushChannel channel, Exception exception)
        {
            Trace.WriteLine("Channel Exception: " + sender + " -> " + exception);
        }

        static void ServiceException(object sender, Exception exception)
        {
            Trace.WriteLine("Channel Exception: " + sender + " -> " + exception);
        }

        static void DeviceSubscriptionExpired(object sender, string expiredDeviceSubscriptionId, DateTime timestamp, INotification notification)
        {
            Trace.WriteLine("Device Subscription Expired: " + sender + " -> " + expiredDeviceSubscriptionId);
        }

        static void ChannelDestroyed(object sender)
        {
            Trace.WriteLine("Channel Destroyed for: " + sender);
        }

        static void ChannelCreated(object sender, IPushChannel pushChannel)
        {
            Trace.WriteLine("Channel Created for: " + sender);
        }

Any help will be highly appreciated.


Solution

  • Maybe try one of the several available GCM modules for Titanium? http://gitt.io/search?q=gcm

    Or use ArrowDB push notifications (which also uses GCM): http://docs.appcelerator.com/platform/latest/#!/guide/Configuring_push_services