update:2020.12.25

fix:新后台对接完成
add:
This commit is contained in:
2020-12-25 11:09:47 +08:00
parent 4d1eafae8c
commit 79ea8888c1
80 changed files with 3636 additions and 12151 deletions

View File

@@ -38,11 +38,6 @@ import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class ApkUtils {
@@ -215,94 +210,94 @@ public class ApkUtils {
}
public static void installRx(final Context context, final String packageName, final String filePath) {
Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(Subscriber<? super Integer> subscriber) {
File file = new File(filePath);
if (filePath == null || filePath.length() == 0 || file == null) {
Log.e("fanhuitong", "errormesg=========" + " 空啊 ");
subscriber.onNext(0);
return;
}
// String[] args = { "pm", "install", "-r", filePath };
String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath};
// String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath;
Log.e("fanhuitong", "argss====" + args);
ProcessBuilder processBuilder = new ProcessBuilder(args);
Process process = null;
BufferedReader successResult = null;
BufferedReader errorResult = null;
StringBuilder successMsg = new StringBuilder();
StringBuilder errorMsg = new StringBuilder();
try {
process = processBuilder.start();
successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s;
while ((s = successResult.readLine()) != null) {
Log.e("mjhseng", "successResult----------" + s);
successMsg.append(s);
}
while ((s = errorResult.readLine()) != null) {
Log.e("mjhseng", "errorResult----------" + s);
errorMsg.append(s);
}
} catch (IOException e1) {
Log.e("fanhuitong", "IOException e1)----------" + e1.toString());
e1.printStackTrace();
} finally {
try {
if (successResult != null) {
successResult.close();
}
if (errorResult != null) {
errorResult.close();
}
} catch (IOException e1) {
Log.e("fanhuitong", "IOException e11)---------" + e1.toString());
e1.printStackTrace();
}
if (process != null) {
process.destroy();
}
}
if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) {
subscriber.onNext(2);
} else {
Log.e("fanhuitong", "errormesg=========" + errorMsg.toString());
subscriber.onNext(1);
}
}
}).subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Integer>() {
@Override
public void onNext(Integer value) {
if (value == 2) {
//安装成功
ToastUtil.show("安装成功");
Log.e("fanhuitong", "-----------安装成功-----------");
} else {
//安装错误
Log.e("fanhuitong", "------------安装错误-----------");
ToastUtil.show("安装失败");
}
}
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
//安装错误
}
});
}
// public static void installRx(final Context context, final String packageName, final String filePath) {
//
// Observable.create(new Observable.OnSubscribe<Integer>() {
// @Override
// public void call(Subscriber<? super Integer> subscriber) {
// File file = new File(filePath);
// if (filePath == null || filePath.length() == 0 || file == null) {
// Log.e("fanhuitong", "errormesg=========" + " 空啊 ");
// subscriber.onNext(0);
// return;
// }
// // String[] args = { "pm", "install", "-r", filePath };
// String[] args = {"pm", "install", "-i", "com.colorflykids", "--user", "0", filePath};
// // String argss = "pm install -i " + "com.colorflykids" + " --user 0 " + filePath;
// Log.e("fanhuitong", "argss====" + args);
// ProcessBuilder processBuilder = new ProcessBuilder(args);
// Process process = null;
// BufferedReader successResult = null;
// BufferedReader errorResult = null;
// StringBuilder successMsg = new StringBuilder();
// StringBuilder errorMsg = new StringBuilder();
// try {
// process = processBuilder.start();
// successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
// errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
// String s;
// while ((s = successResult.readLine()) != null) {
// Log.e("mjhseng", "successResult----------" + s);
// successMsg.append(s);
// }
// while ((s = errorResult.readLine()) != null) {
// Log.e("mjhseng", "errorResult----------" + s);
// errorMsg.append(s);
// }
// } catch (IOException e1) {
// Log.e("fanhuitong", "IOException e1)----------" + e1.toString());
// e1.printStackTrace();
// } finally {
// try {
// if (successResult != null) {
// successResult.close();
// }
// if (errorResult != null) {
// errorResult.close();
// }
// } catch (IOException e1) {
// Log.e("fanhuitong", "IOException e11)---------" + e1.toString());
// e1.printStackTrace();
// }
// if (process != null) {
// process.destroy();
// }
// }
// if (successMsg.toString().contains("Success") || successMsg.toString().contains("success")) {
// subscriber.onNext(2);
// } else {
// Log.e("fanhuitong", "errormesg=========" + errorMsg.toString());
// subscriber.onNext(1);
// }
// }
// }).subscribeOn(Schedulers.newThread())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(new Observer<Integer>() {
//
// @Override
// public void onNext(Integer value) {
// if (value == 2) {
// //安装成功
// ToastUtil.show("安装成功");
// Log.e("fanhuitong", "-----------安装成功-----------");
// } else {
// //安装错误
// Log.e("fanhuitong", "------------安装错误-----------");
// ToastUtil.show("安装失败");
// }
// }
//
// @Override
// public void onCompleted() {
//
// }
//
// @Override
// public void onError(Throwable e) {
// //安装错误
// }
// });
// }
// public static void installApp(final String path, final String packageNames){
// File apkFile = new File(path);
@@ -643,4 +638,25 @@ public class ApkUtils {
}
public static int getAppVersionCode(Context context, String packageName) {
PackageManager pm = context.getPackageManager();
PackageInfo info = null;
try {
info = pm.getPackageInfo(packageName, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (null != info) {
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = info.getLongVersionCode();
} else {
appVersionCode = info.versionCode;
}
return (int) appVersionCode;
} else {
return 0;
}
}
}