update:2019.04.22
fix:增加绑定确认 add:
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
package com.info.sn.service;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
public class APKinstallReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// TODO: This method is called when the BroadcastReceiver is receiving
|
||||
// an Intent broadcast.
|
||||
|
||||
if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED) || intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
|
||||
String packageName = intent.getDataString().replace("package:", "");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.info.sn.service;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class BootReceiver extends BroadcastReceiver {
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Log.e("SNBootReceiver", intent.getAction());
|
||||
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);
|
||||
// context.startService(i);
|
||||
context.startService(new Intent(context, StepService.class));
|
||||
context.startService(new Intent(context, GuardService.class));
|
||||
context.startService(new Intent(context, MyDownloadService.class));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package com.info.sn.service;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.drafts.Draft_6455;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
public class JWebSocketClient extends WebSocketClient {
|
||||
public JWebSocketClient(URI serverUri) {
|
||||
super(serverUri, new Draft_6455());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(ServerHandshake handshakedata) {
|
||||
Log.i("JWebSocketClient", "onOpen()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
Log.i("JWebSocketClient", "onMessage()");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int code, String reason, boolean remote) {
|
||||
Log.i("JWebSocketClient", "onClose():" + reason);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception ex) {
|
||||
Log.i("JWebSocketClient", "onError():" + ex.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,11 @@ import android.view.WindowManager;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.info.sn.BuildConfig;
|
||||
import com.info.sn.R;
|
||||
import com.info.sn.network.api.HTTPInterface;
|
||||
@@ -28,9 +33,10 @@ import com.lzy.okgo.model.Progress;
|
||||
import com.lzy.okgo.model.Response;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
// 下载管理服务
|
||||
public class MyDownloadService extends Service {
|
||||
public class MyDownloadService extends Service implements NetworkUtils.OnNetworkStatusChangedListener {
|
||||
|
||||
|
||||
@Override
|
||||
@@ -46,6 +52,10 @@ public class MyDownloadService extends Service {
|
||||
CheckUpdateByPackageName("com.uiuios.updatetools", handler);
|
||||
//静默升级更新工具
|
||||
HTTPInterface.getAllAppPackageName(handler);
|
||||
Aria.download(this).register();
|
||||
|
||||
Aria.download(this).resumeAllTask();
|
||||
//恢复所有未完成的下载任务
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@@ -265,4 +275,31 @@ public class MyDownloadService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(NetworkUtils.NetworkType networkType) {
|
||||
Aria.download(this).resumeAllTask();
|
||||
}
|
||||
|
||||
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@Download.onTaskRunning
|
||||
protected void running(DownloadTask task) {
|
||||
ToastUtils.showShort("正在下载:" + task.getExtendField() + "-" + task.getPercent() + "%");
|
||||
Log.e("aria running", "正在下载:" + task.getState() + "--" + task.getPercent() + "--" + task.getExtendField());
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(DownloadTask task) {
|
||||
//在这里处理任务完成的状态
|
||||
ApkUtils.installApp(MyDownloadService.this, task.getFilePath());
|
||||
Log.e("taskComplete", task.getExtendField());
|
||||
Aria.download(this).load(task.getDownloadEntity().getId()).cancel();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.util.Log;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.info.sn.KeepAliveConnection;
|
||||
import com.info.sn.network.JWebSocketClient;
|
||||
import com.info.sn.utils.LogUtils;
|
||||
import com.info.sn.utils.ServiceAliveUtils;
|
||||
import com.info.sn.utils.Utils;
|
||||
|
||||
Reference in New Issue
Block a user