2

I am using GCM in my android app. My app is totally based on GCM. I implemented client side and server side and working fine. I am having problem in expiration of registration with google server. I registered successfully but it register only for next 7 days. I already tried this `GCMRegistrar.setRegisteredOnServer(_context, true);

                    final long DEFAULT_ON_SERVER_LIFESPAN_MS =
                            1000 * 3600 * 24 * 365;
                    GCMRegistrar.setRegisterOnServerLifespan(_context, DEFAULT_ON_SERVER_LIFESPAN_MS);` 

but it still registering key for 7 days. I know if we change version code google server may change GCM key but right now I am not changing this version code. Any idea what should I do to overcome this expiration issue.

Zeeshan
  • 1,625
  • 17
  • 25
  • I found a similar question, maybe this can help :) [**Link**](http://stackoverflow.com/questions/11590482/do-gcm-registration-ids-expire) – so_jin_ee Feb 09 '15 at 16:58

1 Answers1

0

After reviewing GCMRegistrar class I see this function implementation

public static void setRegisteredOnServer(Context context, boolean flag)
{
SharedPreferences prefs = getGCMPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("onServer", flag);

long lifespan = getRegisterOnServerLifespan(context);
long expirationTime = System.currentTimeMillis() + lifespan;
Log.v("GCMRegistrar", "Setting registeredOnServer status as " + flag + " until " + new Timestamp(expirationTime));

editor.putLong("onServerExpirationTime", expirationTime);
editor.commit();
}

They are setting expirationTime in this function after getting lifespan. I was doing mistake that I was setting lifespan after this function calling so it was setting by default lifespan that is for 7 days in GCMRegistrar class. So I need to set lifespan first according to my need and then call setRegisterOnServer function. Now it expires GCM key that I set in setRegisterOnServerLifespan(context, lifespan).

Zeeshan
  • 1,625
  • 17
  • 25