update:2020.01.10 20:21
fix:修改安装逻辑,优化状态栏逻辑 add:
This commit is contained in:
@@ -17,9 +17,11 @@ import android.widget.Toast;
|
||||
import com.lzy.okserver.download.DownloadInfo;
|
||||
import com.lzy.okserver.download.DownloadManager;
|
||||
import com.lzy.okserver.download.DownloadService;
|
||||
import com.mjsheng.myappstore.BuildConfig;
|
||||
import com.mjsheng.myappstore.R;
|
||||
import com.mjsheng.myappstore.bean.AppDateInfo;
|
||||
import com.mjsheng.myappstore.bean.AppDownloadInfo;
|
||||
import com.mjsheng.myappstore.bean.FileData;
|
||||
import com.mjsheng.myappstore.download.StorageUtils;
|
||||
import com.mjsheng.myappstore.utils.update.ToastTool;
|
||||
|
||||
@@ -305,11 +307,58 @@ public class ApkUtils {
|
||||
// Log.e("mjsheng", "安装失败");
|
||||
// }
|
||||
// }
|
||||
public interface InstallCallback {
|
||||
void installInfoCallback(String path, String packageName);
|
||||
}
|
||||
|
||||
public static boolean installApp(Context context, String apkPath) {
|
||||
ToastTool.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 installApkInSilence(String installPath, String packageName) {
|
||||
ToastTool.show("正在安装应用...");
|
||||
setInstallIngPackageName(packageName);
|
||||
|
||||
Class<?> pmService;
|
||||
Class<?> activityTherad;
|
||||
Method method;
|
||||
@@ -380,111 +429,5 @@ public class ApkUtils {
|
||||
return uid / PER_USER_RANGE;
|
||||
}
|
||||
|
||||
private static List<AppDownloadInfo> taskList = new ArrayList<>();
|
||||
public static List<DownloadInfo> alltask;
|
||||
|
||||
static String packageName = "";
|
||||
|
||||
public static void setInstallIngPackageName(String packageNames) {
|
||||
packageName = packageNames;
|
||||
Log.e("fht", "正在安装:" + packageNames);
|
||||
}
|
||||
|
||||
public static String getinstallPackage() {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
public static boolean isInstalling(String packageNames) {
|
||||
Log.e("fht", "isInstalling:" + packageName);
|
||||
return packageName.equals(packageNames);
|
||||
}
|
||||
|
||||
public static DownloadInfo getDownloadInfoByPackageName(String s) {
|
||||
int x = -1;
|
||||
if (alltask != null && alltask.size() > 0) {
|
||||
for (int i = 0; i < alltask.size(); i++) {
|
||||
DownloadInfo downloadInfo = alltask.get(i);
|
||||
AppDateInfo dateInfo = (AppDateInfo) downloadInfo.getData();
|
||||
if (dateInfo.getApp_baoming().equals(s)) {
|
||||
x = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (x != -1) {
|
||||
return alltask.get(x);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static synchronized public void updateTask(List<DownloadInfo> allTask, Context context) {
|
||||
alltask = allTask;
|
||||
Log.e("fht", "updateTask:" + allTask.size());
|
||||
long time1 = System.currentTimeMillis();
|
||||
List<AppDownloadInfo> list = new ArrayList<>();
|
||||
if (allTask.size() > 0) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
long time2 = System.currentTimeMillis();
|
||||
Log.e("fht", "time:" + (time2 - time1));
|
||||
taskList = list;
|
||||
if ((packageName.equals("") || isAvailable(context, getinstallPackage())) && taskList.size() > 0 && taskList.get(0).getState() == DownloadManager.FINISH) {
|
||||
if (isAvailable(context, taskList.get(0).getPackageName())) {
|
||||
taskList.remove(0);
|
||||
}
|
||||
if (taskList.size() > 0) {
|
||||
ApkUtils.installApkInSilence(taskList.get(0).getTargetPath(), taskList.get(0).getPackageName());
|
||||
Log.e("fht", "updateTask1:" + taskList.get(0).getPackageName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
synchronized public static void removeInfo(String packageName) {
|
||||
Log.e("fht", "removeInfo:" + "taskList.size():" + taskList.size());
|
||||
|
||||
int position = -1;
|
||||
for (int i = 0; i < taskList.size(); i++) {
|
||||
if (packageName.equals(taskList.get(i).getPackageName())) {
|
||||
position = i;
|
||||
}
|
||||
}
|
||||
if (position != -1) {
|
||||
removeInfo(taskList.get(position));
|
||||
} else {
|
||||
setInstallIngPackageName("");
|
||||
Log.e("fht", "position == -1");
|
||||
}
|
||||
}
|
||||
|
||||
synchronized public static void removeInfo(AppDownloadInfo info) {
|
||||
taskList.remove(info);
|
||||
if (taskList != null && taskList.size() > 0) {
|
||||
ApkUtils.installApkInSilence(taskList.get(0).getTargetPath(), taskList.get(0).getPackageName());
|
||||
Log.e("fht", "removeInfo:" + taskList.get(0).getPackageName());
|
||||
} else {
|
||||
setInstallIngPackageName("");
|
||||
Log.e("fht", "任务为空");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -186,4 +186,8 @@ public class Configure {
|
||||
|
||||
public static final String SEND_USEDTIME= HTTP_TAG_HEAD_NEW + "Applog/getAppLog";
|
||||
|
||||
public static final String CHECK_UPDATE= HTTP_TAG_HEAD_NEW + "Silent/silent";
|
||||
//更新接口
|
||||
public static final String GET_DEVICES_TAGS= HTTP_TAG_HEAD_NEW + "Sn/getSnTag";
|
||||
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ import java.io.FileReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.NetworkInterface;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -103,6 +104,7 @@ public class Utils {
|
||||
public static final int COUNT_ONE_PAGE2 = 10;
|
||||
public static final String YOUNGSYSTEM_APP_TONGBU = "com.school.app.syn"; // 小学系统 同步教材app
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final String number[] = {
|
||||
"1", "2", "3", "4", "5", "6", "7",
|
||||
@@ -154,7 +156,6 @@ public class Utils {
|
||||
// 积分记录 达人标准次数记录
|
||||
|
||||
|
||||
|
||||
// MD5 设备地址标识
|
||||
public static String getMAC(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // 如果当前设备系统大于等于6.0 使用下面的方法
|
||||
@@ -715,15 +716,16 @@ public class Utils {
|
||||
}
|
||||
|
||||
|
||||
public static String transferLongToDate(Long millSec){
|
||||
public static String transferLongToDate(Long millSec) {
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
Date date= new Date(millSec);
|
||||
Date date = new Date(millSec);
|
||||
|
||||
return sdf.format(date);
|
||||
|
||||
}
|
||||
|
||||
public static String getSn() {
|
||||
return Build.SERIAL;
|
||||
}
|
||||
@@ -783,7 +785,6 @@ public class Utils {
|
||||
}
|
||||
|
||||
|
||||
|
||||
//判断是否为系统应用
|
||||
public static boolean isSystemApp(Context context, String pkgName) {
|
||||
boolean isSystemApp = false;
|
||||
@@ -856,5 +857,18 @@ public class Utils {
|
||||
// return bgBitmap;
|
||||
}
|
||||
|
||||
public static String getProperty(String key, String defaultValue) {
|
||||
String value = defaultValue;
|
||||
try {
|
||||
Class<?> c = Class.forName("android.os.SystemProperties");
|
||||
Method get = c.getMethod("get", String.class, String.class);
|
||||
value = (String) (get.invoke(c, key, "unknown"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user