update:2019.03.18
fix:增加桌面,应用市场,updatetools静默安装。增加亮屏后检测更新 add:
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 15
|
versionCode 16
|
||||||
versionName "1.1.5"
|
versionName "1.1.6"
|
||||||
multiDexEnabled true
|
multiDexEnabled true
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
ndk {
|
ndk {
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="com.info.sn"
|
package="com.info.sn">
|
||||||
>
|
|
||||||
|
<uses-permission android:name="android.permission.ACTION_SCREEN_ON" />
|
||||||
|
<uses-permission android:name="android.permission.ACTION_SCREEN_OFF" />
|
||||||
|
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
|
||||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
|
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
|
||||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||||
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
|
||||||
<uses-permission android:name="android.permission.INSTALL_PACKAGES" />
|
|
||||||
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
|
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
|
||||||
<uses-permission android:name="android.permission.MASTER_CLEAR" />
|
<uses-permission android:name="android.permission.MASTER_CLEAR" />
|
||||||
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" /> <!-- 系统权限,有系统签名可以使用 -->
|
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" /> <!-- 系统权限,有系统签名可以使用 -->
|
||||||
@@ -170,6 +172,16 @@
|
|||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter android:priority="1000">
|
<intent-filter android:priority="1000">
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
|
||||||
|
<action android:name="android.intent.action.BATTERY_CHANGED" />
|
||||||
|
<action android:name="android.intent.action.BATTERY_LEVEL_CHANGED" />
|
||||||
|
<action android:name="android.intent.action.BATTERY_LOW" />
|
||||||
|
<action android:name="android.intent.action.BATTERY_OKAY" />
|
||||||
|
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
|
||||||
|
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
|
||||||
|
<action android:name="android.intent.action.DATE_CHANGED" />
|
||||||
|
<action android:name="android.intent.action.TIME_TICK" />
|
||||||
|
<action android:name="android.intent.action.USER_PRESENT" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver> <!-- User defined. For test only 用户自定义的广播接收器 -->
|
</receiver> <!-- User defined. For test only 用户自定义的广播接收器 -->
|
||||||
<receiver
|
<receiver
|
||||||
|
|||||||
161
app/src/main/assets/aria_config.xml
Normal file
161
app/src/main/assets/aria_config.xml
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<aria>
|
||||||
|
<!--注意,修改该配置文件中的属性会覆盖代码中所设置的属性-->
|
||||||
|
|
||||||
|
<!--Aria框架配置-->
|
||||||
|
<app>
|
||||||
|
<!--是否使用AriaCrashHandler来捕获异常,异常日志保存在:/mnt/sdcard/Android/data/{package_name}/files/log/-->
|
||||||
|
<useAriaCrashHandler value="true"/>
|
||||||
|
<!--设置Aria的日志级别,{@link ALog#LOG_LEVEL_VERBOSE}-->
|
||||||
|
<logLevel value="2"/>
|
||||||
|
<!-- 是否检查网络 true: 检查网络,false: 不检查网络-->
|
||||||
|
<netCheck value="true"/>
|
||||||
|
<!--除非无法使用注解,否则不建议使用广播来接受任务状态,true:使用广播接收任务状态,false:不适用广播接收状态 -->
|
||||||
|
<!-- http://aria.laoyuyu.me/aria_doc/api/use_broadcast.html -->
|
||||||
|
<useBroadcast value="true"/>
|
||||||
|
<!--断网的时候是否重试,true:断网也重试;false:断网不重试,直接走失败的回调-->
|
||||||
|
<notNetRetry value="true"/>
|
||||||
|
</app>
|
||||||
|
|
||||||
|
|
||||||
|
<!--普通下载任务-->
|
||||||
|
<download>
|
||||||
|
|
||||||
|
<!--设置任务最大下载速度,0表示不限速,单位为:kb-->
|
||||||
|
<maxSpeed value="0"/>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
多线程下载是否使用块下载模式,{@code true}使用,{@code false}不使用
|
||||||
|
注意:
|
||||||
|
1、使用分块模式,在I/O性能底下的手机上,合并文件需要的时间会更加长;
|
||||||
|
2、优点是使用多线程的块下载,初始化时,文件初始化时将不会预占用对应长度的空间;
|
||||||
|
3、只对新的多线程下载任务有效
|
||||||
|
4、只对多线程的任务有效
|
||||||
|
-->
|
||||||
|
<useBlock value="true"/>
|
||||||
|
|
||||||
|
<!--设置下载线程数,下载线程数不能小于1
|
||||||
|
注意:
|
||||||
|
1、线程下载数改变后,新的下载任务才会生效;
|
||||||
|
2、如果任务大小小于1m,该设置不会生效;
|
||||||
|
3、从3.4.1开始,如果线程数为1,文件初始化时将不再预占用对应长度的空间,下载多少byte,则占多大的空间;
|
||||||
|
对于3.4.1之前版本的未完成的老任务,依然采用原来的文件空间占用方式;
|
||||||
|
-->
|
||||||
|
<threadNum value="3"/>
|
||||||
|
|
||||||
|
<!--设置下载队列最大任务数, 默认为2-->
|
||||||
|
<maxTaskNum value="1"/>
|
||||||
|
|
||||||
|
<!--设置下载失败,重试次数,默认为10-->
|
||||||
|
<reTryNum value="10"/>
|
||||||
|
|
||||||
|
<!--设置重试间隔,单位为毫秒,默认2000毫秒-->
|
||||||
|
<reTryInterval value="5000"/>
|
||||||
|
|
||||||
|
<!--设置url连接超时时间,单位为毫秒,默认5000毫秒-->
|
||||||
|
<connectTimeOut value="5000"/>
|
||||||
|
|
||||||
|
<!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
|
||||||
|
<iOTimeOut value="10000"/>
|
||||||
|
|
||||||
|
<!--设置写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢-->
|
||||||
|
<buffSize value="8192"/>
|
||||||
|
|
||||||
|
<!--设置https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名-->
|
||||||
|
<ca name="" path=""/>
|
||||||
|
|
||||||
|
<!--是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度-->
|
||||||
|
<convertSpeed value="true"/>
|
||||||
|
|
||||||
|
<!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait-->
|
||||||
|
<queueMod value="wait"/>
|
||||||
|
|
||||||
|
<!--进度更新更新间隔,默认1000毫秒-->
|
||||||
|
<updateInterval value="1000"/>
|
||||||
|
|
||||||
|
</download>
|
||||||
|
|
||||||
|
<!--普通上传任务-->
|
||||||
|
<upload>
|
||||||
|
<!--设置任务最大上传速度,0表示不限速,单位为:kb-->
|
||||||
|
<maxSpeed value="0"/>
|
||||||
|
|
||||||
|
<!--设置IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
|
||||||
|
<iOTimeOut value="10000"/>
|
||||||
|
|
||||||
|
<!--设置写文件buff大小,该数值大小不能小于2048,数值变小,速度会变慢-->
|
||||||
|
<buffSize value="8192"/>
|
||||||
|
|
||||||
|
<!--是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度-->
|
||||||
|
<convertSpeed value="true"/>
|
||||||
|
|
||||||
|
<!--设置上传队列最大任务数, 默认为2-->
|
||||||
|
<maxTaskNum value="2"/>
|
||||||
|
|
||||||
|
<!--设置上传失败,重试次数,默认为10-->
|
||||||
|
<reTryNum value="3"/>
|
||||||
|
|
||||||
|
<!--设置重试间隔,单位为毫秒-->
|
||||||
|
<reTryInterval value="2000"/>
|
||||||
|
|
||||||
|
<!--设置url连接超时时间,单位为毫秒,默认5000毫秒-->
|
||||||
|
<connectTimeOut value="5000"/>
|
||||||
|
|
||||||
|
<!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait-->
|
||||||
|
<queueMod value="wait"/>
|
||||||
|
|
||||||
|
<!--进度更新更新间隔,默认1000毫秒-->
|
||||||
|
<updateInterval value="1000"/>
|
||||||
|
|
||||||
|
</upload>
|
||||||
|
|
||||||
|
<!-- 下载类组合任务 -->
|
||||||
|
<dGroup>
|
||||||
|
|
||||||
|
<!--组合任务下载队列最大任务数, 默认为2-->
|
||||||
|
<maxTaskNum value="1"/>
|
||||||
|
|
||||||
|
<!--设置下载失败,重试次数,默认为10-->
|
||||||
|
<reTryNum value="10"/>
|
||||||
|
|
||||||
|
<!--设置重试间隔,单位为毫秒,默认2000毫秒-->
|
||||||
|
<reTryInterval value="5000"/>
|
||||||
|
|
||||||
|
<!--执行队列类型,见com.arialyy.aria.core.QueueMod,默认类型为wait-->
|
||||||
|
<queueMod value="wait"/>
|
||||||
|
|
||||||
|
<!--进度更新更新间隔,默认1000毫秒-->
|
||||||
|
<updateInterval value="1000"/>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- =============================以下为子任务的配置====================================-->
|
||||||
|
|
||||||
|
<!--能同时下载的子任务最大任务数,默认3-->
|
||||||
|
<subMaxTaskNum value="1"/>
|
||||||
|
|
||||||
|
<!--子任务下载失败时的重试次数,默认为5-->
|
||||||
|
<subReTryNum value="5"/>
|
||||||
|
|
||||||
|
<!--子任务下载失败时的重试间隔,单位为毫秒,默认2000毫秒-->
|
||||||
|
<subReTryInterval value="5000"/>
|
||||||
|
|
||||||
|
<!--子任务url连接超时时间,单位为毫秒,默认5000毫秒-->
|
||||||
|
<connectTimeOut value="5000"/>
|
||||||
|
|
||||||
|
<!--子任务IO流读取时间,单位为毫秒,默认20000毫秒,该时间不能少于10000毫秒-->
|
||||||
|
<iOTimeOut value="10000"/>
|
||||||
|
|
||||||
|
<!--子任务写文件buff大小,该数值大小不能小于2048,数值变小,下载速度会变慢-->
|
||||||
|
<buffSize value="8192"/>
|
||||||
|
|
||||||
|
<!--子任务 https ca 证书信息;path 为assets目录下的CA证书完整路径,name 为CA证书名-->
|
||||||
|
<ca name="" path=""/>
|
||||||
|
|
||||||
|
<!--子任务是否需要转换速度单位,转换完成后为:1b/s、1kb/s、1mb/s、1gb/s、1tb/s,如果不需要将返回byte长度-->
|
||||||
|
<convertSpeed value="true"/>
|
||||||
|
|
||||||
|
<!--子任务的最大下载速度,0表示不限速,单位为:kb; -->
|
||||||
|
<maxSpeed value="0"/>
|
||||||
|
|
||||||
|
</dGroup>
|
||||||
|
</aria>
|
||||||
@@ -94,6 +94,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
initView();
|
initView();
|
||||||
initData();
|
initData();
|
||||||
HTTPInterface.checkDevicesInfo(handler);
|
HTTPInterface.checkDevicesInfo(handler);
|
||||||
|
HTTPInterface.checkUpdateByself(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
|
||||||
startService(new Intent(MainActivity.this, MyDownloadService.class));
|
startService(new Intent(MainActivity.this, MyDownloadService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +136,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) {
|
if (mHits[0] >= (SystemClock.uptimeMillis() - DURATION)) {
|
||||||
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.checkUpdateByself(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,21 +276,27 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
SPUtils.put(MainActivity.this, "isLogined", 2);
|
SPUtils.put(MainActivity.this, "isLogined", 2);
|
||||||
setImageAndText(imageView, "未经验证的设备,请联系客服");
|
setImageAndText(imageView, "未经验证的设备,请联系客服");
|
||||||
break;
|
break;
|
||||||
case 200:
|
case 300:
|
||||||
Bundle bundle = (Bundle) msg.obj;
|
Bundle bundle = (Bundle) msg.obj;
|
||||||
getFile(bundle);
|
getFile(bundle);
|
||||||
break;
|
break;
|
||||||
case -200:
|
case -200:
|
||||||
ToastUtil.show("已是最新版本");
|
ToastUtil.show("已是最新版本");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case -300:
|
||||||
|
ToastUtil.show("网络连接失败,检查网络连接");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void getFile(final Bundle bundle) {
|
private void getFile(final Bundle bundle) {
|
||||||
|
String url = bundle.getString("url");
|
||||||
|
|
||||||
final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/");
|
final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/");
|
||||||
path.mkdirs();
|
path.mkdirs();
|
||||||
final File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/Update" + bundle.getString("versionCode") + ".apk");
|
final File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/" + url.substring(url.lastIndexOf("/") + 1));
|
||||||
|
|
||||||
if (file.exists() && file.isFile()) {
|
if (file.exists() && file.isFile()) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||||
@@ -309,8 +316,8 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
|
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
|
||||||
ad.show();
|
ad.show();
|
||||||
} else {
|
} else {
|
||||||
OkGo.<File>get(bundle.getString("url"))
|
OkGo.<File>get(url)
|
||||||
.execute(new FileCallback("Sninfo/Update" + bundle.getString("versionCode") + ".apk") {
|
.execute(new FileCallback("Sninfo/" + url.substring(url.lastIndexOf("/") + 1)) {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(final Response<File> response) {
|
public void onSuccess(final Response<File> response) {
|
||||||
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
||||||
|
|||||||
@@ -143,20 +143,65 @@ public class HTTPInterface {
|
|||||||
message.obj = bundle;
|
message.obj = bundle;
|
||||||
}
|
}
|
||||||
handler.sendMessage(message);
|
handler.sendMessage(message);
|
||||||
Log.e("checkUpdateByPackage", msg);
|
Log.e("checkUpdateSN", msg);
|
||||||
} else {
|
} else {
|
||||||
handler.sendEmptyMessage(-200);
|
handler.sendEmptyMessage(-200);
|
||||||
Log.e("checkUpdateByPackage", msg);
|
Log.e("checkUpdateSN", msg);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e("checkUpdateByPackage", e.getMessage());
|
Log.e("checkUpdateSN", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Response<String> response) {
|
public void onError(Response<String> response) {
|
||||||
super.onError(response);
|
super.onError(response);
|
||||||
Log.e("checkUpdateByPackage", response.getException().toString());
|
handler.sendEmptyMessage(-300);
|
||||||
|
Log.e("checkUpdateSN", response.getException().toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
synchronized public static void checkUpdateByself(final Handler handler, String packageName, String versionCode) {
|
||||||
|
OkGo.<String>post(UrlPath.GET_APP_UPDATE)
|
||||||
|
.params("code", versionCode)
|
||||||
|
.params("package", packageName)
|
||||||
|
.execute(new StringCallback() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(Response<String> response) {
|
||||||
|
try {
|
||||||
|
JSONObject body = JSON.parseObject(response.body());
|
||||||
|
int code = body.getInteger("code");
|
||||||
|
String msg = body.getString("msg");
|
||||||
|
if (code == 200) {
|
||||||
|
Message message = new Message();
|
||||||
|
JSONObject data = JSON.parseObject(body.getString("data"));
|
||||||
|
if (data != null) {
|
||||||
|
String url = data.getString("downloadurl");
|
||||||
|
String newversion = data.getString("newversion");
|
||||||
|
String content = data.getString("content");
|
||||||
|
message.what = 300;
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("url", url);
|
||||||
|
bundle.putString("versionCode", newversion);
|
||||||
|
bundle.putString("content", content);
|
||||||
|
message.obj = bundle;
|
||||||
|
}
|
||||||
|
handler.sendMessage(message);
|
||||||
|
Log.e("checkUpdateSN", msg);
|
||||||
|
} else {
|
||||||
|
handler.sendEmptyMessage(-200);
|
||||||
|
Log.e("checkUpdateSN", msg);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e("checkUpdateSN", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Response<String> response) {
|
||||||
|
super.onError(response);
|
||||||
|
handler.sendEmptyMessage(-300);
|
||||||
|
Log.e("checkUpdateSN", response.getException().toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,24 @@ public class BootReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Log.e("BootReceiver", intent.getAction());
|
Log.e("SNBootReceiver", intent.getAction());
|
||||||
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
|
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")
|
||||||
|
|| intent.getAction().equals("android.intent.action.BATTERY_CHANGED")
|
||||||
|
|| intent.getAction().equals("android.intent.action.BATTERY_LEVEL_CHANGED")
|
||||||
|
|| intent.getAction().equals("android.intent.action.BATTERY_LOW")
|
||||||
|
|| intent.getAction().equals("android.intent.action.BATTERY_OKAY")
|
||||||
|
|| intent.getAction().equals("android.intent.action.ACTION_POWER_CONNECTED")
|
||||||
|
|| intent.getAction().equals("android.intent.action.ACTION_POWER_DISCONNECTED")
|
||||||
|
|| intent.getAction().equals("android.intent.action.DATE_CHANGED")
|
||||||
|
|| intent.getAction().equals("android.intent.action.TIME_TICK")
|
||||||
|
|| intent.getAction().equals("android.intent.action.USER_PRESENT")
|
||||||
|
|| intent.getAction().equals("android.intent.action.ACTION_SCREEN_ON")
|
||||||
|
|| intent.getAction().equals("android.intent.action.ACTION_SCREEN_OFF")) {
|
||||||
// Intent i = new Intent(context, InitJpushServer.class);
|
// Intent i = new Intent(context, InitJpushServer.class);
|
||||||
// context.startService(i);
|
// context.startService(i);
|
||||||
context.startService(new Intent(context, StepService.class));
|
context.startService(new Intent(context, StepService.class));
|
||||||
context.startService(new Intent(context, GuardService.class));
|
context.startService(new Intent(context, GuardService.class));
|
||||||
|
context.startService(new Intent(context, MyDownloadService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,24 +36,24 @@ public class MyDownloadService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
flags = START_STICKY;
|
flags = START_STICKY;
|
||||||
return super.onStartCommand(intent, flags, startId);
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized private void CheckUpdate() {
|
|
||||||
HTTPInterface.checkUpdateByPackage(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
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.appstore.uiui", handler);
|
||||||
//静默升级应用市场
|
//静默升级应用市场
|
||||||
|
CheckUpdateByPackageName("com.android.uiuios", handler);
|
||||||
|
//静默升级桌面
|
||||||
CheckUpdateByPackageName("com.uiuios.updatetools", handler);
|
CheckUpdateByPackageName("com.uiuios.updatetools", handler);
|
||||||
//静默升级更新工具
|
//静默升级更新工具
|
||||||
HTTPInterface.getAllAppPackageName(handler);
|
HTTPInterface.getAllAppPackageName(handler);
|
||||||
|
return super.onStartCommand(intent, flags, startId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
|
||||||
|
|
||||||
// new Thread(new Runnable() {
|
// new Thread(new Runnable() {
|
||||||
// @Override
|
// @Override
|
||||||
@@ -72,8 +72,11 @@ public class MyDownloadService extends Service {
|
|||||||
// }).start();
|
// }).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
synchronized private void CheckUpdate() {
|
||||||
|
HTTPInterface.checkUpdateByself(handler, this.getPackageName(), String.valueOf(BuildConfig.VERSION_CODE));
|
||||||
|
}
|
||||||
|
|
||||||
synchronized private void CheckUpdateByPackageName(String packageName, Handler handlers) {
|
synchronized private void CheckUpdateByPackageName(String packageName, Handler handlers) {
|
||||||
//检测设备信息的更新
|
|
||||||
PackageManager pm = getPackageManager();
|
PackageManager pm = getPackageManager();
|
||||||
PackageInfo packageInfo = null;
|
PackageInfo packageInfo = null;
|
||||||
try {
|
try {
|
||||||
@@ -124,14 +127,85 @@ public class MyDownloadService extends Service {
|
|||||||
break;
|
break;
|
||||||
case 202:
|
case 202:
|
||||||
break;
|
break;
|
||||||
|
case 300:
|
||||||
|
Bundle b = (Bundle) msg.obj;
|
||||||
|
update(b);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private void getFile(final Bundle bundle) {
|
private void getFile(final Bundle bundle) {
|
||||||
|
String url = bundle.getString("url");
|
||||||
|
|
||||||
final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/");
|
final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/");
|
||||||
path.mkdirs();
|
path.mkdirs();
|
||||||
final File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/Update" + bundle.getString("versionCode") + ".apk");
|
final File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/" + url.substring(url.lastIndexOf("/") + 1));
|
||||||
|
|
||||||
|
if (file.exists() && file.isFile()) {
|
||||||
|
// AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||||
|
// .setTitle("软件更新")
|
||||||
|
// .setIcon(R.mipmap.ic_launcher)
|
||||||
|
// .setCancelable(false)
|
||||||
|
// .setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content"))
|
||||||
|
// .setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||||
|
// @Override
|
||||||
|
// public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
ApkUtils.installApp(MyDownloadService.this, file.getAbsolutePath());
|
||||||
|
// dialogInterface.dismiss();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// AlertDialog ad = builder.create();
|
||||||
|
// ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||||
|
// ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
|
||||||
|
// ad.show();
|
||||||
|
} else {
|
||||||
|
OkGo.<File>get(url)
|
||||||
|
.execute(new FileCallback("Sninfo/" + url.substring(url.lastIndexOf("/") + 1)) {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(final Response<File> response) {
|
||||||
|
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
||||||
|
// ApkUtils.installApkInSilence(response.body().getAbsolutePath(), Launcher.this.getPackageName());
|
||||||
|
// AlertDialog.Builder builder = new AlertDialog.Builder(MyDownloadService.this)
|
||||||
|
// .setTitle("软件更新")
|
||||||
|
// .setIcon(R.mipmap.ic_launcher)
|
||||||
|
// .setCancelable(false)
|
||||||
|
// .setMessage("发现新版本,点击确定更新\n" + "更新内容:" + bundle.getString("content"))
|
||||||
|
// .setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||||
|
// @Override
|
||||||
|
// public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
ApkUtils.installApp(MyDownloadService.this, response.body().getAbsolutePath());
|
||||||
|
// dialogInterface.dismiss();
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
// AlertDialog ad = builder.create();
|
||||||
|
// ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||||
|
// ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
|
||||||
|
// ad.show();
|
||||||
|
Log.e("getFile", "download file successful,now installing");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onError(Response<File> response) {
|
||||||
|
super.onError(response);
|
||||||
|
Log.e("getFile", "File download Failure" + response.getException());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downloadProgress(Progress progress) {
|
||||||
|
super.downloadProgress(progress);
|
||||||
|
Log.e("getFile", "已下载:" + progress.currentSize + ",总大小:" + progress.totalSize + ",进度:" + progress.fraction + ",当前网速:" + progress.speed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void update(final Bundle bundle) {
|
||||||
|
String url = bundle.getString("url");
|
||||||
|
|
||||||
|
final File path = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/");
|
||||||
|
path.mkdirs();
|
||||||
|
final File file = new File(Environment.getExternalStoragePublicDirectory("Download") + "/Sninfo/" + url.substring(url.lastIndexOf("/") + 1));
|
||||||
|
|
||||||
if (file.exists() && file.isFile()) {
|
if (file.exists() && file.isFile()) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
||||||
@@ -151,8 +225,8 @@ public class MyDownloadService extends Service {
|
|||||||
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
|
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
|
||||||
ad.show();
|
ad.show();
|
||||||
} else {
|
} else {
|
||||||
OkGo.<File>get(bundle.getString("url"))
|
OkGo.<File>get(url)
|
||||||
.execute(new FileCallback("Sninfo/Update" + bundle.getString("versionCode") + ".apk") {
|
.execute(new FileCallback("Sninfo/" + url.substring(url.lastIndexOf("/") + 1)) {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(final Response<File> response) {
|
public void onSuccess(final Response<File> response) {
|
||||||
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
// Settings.System.putString(getApplicationContext().getContentResolver(), "qch_app_forbid", "com.baidu.video");
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import android.widget.Toast;
|
|||||||
import androidx.core.content.FileProvider;
|
import androidx.core.content.FileProvider;
|
||||||
|
|
||||||
|
|
||||||
|
import com.info.sn.BuildConfig;
|
||||||
import com.info.sn.R;
|
import com.info.sn.R;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -335,6 +336,49 @@ public class ApkUtils {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static boolean installApp(Context context, String apkPath) {
|
||||||
|
ToastUtil.show("正在安装应用...");
|
||||||
|
Process process = null;
|
||||||
|
BufferedReader successResult = null;
|
||||||
|
BufferedReader errorResult = null;
|
||||||
|
StringBuilder successMsg = new StringBuilder();
|
||||||
|
StringBuilder errorMsg = new StringBuilder();
|
||||||
|
try {
|
||||||
|
process = new ProcessBuilder("pm", "install", "-i", BuildConfig.APPLICATION_ID, "--user", "0", apkPath).start();
|
||||||
|
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||||
|
String s;
|
||||||
|
while ((s = successResult.readLine()) != null) {
|
||||||
|
successMsg.append(s);
|
||||||
|
}
|
||||||
|
while ((s = errorResult.readLine()) != null) {
|
||||||
|
errorMsg.append(s);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (successResult != null) {
|
||||||
|
successResult.close();
|
||||||
|
}
|
||||||
|
if (errorResult != null) {
|
||||||
|
errorResult.close();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
if (process != null) {
|
||||||
|
process.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.e("result", "" + errorMsg.toString());
|
||||||
|
//如果含有“success”认为安装成功
|
||||||
|
Log.e("installApp", successMsg.toString());
|
||||||
|
// if (!successMsg.toString().equalsIgnoreCase("success")) {
|
||||||
|
// ApkUtils.install(context, new File(apkPath));
|
||||||
|
// }
|
||||||
|
return successMsg.toString().equalsIgnoreCase("success");
|
||||||
|
}
|
||||||
|
|
||||||
public static void deleteApkInSilence(String packageName) {
|
public static void deleteApkInSilence(String packageName) {
|
||||||
Class<?> pmService;
|
Class<?> pmService;
|
||||||
|
|||||||
Reference in New Issue
Block a user