Android Open Source - wonderpush-android-sdk Wonder Push On Upgrade Receiver






From Project

Back to project page wonderpush-android-sdk.

License

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.

Java Source Code

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>&lt;application&gt;
 *    &lt;receiver android:name="com.wonderpush.sdk.WonderPushOnUpgradeReceiver"&gt;
 *        &lt;intent-filter&gt;
 *            &lt;action android:name="android.intent.action.PACKAGE_REPLACED" /&gt;
 *            &lt;data android:scheme="package" android:path="com.package" /&gt;
 *        &lt;/intent-filter&gt;
 *    &lt;/receiver&gt;
 *&lt;/application&gt;</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);
        }
    }

}




Java Source Code List

com.wonderpush.sdk.QueryStringParser.java
com.wonderpush.sdk.WonderPushBroadcastReceiver.java
com.wonderpush.sdk.WonderPushCompatibilityHelper.java
com.wonderpush.sdk.WonderPushConfiguration.java
com.wonderpush.sdk.WonderPushDialogBuilder.java
com.wonderpush.sdk.WonderPushGcmClient.java
com.wonderpush.sdk.WonderPushInitializer.java
com.wonderpush.sdk.WonderPushJobQueue.java
com.wonderpush.sdk.WonderPushOnUpgradeReceiver.java
com.wonderpush.sdk.WonderPushRequestParamsDecorator.java
com.wonderpush.sdk.WonderPushRequestVault.java
com.wonderpush.sdk.WonderPushRestClient.java
com.wonderpush.sdk.WonderPushService.java
com.wonderpush.sdk.WonderPushUriHelper.java
com.wonderpush.sdk.WonderPushView.java
com.wonderpush.sdk.WonderPush.java
com.wonderpush.sdk.package-info.java