Crashes on device with older Google Play Services
java.lang.RuntimeException: Unable to start receiver com.cuneytayyildiz.simplegcm.GcmPackageReplacedReceiver: java.lang.ClassCastException: android.app.ReceiverRestrictedContext cannot be cast to android.app.Activity at android.app.ActivityThread.handleReceiver(ActivityThread.java:2824) at android.app.ActivityThread.access$1800(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1484) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:168) at android.app.ActivityThread.main(ActivityThread.java:5845) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) Caused by: java.lang.ClassCastException: android.app.ReceiverRestrictedContext cannot be cast to android.app.Activity at com.cuneytayyildiz.simplegcm.Utils.checkCanAndShouldRegister(Utils.java:51) at com.cuneytayyildiz.simplegcm.GcmPackageReplacedReceiver.onReceive(GcmPackageReplacedReceiver.java:16) at android.app.ActivityThread.handleReceiver(ActivityThread.java:2810) at android.app.ActivityThread.access$1800(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1484) at android.os.Handler.dispatchMessage(Handler.java:102)
It appears to me that the check for Google Play Services is already done (indirectly) by SimpleGcm.init(), so that init() call just needs to inform the user and also prevent checkCanAndShouldRegister() from being called by GcmPackageReplacedReceiver in such a scenario.
Does that make sense?