Back to project page wonderpush-android-sdk.
The source code is released under:
Apache License
If you think the Android project wonderpush-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.wonderpush.sdk; // www.j a v a 2 s.c o m import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.util.Log; /** * Receiver that refreshes the push token after each upgrade. * * <pre><code><application> * <receiver android:name="com.wonderpush.sdk.WonderPushOnUpgradeReceiver"> * <intent-filter> * <action android:name="android.intent.action.PACKAGE_REPLACED" /> * <data android:scheme="package" android:path="com.package" /> * </intent-filter> * </receiver> *</application></code></pre> */ public class WonderPushOnUpgradeReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { if (!WonderPushConfiguration.isInitialized()) { WonderPushConfiguration.initialize(context); } WonderPush.ensureInitialized(context); // Detect same-version-code updates, which can invalidate the push token in a few weeks. // This scenario typically only happens during development. int versionCode = WonderPush.getApplicationVersionCode(); if (WonderPushConfiguration.getGCMRegistrationAppVersionForUpdateReceiver() == versionCode) { // Forget the old registration id, it will expire soon WonderPushConfiguration.setGCMRegistrationId(null); // Force re-registration // Even if this call is concurrent with another update of push token (with an old value), // as this scenario is likely to reproduce soon in a classic development process, // and as Google registration ids are still valid for a few weeks, there is no service disruption. WonderPush.registerForPushNotification(context); } else { WonderPushConfiguration.setGCMRegistrationAppVersionForUpdateReceiver(versionCode); } } catch (Exception e) { Log.e(WonderPush.TAG, "Unexpected error", e); } } }