update:2020.5.14

fix:兼容Android10.0 http联网问题,静默安装问题
add:
This commit is contained in:
2020-05-14 18:34:36 +08:00
parent eb1f74288c
commit fdbecb973e
13 changed files with 236 additions and 195 deletions

View File

@@ -65,7 +65,7 @@ import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
*/
//public class MyApplication extends MultiDexApplication implements Thread.UncaughtExceptionHandler {
public class MyApplication extends MultiDexApplication {
public class MyApplication extends MultiDexApplication {
public static String userName = null;
private static final String TAG = "--MyApplication--";
@@ -442,13 +442,14 @@ import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
}
private void catchException() {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
Log.d("捕获异常子线程:", Thread.currentThread().getName() +
"在:" + e.getStackTrace()[0].getClassName());
}
}
Thread.setDefaultUncaughtExceptionHandler(
new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
Log.d("捕获异常子线程:", Thread.currentThread().getName() +
"在:" + e.getStackTrace()[0].getClassName());
}
}
);
//下面是新增方法!
new Handler(Looper.getMainLooper()).post(new Runnable() {

View File

@@ -543,7 +543,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
int batteryLevel = getBatteryLevel();
LogUtils.e(batteryLevel + "------------------" + isReset);
if (isReset && batteryLevel >= CommonDatas.MIN_POWER) {
sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR").setPackage("com.android.settings"));
}
}
@@ -1242,32 +1242,6 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
}
}
private class BroadcastThread extends Thread {
String packagename[];
String action;
public BroadcastThread(String a, String s[]) {
super();
this.packagename = s;
this.action = a;
}
@Override
public void run() {
super.run();
for (String name : packagename) {
Intent disIntent = new Intent(action);
disIntent.putExtra("package_name", name);
Log.e("mymjsheng", "package_name::" + name);
sendBroadcast(disIntent);
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
private void writeDeselectBrowserIDtoSystem(String ids) {
if (!TextUtils.isEmpty(ids)) {
@@ -1376,7 +1350,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
break;
}
Intent usbIntent = new Intent(usbStatus);
Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings");
sendBroadcast(usbIntent);
}
@@ -1417,7 +1391,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
break;
}
Intent navIntent = new Intent(navigationStatus);
Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui");
sendBroadcast(navIntent);
@@ -1436,7 +1410,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
statusbarStatus = "qch_hide_statusBar";
break;
}
Intent statusIntent = new Intent(statusbarStatus);
Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
mContext.sendBroadcast(statusIntent);
}
@@ -1452,7 +1426,7 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs
cameraStatus = "qch_camera_forbid";
break;
}
Intent cameraIntent = new Intent(cameraStatus);
Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings");
sendBroadcast(cameraIntent);
//added:2019.12.6

View File

