Update v1.2.2版本的 MD5 值为:87ab33f0c8bd4c1dd345062aa2794e73
以下内容为反编译后的 DownAPKService.java 源代码,内容仅作参考
package com.luxcine.luxcine_ota.version;
import android.app.ActivityManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.IBinder;
import android.util.Log;
import com.google.gson.Gson;
import com.luxcine.luxcine_ota.MyApplication;
import com.luxcine.luxcine_ota.version.OkHttpUtil;
import java.util.List;
public class DownAPKService extends Service {
public static final String BASE_URL = "http://api.bq04.com/apps/latest/5f617b7db2eb467dd1a6abed?api_token=02adf1aa8df8c3aa9f2fb0026551e709";
private static final String TAG = "DownAPKService";
public static final String api_token = "02adf1aa8df8c3aa9f2fb0026551e709";
public static final String id = "5f617b7db2eb467dd1a6abed";
private IntentFilter intentFilter;
private NetworkBroadcast networkBroadcast;
private String newVersion;
private String oldVersion;
private String url;
private VersionModel versionModel;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
IntentFilter intentFilter = new IntentFilter();
this.intentFilter = intentFilter;
intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
NetworkBroadcast networkBroadcast = new NetworkBroadcast();
this.networkBroadcast = networkBroadcast;
registerReceiver(networkBroadcast, this.intentFilter);
}
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(this.networkBroadcast);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
public void initVersion() {
new OkHttpUtil().getAsynHttp("http://api.bq04.com/apps/latest/5f617b7db2eb467dd1a6abed?api_token=02adf1aa8df8c3aa9f2fb0026551e709", new OkHttpUtil.OnOkHttpListener() {
@Override
public void onSuccess(String response) {
Log.e(DownAPKService.TAG, "onSuccess: ---------------------" + response);
DownAPKService.this.versionModel = (VersionModel) new Gson().fromJson(response, (Class<Object>) VersionModel.class);
if (DownAPKService.this.versionModel != null) {
DownAPKService downAPKService = DownAPKService.this;
downAPKService.newVersion = downAPKService.versionModel.getVersionShort();
DownAPKService downAPKService2 = DownAPKService.this;
downAPKService2.url = downAPKService2.versionModel.getInstallUrl();
Log.e(DownAPKService.TAG, "onStartCommand: ---------------" + DownAPKService.this.oldVersion + "---" + DownAPKService.this.newVersion);
int old1 = Integer.parseInt(DownAPKService.this.oldVersion.replace(".", ""));
int new1 = Integer.parseInt(DownAPKService.this.newVersion.replace(".", ""));
if (new1 > old1) {
SilentUpdateAppManager updateAppManager = new SilentUpdateAppManager(MyApplication.getContext(), new1, DownAPKService.this.url);
updateAppManager.getUpdateMsg();
}
}
}
@Override
public void onFailure(Exception e) {
Log.e(DownAPKService.TAG, "onFailure: ---------------------" + e.toString());
}
});
}
public String getVersionCode() {
try {
this.oldVersion = MyApplication.getContext().getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
Log.e(TAG, "getVersionCode: ----------------------" + this.oldVersion);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return this.oldVersion;
}
public static boolean isApplicationBroughtToBackground(final Context context) {
ActivityManager am = (ActivityManager) context.getSystemService("activity");
List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
class NetworkBroadcast extends BroadcastReceiver {
private static final String TAG = "NetworkBroadcast";
NetworkBroadcast() {
}
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectionManager = (ConnectivityManager) MyApplication.getContext().getSystemService("connectivity");
NetworkInfo networkInfo = connectionManager.getActiveNetworkInfo();
if (networkInfo == null || !networkInfo.isAvailable()) {
Log.e(TAG, "onReceive: ------网络未连接---------------");
return;
}
Log.e(TAG, "onReceive: ------网络已连接---------------");
boolean b = DownAPKService.isApplicationBroughtToBackground(MyApplication.getContext());
Log.e(TAG, "onCreate: ---是否在前台-------------" + b);
if (b) {
DownAPKService.this.getVersionCode();
DownAPKService.this.initVersion();
}
}
}
}