Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added one missing bit

  • Loading branch information...
commit 5b5d613a757b12662ce9a3c548f13c431eeff8c0 1 parent c8b945e
@Redth authored
View
48 GCMSharp.Client/GCMBaseIntentService.cs
@@ -23,7 +23,7 @@ public abstract class GCMBaseIntentService : IntentService
static object LOCK = new object();
string mSenderId;
- int sCounter = 1;
+ //int sCounter = 1;
Random sRandom = new Random();
const int MAX_BACKOFF_MS = 3600000; //1 hour
@@ -65,15 +65,57 @@ protected override void OnHandleIntent(Intent intent)
if (action.Equals(GCMConstants.INTENT_FROM_GCM_REGISTRATION_CALLBACK))
{
-
+ handleRegistration(context, intent);
}
else if (action.Equals(GCMConstants.INTENT_FROM_GCM_MESSAGE))
{
-
+ // checks for special messages
+ var messageType = intent.GetStringExtra(GCMConstants.EXTRA_SPECIAL_MESSAGE);
+ if (messageType != null)
+ {
+ if (messageType.Equals(GCMConstants.VALUE_DELETED_MESSAGES))
+ {
+ var sTotal = intent.GetStringExtra(GCMConstants.EXTRA_TOTAL_DELETED);
+ if (!string.IsNullOrEmpty(sTotal))
+ {
+ int nTotal = 0;
+ if (int.TryParse(sTotal, out nTotal))
+ {
+ Log.Verbose(TAG, "Received deleted messages notification: " + nTotal);
+ OnDeletedMessages(context, nTotal);
+ }
+ else
+ Log.Error(TAG, "GCM returned invalid number of deleted messages: " + sTotal);
+ }
+ }
+ else
+ {
+ // application is not using the latest GCM library
+ Log.Error(TAG, "Received unknown special message: " + messageType);
+ }
+ }
+ else
+ {
+ OnMessage(context, intent);
+ }
}
else if (action.Equals(GCMConstants.INTENT_FROM_GCM_LIBRARY_RETRY))
{
+ var token = intent.GetStringExtra(EXTRA_TOKEN);
+ if (!string.IsNullOrEmpty(token) && !TOKEN.Equals(token))
+ {
+ // make sure intent was generated by this class, not by a
+ // malicious app.
+ Log.Error(TAG, "Received invalid token: " + token);
+ return;
+ }
+
+ // retry last call
+ if (GCMRegistrar.IsRegistered(context))
+ GCMRegistrar.internalUnRegister(context);
+ else
+ GCMRegistrar.internalRegister(context, mSenderId);
}
}
finally
View
4 GCMSharp.Client/GCMBroadcastReceiver.cs
@@ -13,6 +13,10 @@
namespace GCMSharp.Client
{
+ [BroadcastReceiver(Permission=GCMConstants.PERMISSION_GCM_INTENTS)]
+ [IntentFilter(new string[] { GCMConstants.INTENT_FROM_GCM_MESSAGE })]
+ [IntentFilter(new string[] { GCMConstants.INTENT_FROM_GCM_REGISTRATION_CALLBACK })]
+ [IntentFilter(new string[] { GCMConstants.INTENT_FROM_GCM_LIBRARY_RETRY })]
public class GCMBroadcastReceiver : BroadcastReceiver
{
const string TAG = "GCMBroadcastReceiver";
View
4 GCMSharp.Client/GCMRegistrar.cs
@@ -125,7 +125,7 @@ public static void Register(Context context, params string[] senderIds)
internalRegister(context, senderIds);
}
- static void internalRegister(Context context, params string[] senderIds)
+ internal static void internalRegister(Context context, params string[] senderIds)
{
if (senderIds == null || senderIds.Length <= 0)
throw new ArgumentException("No senderIds");
@@ -150,7 +150,7 @@ public static void UnRegister(Context context)
internalUnRegister(context);
}
- static void internalUnRegister(Context context)
+ internal static void internalUnRegister(Context context)
{
Log.Verbose(TAG, "Unregistering app " + context.PackageName);

4 comments on commit 5b5d613

@nikunjclarion

In this solution I am missing Android dll file....
At many place it's reference has been given like Android.Content etc...
But while I am running the code there is no dll file available with this solution.

Can you please add the latest dll file with this solution?

@Redth
Owner

This is only meant to be used in a client application using Mono for Android check out https://github.com/Redth/PushSharp for .NET library to send push notifications out. This project (GCMSharp), is strictly a port of the client gcm.jar that google released for Android application development. Sorry if there was any confusion!

@nikunjclarion

https://github.com/Redth/PushSharp example is for "C2DM".
And I want to implement for the "GCM".

As there is migration from the "C2DM" to "GCM".
Reference : http://developer.android.com/guide/google/gcm/c2dm.html

Can you please provide any help to implement the GCM implementation for push notification by using Asp.Net or CSharp?

@Redth
Owner
Please sign in to comment.
Something went wrong with that request. Please try again.