package com.demo.lib.common.upgrade; import android.app.IntentService; import android.content.Intent; import com.demo.lib.common.util.common.PackageUtils2; public abstract class CheckUpdateService extends IntentService { public static final int UPDATE_NONE = -1; public static final int UPDATE_COMPULSION_NOT = 0; public static final int UPDATE_COMPULSION = 1; public CheckUpdateService() { super("CheckUpdateService"); } @Override protected void onHandleIntent(Intent intent) { Version version = getVersion(PackageUtils2.getVersionCode(this)); if (version == null) { return; } switch (version.getType()) { case UPDATE_NONE: break; case UPDATE_COMPULSION_NOT: { Intent intentUpdate = new Intent(this, UpdateActivity.class); intentUpdate.putExtra("download_url", version.getDownloadUrl()); intentUpdate.putExtra("file_name", version.getFileName()); intentUpdate.putExtra("notification_title", version.getTitle()); intentUpdate.putExtra("notification_description", version.getDescription()); startActivity(intentUpdate); } break; case UPDATE_COMPULSION: { Intent intentUpdate = new Intent(this, UpdateService.class); intentUpdate.putExtra("download_url", version.getDownloadUrl()); intentUpdate.putExtra("file_name", version.getFileName()); intentUpdate.putExtra("notification_title", version.getTitle()); intentUpdate.putExtra("notification_description", version.getDescription()); startService(intentUpdate); } break; default: break; } } public abstract Version getVersion(int currentVersionCode); }