@@ -357,7 +357,7 @@ public class HTTPInterface {
JSONObject jsondata = JSON.parseObject(data);
//主页
String homepagURL = jsondata.getString("homepage");
Intent homepag = new Intent("qch_app_brower_homepage");
Intent homepag = new Intent("qch_app_brower_homepage").setPackage("com.android.settings");
if (homepagURL != null && !homepagURL.equals("")) {
homepag.putExtra("homepage", homepagURL);
} else {
@@ -367,7 +367,7 @@ public class HTTPInterface {
//书签
String labelpage = jsondata.getString("labelpage");
Intent websiteBookMark = new Intent("qch_app_brower_website");
Intent websiteBookMark = new Intent("qch_app_brower_website").setPackage("com.android.settings");
if (labelpage != null && !labelpage.equals("")) {
websiteBookMark.putExtra("websiteBookMark", labelpage);
} else {
@@ -376,10 +376,10 @@ public class HTTPInterface {
context.sendBroadcast(websiteBookMark);
} else {
Intent intent1 = new Intent("qch_app_brower_homepage");
Intent intent1 = new Intent("qch_app_brower_homepage").setPackage("com.android.settings");
intent1.putExtra("homepage", " ");
context.sendBroadcast(intent1);
Intent intent2 = new Intent("qch_app_brower_website");
Intent intent2 = new Intent("qch_app_brower_website").setPackage("com.android.settings");
intent2.putExtra("websiteBookMark", " ");
context.sendBroadcast(intent2);
}
@@ -426,7 +426,7 @@ public class HTTPInterface {
packageList = packageList.substring(0, packageList.length() - 1);
//去掉多余的,
Log.e("setAppinsideWeb ", "packageList:" + packageList);
Intent qch_app_website = new Intent("qch_app_website");
Intent qch_app_website = new Intent("qch_app_website").setPackage("com.android.settings");
qch_app_website.putExtra("package_name", packageList);
context.sendBroadcast(qch_app_website);
} else {
@@ -437,7 +437,7 @@ public class HTTPInterface {
strings = strings.substring(0, strings.length() - 1);
//去掉多余的;
Log.e("setAppinsideWeb ", "strings:" + strings);
Intent intent = new Intent("qch_app_inside_website");
Intent intent = new Intent("qch_app_inside_website").setPackage("com.android.settings");
intent.putExtra("websitelist", strings);
context.sendBroadcast(intent);
} else {
@@ -466,13 +466,13 @@ public class HTTPInterface {
}
private static void sendAllweb(Context context) {
Intent intent = new Intent("qch_app_website");
Intent intent = new Intent("qch_app_website").setPackage("com.android.settings");
intent.putExtra("package_name", "Invalid");
context.sendBroadcast(intent);
}
private static void sendwebUrl(Context context) {
Intent intent = new Intent("qch_app_inside_website");
Intent intent = new Intent("qch_app_inside_website").setPackage("com.android.settings");
intent.putExtra("websitelist", "Invalid");
context.sendBroadcast(intent);
}

View File

@@ -39,11 +39,11 @@ public class Network {
// public static final String ROOT_URL = "http://www.as.xueshibao.com.cn/api/"; 弃用
// public static final String ROOT_URL = "https://www.jiaoguanyi.com/api/";//正式 弃用
public static final String ROOT_URL = "https://partner.jiaoguanyi.com/api/";//正式
public static final String WebsocketURL = "ws://47.107.133.19:1234";
// public static final String ROOT_URL = "https://partner.jiaoguanyi.com/api/";//正式
// public static final String WebsocketURL = "ws://47.107.133.19:1234";
// public static final String ROOT_URL = "http://www.jiaoguanyi.cn/api/";//测试
// public static final String WebsocketURL = "ws://47.107.133.19:2345";
public static final String ROOT_URL = "http://www.jiaoguanyi.cn/api/";//测试
public static final String WebsocketURL = "ws://47.107.133.19:2345";
private static UploadAppInfoApi uploadAppInfoApi;
private static DeselectIDApi deselectIDApi;

View File

@@ -133,7 +133,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
break;
}
Intent usbIntent = new Intent(usbStatus);
Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings");
mContext.sendBroadcast(usbIntent);
}
@@ -175,7 +175,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
break;
}
Intent navIntent = new Intent(navigationStatus);
Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui");
mContext.sendBroadcast(navIntent);
@@ -194,7 +194,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
statusbarStatus = "qch_hide_statusBar";
break;
}
Intent statusIntent = new Intent(statusbarStatus);
Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
mContext.sendBroadcast(statusIntent);
}
@@ -210,7 +210,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
cameraStatus = "qch_camera_forbid";
break;
}
Intent cameraIntent = new Intent(cameraStatus);
Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings");
mContext.sendBroadcast(cameraIntent);
//影音管控开关
@@ -518,7 +518,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
break;
case MSG_RESET:
if (getBatteryLevel() >= CommonDatas.MIN_POWER) {
mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR").setPackage("com.android.settings"));
} else {
MySQLData.SetBooleanData(mContext, CommonDatas.IS_RESET, true);
}
@@ -574,7 +574,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
// "com.handsgo.jiakao.android,com.chinessjunqi.nb,com.cktiku.gushiwenbibei,com.yangcong345.android.phone"}
private void settingCamera(String s) {
if (TextUtils.isEmpty(s)) {
Intent intent = new Intent("qch_camera_forbid");
Intent intent = new Intent("qch_camera_forbid").setPackage("com.android.settings");
intent.putExtra("camera_package_name", "close");
this.mContext.sendBroadcast(intent);
Log.e("mjsheng", "settingNetControl extras is null");
@@ -587,11 +587,11 @@ public class MyJPushReceiver extends BroadcastReceiver {
Log.e("mymjsheng", "ban::" + s1);
// Log.e("mymjsheng", "not::" + str);
if (s1.equals("0")) {
Intent intent2 = new Intent("qch_camera_forbid");
Intent intent2 = new Intent("qch_camera_forbid").setPackage("com.android.settings");
// intent2.putExtra("camera_package_name", s1);
this.mContext.sendBroadcast(intent2);
} else {
Intent intent1 = new Intent("qch_camera_open");
Intent intent1 = new Intent("qch_camera_open").setPackage("com.android.settings");
// intent1.putExtra("camera_package_name", str);
this.mContext.sendBroadcast(intent1);
}
@@ -751,32 +751,6 @@ public class MyJPushReceiver extends BroadcastReceiver {
// }
}
private class BroadcastThread extends Thread {
String[] packagename;
String action;
public BroadcastThread(String a, String[] s) {
super();
this.packagename = s;
this.action = a;
}
@Override
public void run() {
super.run();
for (String name : packagename) {
Intent disIntent = new Intent(action);
disIntent.putExtra("package_name", name);
Log.e("mymjsheng", "package_name::" + name);
mContext.sendBroadcast(disIntent);
try {
sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
//应用id管控
@@ -854,7 +828,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
Log.e("SystemSetting", "qch_unlock_ipad---------" + i);
if (getBatteryLevel() >= CommonDatas.MIN_POWER) {
mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR").setPackage("com.android.settings"));
} else {
MySQLData.SetBooleanData(mContext, CommonDatas.IS_RESET, true);
}

View File

@@ -522,39 +522,13 @@ public class InitJpushServer extends Service {
Intent intent2 = new Intent("qch_camera_forbid");
intent2.putExtra("camera_package_name", camera_not);
intent2.putExtra("camera_package_name", camera_not).setPackage("com.android.settings");
sendBroadcast(intent2);
Intent intent1 = new Intent("qch_camera_open");
intent1.putExtra("camera_package_name", camera_ok);
intent1.putExtra("camera_package_name", camera_ok).setPackage("com.android.settings");
sendBroadcast(intent1);
}
private class BroadcastThread extends Thread {
String packagename[];
String action;
public BroadcastThread(String a, String s[]) {
super();
this.packagename = s;
this.action = a;
}
@Override
public void run() {
super.run();
for (String name : packagename) {
Intent disIntent = new Intent(action);
disIntent.putExtra("package_name", name);
Log.e("mymjsheng", "package_name::" + name);
sendBroadcast(disIntent);
// try {
// sleep(5000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
}
}
}
private void writeDeselectBrowserIDtoSystem(String ids) {
// if (!TextUtils.isEmpty(ids)) {
@@ -719,7 +693,7 @@ public class InitJpushServer extends Service {
private void resetDevice() {
boolean isReset = MySQLData.GetBooleanData(this, CommonDatas.IS_RESET);
if (isReset) {
sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR").setPackage("com.android.settings"));
}
}
@@ -768,7 +742,7 @@ public class InitJpushServer extends Service {
break;
}
Intent usbIntent = new Intent(usbStatus);
Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings");
sendBroadcast(usbIntent);
}
@@ -807,7 +781,7 @@ public class InitJpushServer extends Service {
break;
}
Intent navIntent = new Intent(navigationStatus);
Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui");
sendBroadcast(navIntent);
@@ -826,7 +800,7 @@ public class InitJpushServer extends Service {
statusbarStatus = "qch_hide_statusBar";
break;
}
Intent statusIntent = new Intent(statusbarStatus);
Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
sendBroadcast(statusIntent);
}
@@ -843,7 +817,7 @@ public class InitJpushServer extends Service {
cameraStatus = "qch_camera_forbid";
break;
}
Intent cameraIntent = new Intent(cameraStatus);
Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings");
sendBroadcast(cameraIntent);
@@ -861,7 +835,7 @@ public class InitJpushServer extends Service {
tfmediaStatus = "qch_tfmedia_forbid";
break;
}
Intent tfmediaIntent = new Intent(tfmediaStatus);
Intent tfmediaIntent = new Intent(tfmediaStatus).setPackage("com.android.settings");
sendBroadcast(tfmediaIntent);
if (setting_tfmedia == 1) {
JSONArray jSONArray = null;

View File

@@ -1,13 +1,16 @@
package com.mjsheng.myappstore.utils;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInstaller;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v4.content.FileProvider;
import android.util.Log;
import android.view.View;
@@ -18,12 +21,18 @@ import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.utils.update.ToastTool;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.annotation.ElementType;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
@@ -303,7 +312,15 @@ public class ApkUtils {
void installInfoCallback(String path, String packageName);
}
public static boolean installApp(Context context, String apkPath) {
public static void installApp(Context context, String filePath) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
installAppatPie(context, filePath);
} else {
installApps(filePath);
}
}
public static boolean installApps(String apkPath) {
ToastUtil.show("正在安装应用...");
Process process = null;
BufferedReader successResult = null;
@@ -347,6 +364,85 @@ public class ApkUtils {
return successMsg.toString().equalsIgnoreCase("success");
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static void installAppatPie(Context context, String apkFilePath) {
File file = new File(apkFilePath);
PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller();
PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstaller
.SessionParams.MODE_FULL_INSTALL);
sessionParams.setSize(file.length());
int sessionId = createSession(packageInstaller, sessionParams);
if (sessionId != -1) {
boolean copySuccess = copyApkFile(packageInstaller, sessionId, apkFilePath);
if (copySuccess) {
ToastUtil.show("正在安装应用");
install(packageInstaller, sessionId, context);
}
}
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static void install(PackageInstaller packageInstaller, int sessionId, Context context) {
try {
PackageInstaller.Session session = packageInstaller.openSession(sessionId);
Intent intent = new Intent(context, InstallResultReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context,
1, intent,
PendingIntent.FLAG_UPDATE_CURRENT
);
session.commit(pendingIntent.getIntentSender());
} catch (IOException e) {
e.printStackTrace();
}
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static int createSession(PackageInstaller packageInstaller, PackageInstaller.SessionParams sessionParams) {
int sessionId = -1;
try {
sessionId = packageInstaller.createSession(sessionParams);
} catch (IOException e) {
e.printStackTrace();
}
return sessionId;
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private static boolean copyApkFile(PackageInstaller pi, int sessionId, String apkFilePath) {
boolean success = false;
File apkFile = new File(apkFilePath);
PackageInstaller.Session session = null;
try {
session = pi.openSession(sessionId);
OutputStream out = session.openWrite("app.apk", 0, apkFile.length());
FileInputStream input = new FileInputStream(apkFile);
int read = 0;
byte[] buffer = new byte[65536];
// while (read != -1) {
// read = input.read(buffer);
// out.write(buffer, 0, read);
// }
while (true) {
read = input.read(buffer);
if (read == -1) {
session.fsync(out);
success = true;
out.close();
input.close();
break;
}
out.write(buffer, 0, read);
}
} catch (IOException e) {
e.printStackTrace();
Log.e("fht", e.getMessage());
}
return success;
}
public static void installApkInSilence(String installPath, String packageName) {
ToastUtil.show("正在安装应用...");

View File

@@ -0,0 +1,43 @@
package com.mjsheng.myappstore.utils;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import java.util.Iterator;
import java.util.Set;
import static android.content.pm.PackageInstaller.STATUS_PENDING_USER_ACTION;
public class InstallResultReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
//throw new UnsupportedOperationException("Not yet implemented");
// String s = intent.getAction();
// Log.e("fht", s);
// Bundle extras = intent.getExtras();
// Set<String> ks = extras.keySet();
// Iterator<String> iterator = ks.iterator();
// while (iterator.hasNext()) {
// Log.d("KEY", iterator.next());
// }
String STATUS = intent.getStringExtra("android.content.pm.extra.STATUS");
String PACKAGE_NAME = intent.getStringExtra("android.content.pm.extra.PACKAGE_NAME");
String SESSION_ID = intent.getStringExtra("android.content.pm.extra.SESSION_ID");
String LEGACY_STATUS = intent.getStringExtra("android.content.pm.extra.LEGACY_STATUS");
String STATUS_MESSAGE = intent.getStringExtra("android.content.pm.extra.STATUS_MESSAGE");
// Log.e("fht", STATUS);
// Log.e("fht", PACKAGE_NAME);
// Log.e("fht", SESSION_ID);
// Log.e("fht", LEGACY_STATUS);
// Log.e("fht", STATUS_MESSAGE);
if (STATUS_MESSAGE.equals("INSTALL_SUCCEEDED")) {
ToastUtil.show(PACKAGE_NAME + "安装成功");
}
}
}

View File

@@ -740,7 +740,7 @@ public class Utils {
}
public static String getSn() {
return Build.SERIAL;
return getSerial();
}
public static Bitmap createQRImage(String content, int widthPix, int heightPix) {