更换包名
This commit is contained in:
1 parent
35c747a334
commit
4f671a3b75
148 files changed
+585
-630
No files matched your search
@@ -0,0 +1,166 @@
|
||||
package com.fuying.sn.service;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Service;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.WindowManager;
|
||||
|
||||
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.ToastUtils;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.fuying.sn.KeepAliveConnection;
|
||||
import com.fuying.sn.R;
|
||||
import com.fuying.sn.service.main.MainService;
|
||||
import com.fuying.sn.utils.ApkUtils;
|
||||
import com.fuying.sn.gson.GsonUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
// 下载管理服务
|
||||
public class DownloadService extends Service {
|
||||
private static final String TAG = DownloadService.class.getSimpleName();
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
startService(new Intent(this, StepService.class));
|
||||
startService(new Intent(this, GuardService.class));
|
||||
startService(new Intent(this, MainService.class));
|
||||
startService(new Intent(this, ManagerService.class));
|
||||
startService(new Intent(this, ControlPanelService.class));
|
||||
Aria.download(this).register();
|
||||
//恢复所有未完成的下载任务
|
||||
Aria.download(this).resumeAllTask();
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return new KeepAliveConnection.Stub() {
|
||||
};
|
||||
}
|
||||
|
||||
private void getFile(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()) {
|
||||
// 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(DownloadService.this, file.getAbsolutePath());
|
||||
// dialogInterface.dismiss();
|
||||
// }
|
||||
// });
|
||||
// AlertDialog ad = builder.create();
|
||||
// ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
// ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
|
||||
// ad.show();
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
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.installApk(DownloadService.this, file);
|
||||
dialogInterface.dismiss();
|
||||
}
|
||||
});
|
||||
AlertDialog ad = builder.create();
|
||||
ad.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
ad.setCanceledOnTouchOutside(false); //点击外面区域不会让dialog消失
|
||||
ad.show();
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@Download.onTaskRunning
|
||||
void running(DownloadTask task) {
|
||||
Log.e("aria running", "正在下载:" + task.getState() + "-" + task.getPercent() + "--" + task.getExtendField());
|
||||
String appName = "";
|
||||
try {
|
||||
String jsonString = task.getExtendField();
|
||||
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
|
||||
if (!TextUtils.isEmpty(jsonString) && jsonObject != null) {
|
||||
appName = jsonObject.get("app_name").getAsString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("running", "running: " + e.getMessage());
|
||||
}
|
||||
ToastUtils.showShort("正在下载:" + appName + "-" + task.getPercent() + "%");
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(DownloadTask task) {
|
||||
//在这里处理任务完成的状态
|
||||
ApkUtils.installApp(DownloadService.this, task.getFilePath());
|
||||
Log.e("taskComplete", task.getExtendField());
|
||||
Aria.download(this).load(task.getDownloadEntity().getId()).cancel();
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
void taskFail(DownloadTask task, Exception e) {
|
||||
// Aria.download(this).resumeAllTask();
|
||||
final String filepath = task.getFilePath();
|
||||
final String packageName = task.getExtendField();
|
||||
try {
|
||||
Log.e(TAG, "taskFail: " + "Exception: " + e.getMessage());
|
||||
} catch (Exception ex) {
|
||||
Log.e(TAG, "taskFail: Exception = " + e.getMessage());
|
||||
}
|
||||
Log.e(TAG, "taskFail: " + packageName + "filepath: " + filepath);
|
||||
Aria.download(this).load(task.getDownloadEntity().getId()).cancel(true);
|
||||
// Aria.download(this)
|
||||
// .load(task.getDownloadEntity().getRealUrl()) //读取下载地址
|
||||
// .setFilePath(task.getFilePath())
|
||||
// .ignoreFilePathOccupy()
|
||||
// .setExtendField(task.getExtendField())
|
||||
// .create(); //启动下载}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user