update
This commit is contained in:
@@ -6,11 +6,12 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
|
||||
<application
|
||||
android:name=".MyApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:icon="@mipmap/ic_app"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
|
||||
13
app/src/main/aidl/com/appstore/uiui/IMyAidlInterface.aidl
Normal file
13
app/src/main/aidl/com/appstore/uiui/IMyAidlInterface.aidl
Normal file
@@ -0,0 +1,13 @@
|
||||
// IMyAidlInterface.aidl
|
||||
package com.appstore.uiui;
|
||||
|
||||
// Declare any non-default types here with import statements
|
||||
|
||||
interface IMyAidlInterface {
|
||||
/**
|
||||
* Demonstrates some basic types that you can use as parameters
|
||||
* and return values in AIDL.
|
||||
*/
|
||||
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
|
||||
double aDouble, String aString);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.appstore.uiui.utils.ToastUtil;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
|
||||
@@ -56,10 +57,10 @@ public class MyApplication extends Application {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
app = this;
|
||||
ToastUtil.init(this);
|
||||
OkGo.getInstance().init(this);
|
||||
// AppUtil.getInstalledApp(this);
|
||||
Aria.init(this);
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||
Aria.download(this).register();
|
||||
if (!isDebug(this)) {
|
||||
catchException();
|
||||
@@ -96,5 +97,7 @@ public class MyApplication extends Application {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Context getAppContext() {
|
||||
return getAppContext();
|
||||
}
|
||||
}
|
||||
|
||||
164
app/src/main/java/com/appstore/uiui/bean/AppDateInfo.java
Normal file
164
app/src/main/java/com/appstore/uiui/bean/AppDateInfo.java
Normal file
@@ -0,0 +1,164 @@
|
||||
package com.appstore.uiui.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2016/10/9.
|
||||
*/
|
||||
public class AppDateInfo implements Serializable {
|
||||
|
||||
public String id;
|
||||
public String app_name;
|
||||
public String app_package;
|
||||
public String app_version_name;
|
||||
public String app_desc;
|
||||
public String app_downloads;
|
||||
public String app_size;
|
||||
public String app_img;
|
||||
public String app_url;
|
||||
public String app_createtime;
|
||||
public String app_score;
|
||||
public String xitong_id;
|
||||
public String zixitong_id;
|
||||
public String app_tag;
|
||||
|
||||
public String getType() {
|
||||
return app_tag;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.app_tag = type;
|
||||
}
|
||||
|
||||
public String getXitong_id() {
|
||||
return xitong_id;
|
||||
}
|
||||
|
||||
public void setXitong_id(String xitong_id) {
|
||||
this.xitong_id = xitong_id;
|
||||
}
|
||||
|
||||
public String getZixitong_id() {
|
||||
return zixitong_id;
|
||||
}
|
||||
|
||||
public void setZixitong_id(String zixitong_id) {
|
||||
this.zixitong_id = zixitong_id;
|
||||
}
|
||||
|
||||
public String getApp_down() {
|
||||
return app_downloads;
|
||||
}
|
||||
|
||||
public void setApp_down(String app_down) {
|
||||
this.app_downloads = app_down;
|
||||
}
|
||||
|
||||
public String getApp_desc() {
|
||||
return app_desc;
|
||||
}
|
||||
|
||||
public void setApp_desc(String app_desc) {
|
||||
this.app_desc = app_desc;
|
||||
}
|
||||
|
||||
public String getApp_pfen() {
|
||||
return app_score;
|
||||
}
|
||||
|
||||
public void setApp_pfen(String app_pfen) {
|
||||
this.app_score = app_pfen;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getApp_name() {
|
||||
return app_name;
|
||||
}
|
||||
|
||||
public void setApp_name(String app_name) {
|
||||
this.app_name = app_name;
|
||||
}
|
||||
|
||||
public String getApp_baoming() {
|
||||
return app_package;
|
||||
}
|
||||
|
||||
public void setApp_baoming(String app_baoming) {
|
||||
this.app_package = app_baoming;
|
||||
}
|
||||
|
||||
public String getApp_banben() {
|
||||
return app_version_name;
|
||||
}
|
||||
|
||||
public void setApp_banben(String app_banben) {
|
||||
this.app_version_name = app_banben;
|
||||
}
|
||||
|
||||
public String getApp_size() {
|
||||
return app_size;
|
||||
}
|
||||
|
||||
public void setApp_size(String app_size) {
|
||||
this.app_size = app_size;
|
||||
}
|
||||
|
||||
public String getApp_img() {
|
||||
return app_img;
|
||||
}
|
||||
|
||||
public void setApp_img(String app_img) {
|
||||
this.app_img = app_img;
|
||||
}
|
||||
|
||||
public String getApp_title() {
|
||||
return app_desc;
|
||||
}
|
||||
|
||||
public void setApp_title(String app_tag) {
|
||||
this.app_desc = app_tag;
|
||||
}
|
||||
|
||||
public String getApp_file() {
|
||||
return app_url;
|
||||
}
|
||||
|
||||
public void setApp_file(String app_file) {
|
||||
this.app_url = app_file;
|
||||
}
|
||||
|
||||
public String getApp_time() {
|
||||
return app_createtime;
|
||||
}
|
||||
|
||||
public void setApp_time(String app_time) {
|
||||
this.app_createtime = app_time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AppDateInfo{" +
|
||||
"id='" + id + '\'' +
|
||||
", app_name='" + app_name + '\'' +
|
||||
", app_package='" + app_package + '\'' +
|
||||
", app_version_name='" + app_version_name + '\'' +
|
||||
", app_desc='" + app_desc + '\'' +
|
||||
", app_downloads='" + app_downloads + '\'' +
|
||||
", app_size='" + app_size + '\'' +
|
||||
", app_img='" + app_img + '\'' +
|
||||
", app_url='" + app_url + '\'' +
|
||||
", app_createtime='" + app_createtime + '\'' +
|
||||
", app_score='" + app_score + '\'' +
|
||||
", xitong_id='" + xitong_id + '\'' +
|
||||
", zixitong_id='" + zixitong_id + '\'' +
|
||||
", app_tag='" + app_tag + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
118
app/src/main/java/com/appstore/uiui/bean/AppDownloadInfo.java
Normal file
118
app/src/main/java/com/appstore/uiui/bean/AppDownloadInfo.java
Normal file
@@ -0,0 +1,118 @@
|
||||
package com.appstore.uiui.bean;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2016/10/9.
|
||||
*/
|
||||
public class AppDownloadInfo implements Serializable {
|
||||
|
||||
private String url; //文件URL
|
||||
private String targetPath; //保存文件地址
|
||||
private String fileName; //保存的文件名
|
||||
private float progress; //下载进度
|
||||
private int state; //当前状态
|
||||
private long totalLength; //总大小
|
||||
private long downloadLength; //已下载大小
|
||||
private String packageName; //保存的包名
|
||||
public String version;; //版本信息
|
||||
private Serializable data; //额外的数据
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
AppDownloadInfo info = (AppDownloadInfo) obj;
|
||||
return url.equals(info.getUrl()) && packageName.equals(info.packageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
String str = url + packageName;
|
||||
return str.hashCode();
|
||||
}
|
||||
|
||||
public Serializable getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(Serializable data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public AppDownloadInfo() {
|
||||
super();
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getPackageName() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public void setPackageName(String packageName) {
|
||||
this.packageName = packageName;
|
||||
}
|
||||
|
||||
public long getTotalLength() {
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
public void setTotalLength(long totalLength) {
|
||||
this.totalLength = totalLength;
|
||||
}
|
||||
|
||||
public long getDownloadLength() {
|
||||
return downloadLength;
|
||||
}
|
||||
|
||||
public void setDownloadLength(long downloadLength) {
|
||||
this.downloadLength = downloadLength;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(int state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getTargetPath() {
|
||||
return targetPath;
|
||||
}
|
||||
|
||||
public void setTargetPath(String targetPath) {
|
||||
this.targetPath = targetPath;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public float getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public void setProgress(float progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
85
app/src/main/java/com/appstore/uiui/common/CommonDatas.java
Normal file
85
app/src/main/java/com/appstore/uiui/common/CommonDatas.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.appstore.uiui.common;
|
||||
|
||||
|
||||
import com.appstore.uiui.BuildConfig;
|
||||
|
||||
public class CommonDatas {
|
||||
|
||||
public static final String PACKAGE = "colorflykids";
|
||||
public static String BABYINFO_CHANGE = PACKAGE + "babyinfo_change"; // 宝宝信息变更标识
|
||||
|
||||
|
||||
|
||||
public final static String SP_LOCK = "lock";//锁定用户
|
||||
public final static String SP_BABY_AGE_KEY = "age_system";//子系统选择
|
||||
public final static String SP_LOCK__KEY = "lock_key";//主界面选择
|
||||
|
||||
public final static String SP_USER_NAME = "user_name";//用户名字
|
||||
public final static String SP_USER_PASSWORD = "user_password";//用户密码
|
||||
public final static String SP_USER_EMAIL = "user_email";//用户信箱
|
||||
public final static String SP_VERSION = "user_version";//版本信息
|
||||
public final static String SP_USER_VIP = "user_vip";//用户等级
|
||||
public final static String SP_USER_DATE = "user_vip_date";//体验用户使用时间段
|
||||
public final static String SP_USER_ALIVE_DATE = "SP_USER_ALIVE_DATE";//用户激活时的时间
|
||||
public final static String SP_USER_ALIVE_CODE = "SP_USER_ALIVE_CODE";//用户激活码
|
||||
|
||||
|
||||
public final static String SP_BABY_HEAD = "age_head";//宝宝头像
|
||||
public final static String SP_BABY_NAME = "age_name";//宝宝名字
|
||||
public final static String SP_BABY_SEX = "age_sex";//宝宝性别
|
||||
public final static String SP_BABY_BIRTHDAY = "age_birthday";//宝宝生日
|
||||
|
||||
public final static String SP_BABY_TITLE = "user_title";//宝宝称谓
|
||||
public final static String SP_TOTAL_POINT = "total_point";//总积分
|
||||
public final static String SP_TODAY_POINT = "today_point";//今日积分
|
||||
public final static String SP_NATIONAL_RANK = "national_rank";//全国排名
|
||||
public final static String SP_YESTERDAY_RANK = "yesterday_rank";//历史排名
|
||||
public final static String SP_TODAY_RANK = "today_rank";//今日排名
|
||||
|
||||
|
||||
public final static String SP_PARENT_PASSWORD = "parent_password";//家长密码
|
||||
public final static String SP_OLD_PARENT_PASSWORD = "old_parent_password";//旧的家长密码
|
||||
public final static String SP_CHANGE_PARENT_PASSWORD = "change_parent_password";//上传家长密码标识
|
||||
public final static String SP_CHANGE_BABY_INFO = "change_baby_info";//上传宝宝信息标识
|
||||
public final static String SP_CHANGE_LEARN_INFO = "change_learn_info";//上传学习日志标识
|
||||
|
||||
|
||||
public final static String SP_TIME_CONTROL_NOW = "time_control_now";//时间控制功能临时开关
|
||||
public final static String SP_TIME_CONTROL_KEY = "time_control";//时间控制功能开关
|
||||
public final static String SP_TIME_CURRENT_REMAINING = "current_remaining_time";//当前剩余时间
|
||||
public final static String SP_TIME_REST_REMAINING = "current_rest_time";//当前剩余休息时间
|
||||
public final static String SP_BATTEY_CONTROL_KEY = "battey_control";//充电保护开关
|
||||
public final static String SP_PASSWORD_LOCK = "password_lock";//家长密码开关
|
||||
public final static String SP_DISTANCE_CONTROL_KEY = "distance_control";//距离感应开关
|
||||
|
||||
// 使用时间段
|
||||
public final static String SP_SELECT_START_TIME = "start_time";
|
||||
public final static String SP_SELECT_END_TIME = "end_time";
|
||||
public final static String SP_OLD_START_TIME = "old_start_time";
|
||||
public final static String SP_OLD_END_TIME = "old_end_time";
|
||||
|
||||
|
||||
public final static String SP_SELECT_USE_TIME = "useTimeLong";//使用时长
|
||||
public final static String SP_SELECT_REST_TIME = "restTimeLong";//休息时长
|
||||
|
||||
//eventbus 事件
|
||||
public final static String SP_LOGIN_SUCCESS = "SP_LOGIN_SUCCESS";//账号登陆成功
|
||||
|
||||
public final static String ENTER_KEY = "enter_key";
|
||||
|
||||
public final static String UPDATE_URL = "http://www.jiaoguanyi.cn/api/update/index";
|
||||
public final static String UPDATE_PKG = BuildConfig.APPLICATION_ID;
|
||||
|
||||
|
||||
public static boolean IS_UPDATE_DOLOADING = false;
|
||||
public static String IS_RESET = "IS_RESET";
|
||||
public static int MIN_POWER = 21;
|
||||
public static String FORCE_INSTALL = "FORCE_INSTALL";
|
||||
|
||||
public static final String ACTION_HrReceiver_JGY_DIS = "qch_jgy_network_disallow";
|
||||
public static final String ACTION_HrReceiver_JGY = "qch_jgy_network_allow";
|
||||
public static final String FLAG_FIRST_ENTER = "qch_first_enter";
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -3,11 +3,9 @@ package com.appstore.uiui.fragment;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@@ -19,8 +17,9 @@ import com.appstore.uiui.base.LazyLoadFragment;
|
||||
import com.appstore.uiui.base.RefreshManager;
|
||||
import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.bean.AppInfos;
|
||||
|
||||
import com.appstore.uiui.network.OKGOPost;
|
||||
import com.appstore.uiui.network.URLs.Url;
|
||||
import com.appstore.uiui.utils.LogUtils;
|
||||
import com.appstore.uiui.utils.ToastUtil;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.StringCallback;
|
||||
@@ -85,37 +84,8 @@ public class FeaturedFragment extends LazyLoadFragment implements RefreshManager
|
||||
initAPPData(handler);
|
||||
}
|
||||
|
||||
private void initAPPData(final Handler handler) {
|
||||
OkGo.<String>post(Url.GET_ALL_APPINFO).execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(Response<String> response) {
|
||||
try {
|
||||
JSONObject body = JSON.parseObject(response.body());
|
||||
// Log.e("onSuccess", body.toString());
|
||||
int code = body.getInteger("code");
|
||||
String msg = body.getString("msg");
|
||||
String data = body.getString("data");
|
||||
List<AppInfo> applist = JSON.parseArray(data, AppInfo.class);
|
||||
if (code == 200) {
|
||||
Message message = new Message();
|
||||
message.what = 0;
|
||||
message.obj = applist;
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
ToastUtil.show(msg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("Exception", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Response<String> response) {
|
||||
super.onError(response);
|
||||
Log.e("Exception", response.getException().toString());
|
||||
|
||||
}
|
||||
});
|
||||
synchronized private void initAPPData(final Handler handler) {
|
||||
OKGOPost.getAllAppInfo(handler);
|
||||
mRefreshLayout.finishRefresh();
|
||||
|
||||
}
|
||||
|
||||
59
app/src/main/java/com/appstore/uiui/network/OKGOPost.java
Normal file
59
app/src/main/java/com/appstore/uiui/network/OKGOPost.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package com.appstore.uiui.network;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.appstore.uiui.bean.AppInfo;
|
||||
import com.appstore.uiui.network.URLs.Url;
|
||||
import com.appstore.uiui.utils.LogUtils;
|
||||
import com.appstore.uiui.utils.ToastUtil;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.callback.StringCallback;
|
||||
import com.lzy.okgo.model.Response;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.Call;
|
||||
|
||||
|
||||
public class OKGOPost {
|
||||
synchronized public static void getAllAppInfo(final Handler handler) {
|
||||
OkGo.post(Url.GET_ALL_APPINFO).execute(new StringCallback() {
|
||||
@Override
|
||||
public void onSuccess(String s, Call call, okhttp3.Response response) {
|
||||
try {
|
||||
JSONObject body = JSON.parseObject(s);
|
||||
// Log.e("onSuccess", body.toString());
|
||||
int code = body.getInteger("code");
|
||||
String msg = body.getString("msg");
|
||||
String data = body.getString("data");
|
||||
List<AppInfo> applist = JSON.parseArray(data, AppInfo.class);
|
||||
if (code == 200) {
|
||||
Message message = new Message();
|
||||
message.what = 0;
|
||||
message.obj = applist;
|
||||
handler.sendMessage(message);
|
||||
} else {
|
||||
ToastUtil.show(msg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e("Exception", e.getMessage());
|
||||
ToastUtil.show("服务器错误,请稍后重试");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Call call, okhttp3.Response response, Exception e) {
|
||||
super.onError(call, response, e);
|
||||
LogUtils.e("Exception", e.getMessage());
|
||||
ToastUtil.show("网络连接失败,检查网络连接");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.appstore.uiui.service;
|
||||
|
||||
/**
|
||||
* 作者 mjsheng
|
||||
* 日期 2019/4/1 10:58
|
||||
* 邮箱 501802639@qq.com
|
||||
* 来自:
|
||||
*/
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.ServiceAliveUtils;
|
||||
import com.arialyy.annotations.Download;
|
||||
import com.arialyy.aria.core.Aria;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
|
||||
|
||||
/**
|
||||
* 守护进程 双进程通讯
|
||||
*
|
||||
* @author LiGuangMin
|
||||
* @time Created by 2018/8/17 11:27
|
||||
*/
|
||||
public class GuardService extends Service {
|
||||
private final static String TAG = GuardService.class.getSimpleName();
|
||||
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||
LogUtils.e(TAG, "GuardService:建立链接");
|
||||
boolean isServiceRunning = ServiceAliveUtils.isServiceAlice();
|
||||
if (!isServiceRunning) {
|
||||
Intent i = new Intent(GuardService.this, MyDownloadService.class);
|
||||
startService(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName componentName) {
|
||||
// 断开链接
|
||||
startService(new Intent(GuardService.this, StepService.class));
|
||||
// 重新绑定
|
||||
bindService(new Intent(GuardService.this, StepService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
// return new KeepAliveConnection.Stub() {};
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
|
||||
Aria.init(this);
|
||||
Aria.get(this).getDownloadConfig().setMaxTaskNum(1);
|
||||
|
||||
|
||||
Aria.download(this).register();
|
||||
|
||||
|
||||
// startForeground(1, new Notification());
|
||||
// 绑定建立链接
|
||||
bindService(new Intent(this, StepService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
//在这里处理任务执行中的状态,如进度进度条的刷新
|
||||
@Download.onTaskRunning
|
||||
protected void running(DownloadTask task) {
|
||||
Log.e("mjsheng", "我在下载=--------------::" + task.getState() + "-------" + task.getPercent() + "-------" + task.getExtendField());
|
||||
ToastUtils.showShort("我在下载=--------------::" + task.getExtendField() + "-------" + task.getPercent());
|
||||
}
|
||||
|
||||
@Download.onTaskComplete
|
||||
void taskComplete(DownloadTask task) {
|
||||
//在这里处理任务完成的状态
|
||||
String downloadPath = task.getFilePath();
|
||||
String packageName = task.getExtendField();
|
||||
Log.e("mjsheng", "downloadPath::" + downloadPath);
|
||||
Log.e("mjsheng", "extendField::" + packageName);
|
||||
ApkUtils.installApkInSilence(downloadPath, packageName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,347 @@
|
||||
|
||||
package com.appstore.uiui.service;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.IBinder;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.appstore.uiui.MyApplication;
|
||||
import com.appstore.uiui.bean.AppDateInfo;
|
||||
import com.appstore.uiui.bean.AppDownloadInfo;
|
||||
import com.appstore.uiui.utils.ApkUtils;
|
||||
import com.appstore.uiui.utils.SaveListUtils;
|
||||
import com.appstore.uiui.utils.StorageUtils;
|
||||
import com.appstore.uiui.utils.Utils;
|
||||
import com.lzy.okgo.OkGo;
|
||||
import com.lzy.okgo.request.GetRequest;
|
||||
import com.lzy.okserver.download.DownloadInfo;
|
||||
import com.lzy.okserver.download.DownloadManager;
|
||||
import com.lzy.okserver.download.DownloadService;
|
||||
import com.lzy.okserver.listener.DownloadListener;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// 下载管理服务
|
||||
public class MyDownloadService extends Service {
|
||||
|
||||
private DownloadReceiver downloadReceiver;
|
||||
private DownloadManager downloadManager;
|
||||
public List<DownloadInfo> allTask;
|
||||
private List<String> downloadURL; // 当前下载的任务
|
||||
private static final String ACTION_START = "START";
|
||||
private static final String ACTION_STOP = "STOP";
|
||||
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
flags = START_STICKY;
|
||||
return super.onStartCommand(intent, flags, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
||||
super.onCreate();
|
||||
downloadManager = DownloadService.getDownloadManager();
|
||||
downloadManager.getThreadPool().setCorePoolSize(1);
|
||||
allTask = downloadManager.getAllTask();
|
||||
for (DownloadInfo downloadInfo : allTask) {
|
||||
DownloadListener downloadListener = new MyDownloadListener();
|
||||
downloadListener.setUserTag(downloadInfo.getUrl());
|
||||
downloadInfo.setListener(downloadListener);
|
||||
}
|
||||
downloadReceiver = new DownloadReceiver();
|
||||
downloadURL = new ArrayList<>();
|
||||
/* 注册广播 */
|
||||
IntentFilter mScreenOnFilter = new IntentFilter();
|
||||
mScreenOnFilter.addAction(Utils.DOWNLOAD_STARTALL_ACTION);
|
||||
mScreenOnFilter.addAction(Utils.DOWNLOAD_DELETE_UPDATE_ACTION);
|
||||
mScreenOnFilter.addAction(Utils.DOWNLOAD_START_ACTION);
|
||||
mScreenOnFilter.addAction(Utils.DOWNLOAD_STOP_ACTION);
|
||||
mScreenOnFilter.addAction(Utils.DOWNLOAD_INITIALIZE_ACTION);
|
||||
mScreenOnFilter.addAction(Utils.DOWNLOAD_DELETE_URL_ACTION);
|
||||
mScreenOnFilter.addAction(Utils.DOWNLOAD_DELETE_PACKAGENAME_ACTION);
|
||||
mScreenOnFilter.addAction(Utils.DOWNLOAD_DELETEALL_ACTION);
|
||||
mScreenOnFilter.addAction(Utils.DOWNLOAD_ALLTASK_ACTION);
|
||||
mScreenOnFilter.addAction(Utils.DOWNLOAD_PACKAGENAME_ACTION);
|
||||
MyDownloadService.this.registerReceiver(downloadReceiver, mScreenOnFilter);
|
||||
|
||||
startService(new Intent(this, StepService.class));
|
||||
startService(new Intent(this, GuardService.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId) {
|
||||
super.onStart(intent, startId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (downloadManager != null) {
|
||||
downloadManager.stopAllTask();
|
||||
}
|
||||
if (allTask != null) {
|
||||
allTask.clear();
|
||||
allTask = null;
|
||||
}
|
||||
downloadURL.clear();
|
||||
MyDownloadService.this.unregisterReceiver(downloadReceiver);
|
||||
Intent sevice = new Intent(this, DownloadService.class);
|
||||
this.startService(sevice);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private class MyDownloadListener extends DownloadListener {
|
||||
|
||||
@Override
|
||||
public void onProgress(DownloadInfo downloadInfo) {
|
||||
Log.e("mjsheng", "onProgress::::::::" + downloadInfo.getProgress());
|
||||
sendDownloadState(downloadInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(DownloadInfo downloadInfo) {
|
||||
sendDownloadState(downloadInfo);
|
||||
AppDateInfo info = (AppDateInfo) downloadInfo.getData();
|
||||
if (info.getApp_baoming().equals(Utils.YOUNGSYSTEM_APP_TONGBU) || info.getApp_baoming().equals(MyApplication.getAppContext().getPackageName())) {
|
||||
// ApkUtils.install(MyApplication.getAppContext(), new File(downloadInfo.getTargetPath()));
|
||||
ApkUtils.installApkInSilence(downloadInfo.getTargetPath(), info.getApp_baoming());
|
||||
}
|
||||
if (downloadURL.contains(downloadInfo.getUrl())) {
|
||||
// ApkUtils.install(MyApplication.getAppContext(), new File(downloadInfo.getTargetPath()));
|
||||
ApkUtils.installApkInSilence(downloadInfo.getTargetPath(), info.getApp_baoming());
|
||||
downloadURL.remove(downloadInfo.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(DownloadInfo downloadInfo, String errorMsg, Exception e) {
|
||||
sendDownloadState(downloadInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendDownloadState(DownloadInfo downloadInfo) {
|
||||
if (downloadInfo == null) return;
|
||||
AppDownloadInfo info = new AppDownloadInfo();
|
||||
info.setFileName(downloadInfo.getFileName());
|
||||
info.setProgress(downloadInfo.getProgress());
|
||||
info.setTargetPath(downloadInfo.getTargetPath());
|
||||
info.setUrl(downloadInfo.getUrl());
|
||||
info.setState(downloadInfo.getState());
|
||||
info.setDownloadLength(downloadInfo.getDownloadLength());
|
||||
info.setTotalLength(downloadInfo.getTotalLength());
|
||||
AppDateInfo dateInfo = (AppDateInfo) downloadInfo.getData();
|
||||
info.setPackageName(dateInfo.getApp_baoming());
|
||||
info.setVersion(dateInfo.getApp_banben());
|
||||
info.setData(dateInfo);
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Utils.DOWNLOAD_SERVICE_ACTION);
|
||||
intent.putExtra("DownloadInfo", info);
|
||||
sendBroadcast(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否存在该包名的下载任务
|
||||
*/
|
||||
public DownloadInfo getPackageName(String packagename) {
|
||||
if (packagename != null) {
|
||||
for (DownloadInfo downloadInfo : allTask) {
|
||||
AppDateInfo info = (AppDateInfo) downloadInfo.getData();
|
||||
if (info.getApp_baoming() != null) {
|
||||
if (info.getApp_baoming().equals(packagename)) {
|
||||
return downloadInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public class DownloadReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Utils.DOWNLOAD_STARTALL_ACTION.equals(intent.getAction())) {
|
||||
downloadManager.startAllTask();
|
||||
} else if (Utils.DOWNLOAD_DELETE_URL_ACTION.equals(intent.getAction())) {
|
||||
// 删除标识 下载地址
|
||||
String URL = intent.getStringExtra("URL");
|
||||
DownloadInfo downloadInfo = downloadManager.getDownloadInfo(URL);
|
||||
if (downloadInfo != null && StorageUtils.isFileIsExists(downloadInfo.getTargetPath())) {
|
||||
downloadInfo.setState(10);
|
||||
sendDownloadState(downloadInfo);
|
||||
downloadManager.removeTask(downloadInfo.getUrl(), true);
|
||||
}
|
||||
} else if (Utils.DOWNLOAD_START_ACTION.equals(intent.getAction())) {
|
||||
// 下载
|
||||
String URL = intent.getStringExtra("URL");
|
||||
AppDateInfo appDateInfo = (AppDateInfo) intent.getSerializableExtra("AppDateInfo");
|
||||
if (appDateInfo != null) {
|
||||
GetRequest request = OkGo.get(URL);
|
||||
MyDownloadListener listener = new MyDownloadListener();
|
||||
listener.setUserTag(URL);
|
||||
if (URL != null) {
|
||||
if (downloadManager.getDownloadInfo(URL) == null) {
|
||||
if (!StorageUtils.isFileIsExists("/Android/data/" + context.getPackageName() + "/files/Download")) {
|
||||
StorageUtils.getFileRoot(context);
|
||||
}
|
||||
downloadManager.addTask(URL, appDateInfo, request, listener);
|
||||
SaveListUtils.addDownLoadList(appDateInfo.getApp_baoming());
|
||||
DownloadInfo downloadInfo = downloadManager.getDownloadInfo(URL);
|
||||
AppDownloadInfo info = new AppDownloadInfo();
|
||||
info.setFileName(downloadInfo.getFileName());
|
||||
info.setProgress(downloadInfo.getProgress());
|
||||
info.setTargetPath(downloadInfo.getTargetPath());
|
||||
info.setUrl(downloadInfo.getUrl());
|
||||
info.setState(downloadInfo.getState());
|
||||
info.setDownloadLength(downloadInfo.getDownloadLength());
|
||||
info.setTotalLength(downloadInfo.getTotalLength());
|
||||
AppDateInfo dateInfo = (AppDateInfo) downloadInfo.getData();
|
||||
info.setPackageName(dateInfo.getApp_baoming());
|
||||
String s = Settings.System.getString(getContentResolver(), "qch_app_forbid");
|
||||
Settings.System.putString(getContentResolver(), "qch_app_forbid", s + "," + dateInfo.getApp_baoming());
|
||||
Log.e("SystemSetting", "qch_app_forbid__________" + Settings.System.getString(getContentResolver(), "qch_app_forbid"));
|
||||
|
||||
//2019.9.26
|
||||
info.setVersion(dateInfo.getApp_banben());
|
||||
info.setData(dateInfo);
|
||||
Intent allIntent = new Intent();
|
||||
allIntent.setAction(Utils.DOWNLOAD_NEWSERVICE_ACTION);
|
||||
allIntent.putExtra("addTask", info);
|
||||
sendBroadcast(allIntent);
|
||||
|
||||
} else {
|
||||
if (!StorageUtils.isFileIsExists(downloadManager.getDownloadInfo(URL).getTargetPath())) {
|
||||
downloadManager.removeTask(URL, true);
|
||||
StorageUtils.getFileRoot(context);
|
||||
}
|
||||
downloadManager.addTask(URL, appDateInfo, request, listener);
|
||||
}
|
||||
if (!downloadURL.contains(URL)) {
|
||||
downloadURL.add(URL);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (downloadManager.getDownloadInfo(URL) != null) {
|
||||
downloadManager.restartTask(URL);
|
||||
}
|
||||
}
|
||||
} else if (Utils.DOWNLOAD_INITIALIZE_ACTION.equals(intent.getAction())) {
|
||||
// 初始化item状态
|
||||
String URL = intent.getStringExtra("URL");
|
||||
DownloadInfo downloadInfo = downloadManager.getDownloadInfo(URL);
|
||||
if (downloadInfo != null && StorageUtils.isFileIsExists(downloadInfo.getTargetPath())) {
|
||||
sendDownloadState(downloadInfo);
|
||||
}
|
||||
} else if (Utils.DOWNLOAD_PACKAGENAME_ACTION.equals(intent.getAction())) {
|
||||
// 初始化item状态
|
||||
String packageName = intent.getStringExtra("packageName");
|
||||
DownloadInfo downloadInfo = getPackageName(packageName);
|
||||
if (downloadInfo != null && StorageUtils.isFileIsExists(downloadInfo.getTargetPath())) {
|
||||
sendDownloadState(downloadInfo);
|
||||
}
|
||||
} else if (Utils.DOWNLOAD_STOP_ACTION.equals(intent.getAction())) {
|
||||
// 暂停标识
|
||||
String URL = intent.getStringExtra("URL");
|
||||
downloadManager.pauseTask(URL);
|
||||
DownloadInfo downloadInfo = downloadManager.getDownloadInfo(URL);
|
||||
if (downloadInfo != null && StorageUtils.isFileIsExists(downloadInfo.getTargetPath())) {
|
||||
sendDownloadState(downloadInfo);
|
||||
}
|
||||
} else if (Utils.DOWNLOAD_DELETE_PACKAGENAME_ACTION.equals(intent.getAction())) {
|
||||
// 删除标识 包名
|
||||
String packageName = intent.getStringExtra("packageName");
|
||||
DownloadInfo downloadInfo = getPackageName(packageName);
|
||||
if (downloadInfo != null && StorageUtils.isFileIsExists(downloadInfo.getTargetPath())) {
|
||||
downloadInfo.setState(10);
|
||||
sendDownloadState(downloadInfo);
|
||||
downloadManager.removeTask(downloadInfo.getUrl(), true);
|
||||
}
|
||||
} else if (Utils.DOWNLOAD_DELETE_URL_ACTION.equals(intent.getAction())) {
|
||||
// 删除标识 下载地址
|
||||
String URL = intent.getStringExtra("URL");
|
||||
DownloadInfo downloadInfo = downloadManager.getDownloadInfo(URL);
|
||||
if (downloadInfo != null) {
|
||||
downloadInfo.setState(10);
|
||||
sendDownloadState(downloadInfo);
|
||||
downloadManager.removeTask(downloadInfo.getUrl(), true);
|
||||
}
|
||||
} else if (Utils.DOWNLOAD_DELETE_UPDATE_ACTION.equals(intent.getAction())) {
|
||||
// 删除 应用更新包
|
||||
String packageName = intent.getStringExtra("packageName");
|
||||
DownloadInfo downloadInfo = getPackageName(packageName);
|
||||
if (downloadInfo != null && downloadInfo.getData() != null) {
|
||||
AppDateInfo dateInfo = (AppDateInfo) downloadInfo.getData();
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
try {
|
||||
PackageInfo packInfo = packageManager.getPackageInfo(context.getPackageName(),
|
||||
0);
|
||||
String version = packInfo.versionName;
|
||||
String oldVersion = dateInfo.getApp_banben();
|
||||
if (oldVersion == null || oldVersion.equals("")) {
|
||||
downloadManager.removeTask(downloadInfo.getUrl(), true);
|
||||
} else if (Utils.isUpdate(oldVersion, version) == true || oldVersion.equals(version)) {
|
||||
downloadManager.removeTask(downloadInfo.getUrl(), true);
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (StorageUtils.isFileIsExists(downloadInfo.getTargetPath())) {
|
||||
downloadInfo.setState(10);
|
||||
sendDownloadState(downloadInfo);
|
||||
downloadManager.removeTask(downloadInfo.getUrl(), true);
|
||||
}
|
||||
}
|
||||
} else if (Utils.DOWNLOAD_ALLTASK_ACTION.equals(intent.getAction())) {
|
||||
downloadManager = DownloadService.getDownloadManager();
|
||||
allTask = downloadManager.getAllTask();
|
||||
List<AppDownloadInfo> list = new ArrayList<>();
|
||||
for (int i = 0; i < allTask.size(); i++) {
|
||||
DownloadInfo downloadInfo = allTask.get(i);
|
||||
if (downloadInfo != null && StorageUtils.isFileIsExists(downloadInfo.getTargetPath())) {
|
||||
AppDateInfo dateInfo = (AppDateInfo) downloadInfo.getData();
|
||||
if (!dateInfo.getApp_baoming().equals(Utils.YOUNGSYSTEM_APP_TONGBU) && !dateInfo.getApp_baoming().equals(context.getPackageName())) {
|
||||
AppDownloadInfo info = new AppDownloadInfo();
|
||||
info.setFileName(downloadInfo.getFileName());
|
||||
info.setProgress(downloadInfo.getProgress());
|
||||
info.setTargetPath(downloadInfo.getTargetPath());
|
||||
info.setUrl(downloadInfo.getUrl());
|
||||
info.setState(downloadInfo.getState());
|
||||
info.setDownloadLength(downloadInfo.getDownloadLength());
|
||||
info.setTotalLength(downloadInfo.getTotalLength());
|
||||
info.setPackageName(dateInfo.getApp_baoming());
|
||||
info.setVersion(dateInfo.getApp_banben());
|
||||
info.setData(dateInfo);
|
||||
list.add(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
Intent allIntent = new Intent();
|
||||
allIntent.setAction(Utils.DOWNLOAD_ALLSERVICE_ACTION);
|
||||
allIntent.putExtra("allTask", (Serializable) list);
|
||||
sendBroadcast(allIntent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
66
app/src/main/java/com/appstore/uiui/service/StepService.java
Normal file
66
app/src/main/java/com/appstore/uiui/service/StepService.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.appstore.uiui.service;
|
||||
|
||||
/**
|
||||
* 作者 mjsheng
|
||||
* 日期 2019/4/1 10:57
|
||||
* 邮箱 501802639@qq.com
|
||||
* 来自:
|
||||
*/
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.appstore.uiui.utils.ServiceAliveUtils;
|
||||
import com.blankj.utilcode.util.LogUtils;
|
||||
|
||||
/**
|
||||
* 主进程 双进程通讯
|
||||
*
|
||||
* @author LiGuangMin
|
||||
* @time Created by 2018/8/17 11:26
|
||||
*/
|
||||
public class StepService extends Service {
|
||||
|
||||
private final static String TAG = StepService.class.getSimpleName();
|
||||
private ServiceConnection mServiceConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
|
||||
LogUtils.e(TAG, "StepService:建立链接");
|
||||
boolean isServiceRunning = ServiceAliveUtils.isServiceAlice();
|
||||
if (!isServiceRunning) {
|
||||
Intent i = new Intent(StepService.this, MyDownloadService.class);
|
||||
startService(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName componentName) {
|
||||
// 断开链接
|
||||
startService(new Intent(StepService.this, GuardService.class));
|
||||
// 重新绑定
|
||||
bindService(new Intent(StepService.this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
// return new KeepAliveConnection.Stub() { };
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
// startForeground(1, new Notification());
|
||||
// 绑定建立链接
|
||||
bindService(new Intent(this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
}
|
||||
37
app/src/main/java/com/appstore/uiui/utils/LogUtils.java
Normal file
37
app/src/main/java/com/appstore/uiui/utils/LogUtils.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package com.appstore.uiui.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.appstore.uiui.BuildConfig;
|
||||
|
||||
public class LogUtils {
|
||||
public static void v(String tag, String msg) {
|
||||
if (BuildConfig.LOG_DEBUG) {
|
||||
Log.v(tag, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void d(String tag, String msg) {
|
||||
if (BuildConfig.LOG_DEBUG) {
|
||||
Log.d(tag, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void i(String tag, String msg) {
|
||||
if (BuildConfig.LOG_DEBUG) {
|
||||
Log.i(tag, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void w(String tag, String msg) {
|
||||
if (BuildConfig.LOG_DEBUG) {
|
||||
Log.w(tag, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void e(String tag, String msg) {
|
||||
if (BuildConfig.LOG_DEBUG) {
|
||||
Log.e(tag, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
66
app/src/main/java/com/appstore/uiui/utils/SaveListUtils.java
Normal file
66
app/src/main/java/com/appstore/uiui/utils/SaveListUtils.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.appstore.uiui.utils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.appstore.uiui.common.CommonDatas;
|
||||
import com.blankj.utilcode.util.SPStaticUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SaveListUtils {
|
||||
private static List<String> downLoadList = new ArrayList<>();
|
||||
|
||||
public static List<String> getList() {
|
||||
String data = SPStaticUtils.getString(CommonDatas.FORCE_INSTALL);
|
||||
Log.e("mjshenglistdata", data);
|
||||
|
||||
Gson gson = new Gson();
|
||||
Type listType = new TypeToken<List<String>>() {
|
||||
}.getType();
|
||||
List<String> list = gson.fromJson(data, listType);
|
||||
|
||||
// Log.e("mjshenglist1", list.toString());
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void addToList(String data) {
|
||||
List<String> list = getList();
|
||||
// Log.e("mjshenglist2", list.toString());
|
||||
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
if (!list.contains(data)) {
|
||||
list.add(data);
|
||||
Gson gson = new Gson();
|
||||
String gsonData = gson.toJson(list);
|
||||
SPStaticUtils.put(CommonDatas.FORCE_INSTALL, gsonData);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getDownLoadList() {
|
||||
|
||||
return downLoadList;
|
||||
}
|
||||
|
||||
public static void addDownLoadList(String packageName) {
|
||||
if (downLoadList == null) {
|
||||
downLoadList = new ArrayList<>();
|
||||
downLoadList.add(packageName);
|
||||
} else {
|
||||
if (!downLoadList.contains(packageName)) {
|
||||
downLoadList.add(packageName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isDownLoading(String packageName) {
|
||||
if (downLoadList.contains(packageName)) {
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.appstore.uiui.utils;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
|
||||
import com.appstore.uiui.MyApplication;
|
||||
|
||||
public class ServiceAliveUtils {
|
||||
|
||||
public static boolean isServiceAlice() {
|
||||
boolean isServiceRunning = false;
|
||||
ActivityManager manager =
|
||||
(ActivityManager) MyApplication.getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
|
||||
if (manager == null) {
|
||||
return true;
|
||||
}
|
||||
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if ("demo.lgm.com.keepalivedemo.service.DownloadService".equals(service.service.getClassName())) {
|
||||
isServiceRunning = true;
|
||||
}
|
||||
}
|
||||
return isServiceRunning;
|
||||
}
|
||||
}
|
||||
124
app/src/main/java/com/appstore/uiui/utils/StorageUtils.java
Normal file
124
app/src/main/java/com/appstore/uiui/utils/StorageUtils.java
Normal file
@@ -0,0 +1,124 @@
|
||||
package com.appstore.uiui.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.os.storage.StorageManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class StorageUtils {
|
||||
|
||||
|
||||
// 获取存储空间 false 内置sd卡路径,true 外置sd卡路径
|
||||
public static File getStoragePath(Context mContext, boolean isSDcard) {
|
||||
StorageManager mStorageManager = (StorageManager) mContext.getSystemService(Context.STORAGE_SERVICE);
|
||||
Class<?> storageVolumeClazz = null;
|
||||
try {
|
||||
storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
|
||||
Method getVolumeList = mStorageManager.getClass().getMethod("getVolumeList");
|
||||
Method getPath = storageVolumeClazz.getMethod("getPath");
|
||||
Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
|
||||
Object result = getVolumeList.invoke(mStorageManager);
|
||||
final int length = Array.getLength(result);
|
||||
for (int i = 0; i < length; i++) {
|
||||
Object storageVolumeElement = Array.get(result, i);
|
||||
String path = (String) getPath.invoke(storageVolumeElement);
|
||||
boolean removable = (Boolean) isRemovable.invoke(storageVolumeElement);
|
||||
if (isSDcard == removable) {
|
||||
File file = new File(path);
|
||||
if (file.exists()) {
|
||||
return file;
|
||||
}else {
|
||||
if (!isSDcard) {
|
||||
return Environment.getExternalStorageDirectory();
|
||||
} else {
|
||||
File file1 = new File("root/storage/sdcard1");
|
||||
if (file1.exists()){
|
||||
return file1;
|
||||
}else {
|
||||
File file2 = new File("storage/sdcard1");
|
||||
if (file2.exists()){
|
||||
return file2;
|
||||
}else {
|
||||
File file3 = new File("/storage/emulated/0");
|
||||
if (file3.exists()){
|
||||
return file3;
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getFileCache(Context context, String s) {
|
||||
return getExternalFilesDir(context, s).getAbsolutePath();
|
||||
}
|
||||
|
||||
public static String getFileRoot(Context context) {
|
||||
return getExternalFilesDir(context, "Download").getAbsolutePath();
|
||||
}
|
||||
|
||||
public static File getExternalFilesDir(Context context, String s) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
|
||||
File path = context.getExternalFilesDir(s);
|
||||
if (path != null) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
final String cacheDir = "/Android/data/" + context.getPackageName() + "/files/" + s;
|
||||
return new File(Environment.getExternalStorageDirectory().getPath() + cacheDir);
|
||||
}
|
||||
|
||||
|
||||
// 检测文件是否存在
|
||||
public static boolean isFileIsExists(String filePath){
|
||||
try{
|
||||
File f=new File(filePath);
|
||||
if(!f.exists()){
|
||||
return false;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static String size(long size) {
|
||||
if (size / (1024 * 1024) > 0) {
|
||||
float tmpSize = (float) (size) / (float) (1024 * 1024 );
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
return "" + df.format(tmpSize) + "GB";
|
||||
} else if (size / 1024 > 0) {
|
||||
float tmpSize = (float) (size) / (float) 1024 ;
|
||||
DecimalFormat df = new DecimalFormat("#.##");
|
||||
return "" + df.format(tmpSize) + "MB";
|
||||
} else if (size > 0) {
|
||||
return "" + (size ) + "KB";
|
||||
} else {
|
||||
return "" + (size) + "KB";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
BIN
app/src/main/res/mipmap-hdpi/ic_app.png
Normal file
BIN
app/src/main/res/mipmap-hdpi/ic_app.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
BIN
app/src/main/res/mipmap-mdpi/ic_app.png
Normal file
BIN
app/src/main/res/mipmap-mdpi/ic_app.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.5 KiB |
Reference in New Issue
Block a user