With the last changes to Android GCM now a InstanceIDListenerService is provided to be able to listen to token refreshes by overriding the onTokenRefresh method.
But when will this method be called? And is there any way to test it manually?
To test it manually from the command line run:
adb shell am startservice -a com.google.android.gms.iid.InstanceID --es "CMD" "RST" -n your.package.name/your.own.MyInstanceIDListenerService
where:
This will send an intent to the service with the extras expected by the base class.
For this to work, the service needs to be set to exported
temporarily:
<service
android:name="your.own.MyInstanceIDListenerService"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID"/>
</intent-filter>
</service>
Note: this should only be done temporarily and never be exported in production or else other apps could access your service.