update:2020.03.16 加入更新升级框架
This commit is contained in:
@@ -15,8 +15,8 @@ android {
|
|||||||
applicationId "com.info.sn"
|
applicationId "com.info.sn"
|
||||||
minSdkVersion 23
|
minSdkVersion 23
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 13
|
versionCode 15
|
||||||
versionName "1.1.3"
|
versionName "1.1.5"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
ndk {
|
ndk {
|
||||||
|
|||||||
@@ -136,7 +136,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
mHits = new long[COUNTS];//重新初始化数组
|
mHits = new long[COUNTS];//重新初始化数组
|
||||||
Toast.makeText(this, "正在检查更新", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "正在检查更新", Toast.LENGTH_SHORT).show();
|
||||||
HTTPInterface.checkUpdateByPackage(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
|
HTTPInterface.checkUpdateByPackage(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,6 +285,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void getFile(final Bundle bundle) {
|
private void getFile(final Bundle bundle) {
|
||||||
final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/");
|
final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/");
|
||||||
path.mkdirs();
|
path.mkdirs();
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import android.util.Log;
|
|||||||
import com.arialyy.annotations.Download;
|
import com.arialyy.annotations.Download;
|
||||||
import com.arialyy.aria.core.Aria;
|
import com.arialyy.aria.core.Aria;
|
||||||
import com.arialyy.aria.core.task.DownloadTask;
|
import com.arialyy.aria.core.task.DownloadTask;
|
||||||
//import com.blankj.utilcode.util.NetworkUtils;
|
|
||||||
import com.info.sn.network.api.HTTPInterface;
|
import com.info.sn.network.api.HTTPInterface;
|
||||||
import com.info.sn.utils.ApkUtils;
|
import com.info.sn.utils.ApkUtils;
|
||||||
import com.info.sn.utils.LogUtils;
|
import com.info.sn.utils.LogUtils;
|
||||||
@@ -33,6 +32,8 @@ import java.util.TreeMap;
|
|||||||
|
|
||||||
import cn.jpush.android.api.CustomMessage;
|
import cn.jpush.android.api.CustomMessage;
|
||||||
|
|
||||||
|
//import com.blankj.utilcode.util.NetworkUtils;
|
||||||
|
|
||||||
//public class MyApplication extends Application implements NetworkUtils.OnNetworkStatusChangedListener {
|
//public class MyApplication extends Application implements NetworkUtils.OnNetworkStatusChangedListener {
|
||||||
public class MyApplication extends Application {
|
public class MyApplication extends Application {
|
||||||
public static Context context;
|
public static Context context;
|
||||||
@@ -375,7 +376,11 @@ public class MyApplication extends Application {
|
|||||||
String url = extra.getString("url");
|
String url = extra.getString("url");
|
||||||
File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/apk");
|
File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/apk");
|
||||||
file.mkdirs();
|
file.mkdirs();
|
||||||
Aria.download(this).load(url).setFilePath(file.getAbsolutePath() + "/" + packages + ".apk").ignoreFilePathOccupy().setExtendField(packages).create();
|
Aria.download(this)
|
||||||
|
.load(url)
|
||||||
|
.setFilePath(file.getAbsolutePath() + "/" + packages + ".apk")
|
||||||
|
.ignoreFilePathOccupy()
|
||||||
|
.setExtendField(packages).create();
|
||||||
// OkGo.<File>get(url)
|
// OkGo.<File>get(url)
|
||||||
// .execute(new FileCallback() {
|
// .execute(new FileCallback() {
|
||||||
// @Override
|
// @Override
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import java.util.List;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class HTTPInterface {
|
public class HTTPInterface {
|
||||||
private final static int requestCodeOK = 200;
|
|
||||||
|
|
||||||
//获取设备信息接口
|
//获取设备信息接口
|
||||||
public static synchronized void checkDevicesInfo(final Handler handler) {
|
public static synchronized void checkDevicesInfo(final Handler handler) {
|
||||||
@@ -46,7 +45,7 @@ public class HTTPInterface {
|
|||||||
UserInfo userInfo = JSON.parseObject(data, UserInfo.class);
|
UserInfo userInfo = JSON.parseObject(data, UserInfo.class);
|
||||||
Message message = new Message();
|
Message message = new Message();
|
||||||
message.obj = userInfo;
|
message.obj = userInfo;
|
||||||
if (code == requestCodeOK) {
|
if (code == 200) {
|
||||||
message.what = 1;
|
message.what = 1;
|
||||||
handler.sendMessage(message);
|
handler.sendMessage(message);
|
||||||
} else if (code == -200) {
|
} else if (code == -200) {
|
||||||
@@ -96,7 +95,7 @@ public class HTTPInterface {
|
|||||||
UserInfo userInfo = JSON.parseObject(data, UserInfo.class);
|
UserInfo userInfo = JSON.parseObject(data, UserInfo.class);
|
||||||
Message message = new Message();
|
Message message = new Message();
|
||||||
message.obj = userInfo;
|
message.obj = userInfo;
|
||||||
if (code == requestCodeOK) {
|
if (code == 200) {
|
||||||
|
|
||||||
} else if (code == -200) {
|
} else if (code == -200) {
|
||||||
|
|
||||||
@@ -135,6 +134,7 @@ public class HTTPInterface {
|
|||||||
String url = data.getString("downloadurl");
|
String url = data.getString("downloadurl");
|
||||||
String newversion = data.getString("newversion");
|
String newversion = data.getString("newversion");
|
||||||
String content = data.getString("content");
|
String content = data.getString("content");
|
||||||
|
|
||||||
message.what = 200;
|
message.what = 200;
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString("url", url);
|
bundle.putString("url", url);
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import android.app.AlertDialog;
|
|||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -17,11 +19,9 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.info.sn.BuildConfig;
|
import com.info.sn.BuildConfig;
|
||||||
import com.info.sn.MyApplication;
|
|
||||||
import com.info.sn.R;
|
import com.info.sn.R;
|
||||||
import com.info.sn.network.api.HTTPInterface;
|
import com.info.sn.network.api.HTTPInterface;
|
||||||
import com.info.sn.utils.ApkUtils;
|
import com.info.sn.utils.ApkUtils;
|
||||||
import com.info.sn.utils.LogUtils;
|
|
||||||
import com.lzy.okgo.OkGo;
|
import com.lzy.okgo.OkGo;
|
||||||
import com.lzy.okgo.callback.FileCallback;
|
import com.lzy.okgo.callback.FileCallback;
|
||||||
import com.lzy.okgo.model.Progress;
|
import com.lzy.okgo.model.Progress;
|
||||||
@@ -49,6 +49,10 @@ public class MyDownloadService extends Service {
|
|||||||
startService(new Intent(this, StepService.class));
|
startService(new Intent(this, StepService.class));
|
||||||
startService(new Intent(this, GuardService.class));
|
startService(new Intent(this, GuardService.class));
|
||||||
CheckUpdate();
|
CheckUpdate();
|
||||||
|
CheckUpdateByPackageName("com.appstore.uiui", handler);
|
||||||
|
//静默升级应用市场
|
||||||
|
CheckUpdateByPackageName("com.uiuios.updatetools", handler);
|
||||||
|
//静默升级更新工具
|
||||||
HTTPInterface.getAllAppPackageName(handler);
|
HTTPInterface.getAllAppPackageName(handler);
|
||||||
|
|
||||||
// new Thread(new Runnable() {
|
// new Thread(new Runnable() {
|
||||||
@@ -68,6 +72,21 @@ public class MyDownloadService extends Service {
|
|||||||
// }).start();
|
// }).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synchronized private void CheckUpdateByPackageName(String packageName, Handler handlers) {
|
||||||
|
//检测设备信息的更新
|
||||||
|
PackageManager pm = getPackageManager();
|
||||||
|
PackageInfo packageInfo = null;
|
||||||
|
try {
|
||||||
|
packageInfo = pm.getPackageInfo(packageName, 0);
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (null != packageInfo) {
|
||||||
|
HTTPInterface.checkUpdateByPackage(handlers, packageName, String.valueOf(packageInfo.versionCode));
|
||||||
|
} else {
|
||||||
|
HTTPInterface.checkUpdateByPackage(handlers, packageName, "0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
@@ -95,8 +114,12 @@ public class MyDownloadService extends Service {
|
|||||||
case 201:
|
case 201:
|
||||||
String apppackage = (String) msg.obj;
|
String apppackage = (String) msg.obj;
|
||||||
Log.e("fht", Settings.System.getString(getContentResolver(), "qch_app_forbid") + "?");
|
Log.e("fht", Settings.System.getString(getContentResolver(), "qch_app_forbid") + "?");
|
||||||
if (Settings.System.putString(getContentResolver(), "qch_app_forbid", apppackage)) {
|
try {
|
||||||
Log.e("fht", "app package write successful");
|
if (Settings.System.putString(getContentResolver(), "qch_app_forbid", apppackage)) {
|
||||||
|
Log.e("fht", "app package write successful");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("fht", e.getMessage());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 202:
|
case 202:
|
||||||
|
|||||||
Reference in New Issue
Block a user