update:2020.06.15

fix:没有推送也能删除应用
add:没有锁定设备不初始化极光推送
This commit is contained in:
2020-06-15 18:17:38 +08:00
parent 64aae388b8
commit 780fb8561b
9 changed files with 438 additions and 391 deletions

View File

@@ -15,8 +15,8 @@ android {
minSdkVersion 20
targetSdkVersion 29
versionCode 145
versionName "3.0.2"//测试jiaoguanyi.cn
versionCode 147
versionName "3.0.4"//测试jiaoguanyi.cn
// versionCode 129
// versionName "2.0.0.9"// 正式jiaoguanyi.com 双数正式 单数测试
multiDexEnabled true

View File

@@ -128,10 +128,10 @@ public class MyApplication extends MultiDexApplication {
JPushInterface.setDebugMode(true);
JPushInterface.requestPermission(this);
// 初始化 JPush
JPushInterface.init(this);
//JPushInterface.init(this);
//解锁设备不需要初始化
context = getApplicationContext();
// Thread.setDefaultUncaughtExceptionHandler(this);
//Thread.setDefaultUncaughtExceptionHandler(this);
mDateFormat = new SimpleDateFormat("HH:mm");
initOKHttp();
@@ -220,7 +220,6 @@ public class MyApplication extends MultiDexApplication {
}
public void onTagOperatorResult(JPushMessage jPushMessage) {
if (jPushMessage == null) {
return;
@@ -547,14 +546,9 @@ public class MyApplication extends MultiDexApplication {
localAppList.add(appInformation);
}
}
} else {
}
}
synchronized public void getWhitePackageList() {
@@ -583,8 +577,6 @@ public class MyApplication extends MultiDexApplication {
super.onError(call, response, e);
}
});
}
private void writeAppPackageList(String result) {

View File

@@ -142,6 +142,7 @@ public class MainActivity extends AppCompatActivity {
private int DeviceInfo;
private RelativeLayout checkupdate;
private ImageView back;
private RelativeLayout layout_class, layout_number, layout_name;
//jiguang
public static boolean isForeground = false;
//for receive customer msg from jpush server
@@ -151,6 +152,7 @@ public class MainActivity extends AppCompatActivity {
public static final String KEY_MESSAGE = "message";
public static final String KEY_EXTRAS = "extras";
public void registerMessageReceiver() {
mMessageReceiver = new MessageReceiver();
IntentFilter filter = new IntentFilter();
@@ -308,7 +310,6 @@ public class MainActivity extends AppCompatActivity {
callback = new ToastCallback(this);
initView();
timerImitate();
initData();
downloadManager = DownloadService.getDownloadManager();
@@ -386,6 +387,10 @@ public class MainActivity extends AppCompatActivity {
lazyExit();
}
});
layout_class = findViewById(R.id.layout_class);
layout_number = findViewById(R.id.layout_number);
layout_name = findViewById(R.id.layout_name);
}
final static int COUNTS = 5;// 点击次数
@@ -409,10 +414,8 @@ public class MainActivity extends AppCompatActivity {
Log.e("mjhsneg", "gagagag--------------------------" + Utils.getSerial());
getLockedState();
// MyApplication.getInstance().getWhitePackageList();
initJpush();//初始化极光推送
HTTPInterface.setJpushTags(this);
// update();//接口更新app
sendMACaddress();
checkUpdate();//更新app
Log.e("mac", com.blankj.utilcode.util.DeviceUtils.getMacAddress());
@@ -570,9 +573,13 @@ public class MainActivity extends AppCompatActivity {
Log.e("ttlocked2", "DeselectBrowserArray---------" + a);
String b = Settings.System.getString(getApplicationContext().getContentResolver(), "qch_webblack_url");
Log.e("ttlocked2", "qch_webblack_url---------" + b);
HTTPInterface.setJpushTags(MainActivity.this);
sendMACaddress();
timerImitate();
lazyLoading();
}
} else if (code == -300) {
ApkUtils.uninstallAllApp(MainActivity.this);
}
}
@@ -642,16 +649,19 @@ public class MainActivity extends AppCompatActivity {
if (null != info) {
if (info.getBatch().equals("")) {
tv_class.setText("暂无信息");
layout_class.setVisibility(View.GONE);
} else {
tv_class.setText(info.getBatch());
}
if (info.getSno().equals("")) {
tv_number.setText("暂无信息");
layout_number.setVisibility(View.GONE);
} else {
tv_number.setText(info.getSno());
}
if (info.getRealname().equals("")) {
tv_name.setText("暂无信息");
layout_name.setVisibility(View.GONE);
} else {
tv_name.setText(info.getRealname());
}
@@ -661,6 +671,9 @@ public class MainActivity extends AppCompatActivity {
tv_class.setText("暂无信息");
tv_number.setText("暂无信息");
tv_name.setText("暂无信息");
layout_class.setVisibility(View.GONE);
layout_number.setVisibility(View.GONE);
layout_name.setVisibility(View.GONE);
break;
}
@@ -918,6 +931,7 @@ public class MainActivity extends AppCompatActivity {
private void initJpush() {
JPushInterface.init(this);
onTagAliasAction(7);
String rid = JPushInterface.getRegistrationID(getApplicationContext());
if (!rid.isEmpty()) {
@@ -962,7 +976,7 @@ public class MainActivity extends AppCompatActivity {
@Override
public void call(Long aLong) {
Log.e("JPushInterface", "JPushInterface重新加载");
initJpush();
initJpush();//初始化极光推送
HTTPInterface.setJpushTags(MainActivity.this);
}
});
@@ -996,7 +1010,7 @@ public class MainActivity extends AppCompatActivity {
}
}
private void getAppLimitApi() {
private void getAppLimitApi() {
AppLimitApi appLimitApi = Network.getAppLimitApi();
appLimitApi.getAppLimitApi(Configure.HTTP_KEY, Utils.getSerial())
.subscribeOn(Schedulers.io())
@@ -1463,6 +1477,7 @@ public class MainActivity extends AppCompatActivity {
MyApplication.getInstance().setFinished(true);
if (!net_ok.equals("")) {
String[] nots = net_ok.split(",");
Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", net_ok);
Log.e("fht", "not::" + net_ok);
}

View File

@@ -714,6 +714,7 @@ public class HTTPInterface {
MyApplication.getInstance().setFinished(true);
if (!net_ok.equals("")) {
String[] nots = net_ok.split(",");
Settings.System.putString(context.getContentResolver(), "qch_jgy_network_allow", net_ok);
Log.e("fht", "not::" + net_ok);
}

View File

@@ -52,28 +52,26 @@ import okhttp3.ResponseBody;
public class MyJPushReceiver extends BroadcastReceiver {
private static final String TAG = "MyJPushReceiver";
private final String ACTION_HrReceiver_JGY = "qch_jgy_network_allow";
private final String ACTION_HrReceiver_JGY_DIS = "qch_jgy_network_disallow";
private final String MSG_APPID = "5";
private final String MSG_BROWSER = "4";
private final String MSG_DELETE = "1";
private final String MSG_INSTALL = "9";
private final String MSG_SETTING = "2";
private final String MSG_LOCK = "10";//解锁
private final String MSG_BROWSER = "4";
private final String MSG_APPID = "5";
private final String MSG_NET_CONTROL = "6";
private final String MSG_POWER_ON = "7";
private final String MSG_RESET = "8";//加锁
private final String MSG_RESET = "8";//重置
private final String MSG_SETTING = "2";
private final String MSG_INSTALL = "9";
private final String MSG_LOCK = "10";//解锁
private final String MSG_CAMERA = "11";
@@ -81,7 +79,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
private final String GET_APP_USEDTIME = "13";
private final String GET_FORCEDOWNLOADURL = "14";
private final String GET_FORCEDOWNLOADURL = "14";//强制下载
private final String SET_HOMEPAG_TAG = "15";//主页和书签管控
@@ -93,9 +91,126 @@ public class MyJPushReceiver extends BroadcastReceiver {
private final String DISABLE_APP_SLIDE = "19";//禁止滑动
private Context mContext;
private int changeNum(int paramInt) {
switch (paramInt) {
default:
return 1;
case 0:
return 1;
case 1:
break;
}
return 0;
}
private void processCustomMessage(final Context context, Bundle bundle) {
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
String title = bundle.getString(JPushInterface.EXTRA_TITLE);
String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE);
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
String package_name = bundle.getString("package_name");
LogUtils.e("mjsheng", "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras);
// ToastUtils.showShort("message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name);
// Toast.makeText(context, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name, Toast.LENGTH_SHORT).show();
switch (message) {
case MSG_DELETE:
if (!TextUtils.isEmpty(title)) {
if (SaveListUtils.getlist().contains(title)) {
SaveListUtils.getlist().remove(title);
}
SaveListUtils.sendForceAPP(mContext);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ApkUtils.uninstall(mContext, title);
} else {
ApkUtils.deleteApkInSilence(title);
}
}
getAppLimitApi();
HTTPInterface.getNetAndLaunchSetting(mContext);
break;
case MSG_SETTING:
if (!TextUtils.isEmpty(extras)) {
SettingSysData(extras);
Log.e(TAG, "title--------" + extras);
}
// getSystemSetting();
break;
case MSG_BROWSER:
getDeselectBrowerID();
break;
case MSG_APPID:
getDeselectID();
break;
case MSG_NET_CONTROL:
settingNetControl(extras);
break;
case MSG_POWER_ON:
settingPowerOn(extras);
break;
case MSG_RESET:
Utils.doMasterClear(mContext);
break;
case MSG_INSTALL:
// mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
getAppLimitApi();
doDownloadAndInstall(extras);
HTTPInterface.setHideDesktopIcon(mContext);
break;
case MSG_LOCK:
settingLock(extras);
break;
case MSG_CAMERA:
settingCamera(extras);
break;
case MSG_ONEPACKAGES:
if (MyApplication.getInstance().isFinished()) {
settingOneNet(extras);
}
break;
case GET_APP_USEDTIME:
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(extras);
String random = jsonObject.getString("random");
String sendType = jsonObject.getString("type");
MyApplication.sendAppUsedTime(random, sendType);
break;
case GET_FORCEDOWNLOADURL:
com.alibaba.fastjson.JSONObject URI = JSON.parseObject(extras);
String versionCode = URI.getString("version_code");
String url = URI.getString("url");
com.alibaba.fastjson.JSONObject packageObj = new com.alibaba.fastjson.JSONObject();
packageObj.put("app_name", "教管易");
packageObj.put("app_package", "com.jiaoguanyi.store");
Aria.download(this)
.load(url) //读取下载地址
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString("com.jiaoguanyi.store") + ".apk", true)
.setExtendField(packageObj.toJSONString())
.create(); //启动下载}
break;
case SET_HOMEPAG_TAG:
setHomepagtag(extras);
break;
case APP_WEBSITE:
setAPPinsideWebsite(extras);
break;
case DISABLE_APPUPDATE:
Log.e("fht", extras);
setDisableUpdateList(extras);
break;
case HIDE_DESKTOP_ICON:
HTTPInterface.setHideDesktopIcon(context);
break;
case DISABLE_APP_SLIDE:
setDisableSlideList(extras);
break;
}
}
private void SettingSysData(String extras) {
try {
JSONObject data = new JSONObject(extras);
@@ -282,18 +397,6 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
}
private int changeNum(int paramInt) {
switch (paramInt) {
default:
return 1;
case 0:
return 1;
case 1:
break;
}
return 0;
}
private void doDownloadAndInstall(String s) {
if (TextUtils.isEmpty(s)) {
Log.e("mjsheng", "doDownloadAndInstall extras is null");
@@ -517,112 +620,6 @@ public class MyJPushReceiver extends BroadcastReceiver {
return stringBuilder.toString();
}
private void processCustomMessage(final Context context, Bundle bundle) {
String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
String title = bundle.getString(JPushInterface.EXTRA_TITLE);
String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE);
String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
String package_name = bundle.getString("package_name");
LogUtils.e("mjsheng", "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras);
// ToastUtils.showShort("message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name);
// Toast.makeText(context, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name, Toast.LENGTH_SHORT).show();
switch (message) {
case MSG_DELETE:
if (!TextUtils.isEmpty(title)) {
if (SaveListUtils.getlist().contains(title)) {
SaveListUtils.getlist().remove(title);
}
SaveListUtils.sendForceAPP(mContext);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ApkUtils.uninstall(mContext, title);
} else {
ApkUtils.deleteApkInSilence(title);
}
}
getAppLimitApi();
HTTPInterface.getNetAndLaunchSetting(mContext);
break;
case MSG_SETTING:
if (!TextUtils.isEmpty(extras)) {
SettingSysData(extras);
Log.e(TAG, "title--------" + extras);
}
// getSystemSetting();
break;
case MSG_BROWSER:
getDeselectBrowerID();
break;
case MSG_APPID:
getDeselectID();
break;
case MSG_NET_CONTROL:
settingNetControl(extras);
break;
case MSG_POWER_ON:
settingPowerOn(extras);
break;
case MSG_RESET:
Utils.doMasterClear(mContext);
break;
case MSG_INSTALL:
// mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
getAppLimitApi();
doDownloadAndInstall(extras);
HTTPInterface.setHideDesktopIcon(mContext);
break;
case MSG_LOCK:
settingLock(extras);
break;
case MSG_CAMERA:
settingCamera(extras);
break;
case MSG_ONEPACKAGES:
if (MyApplication.getInstance().isFinished()) {
settingOneNet(extras);
}
break;
case GET_APP_USEDTIME:
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(extras);
String random = jsonObject.getString("random");
String sendType = jsonObject.getString("type");
MyApplication.sendAppUsedTime(random, sendType);
break;
case GET_FORCEDOWNLOADURL:
com.alibaba.fastjson.JSONObject URI = JSON.parseObject(extras);
String versionCode = URI.getString("version_code");
String url = URI.getString("url");
com.alibaba.fastjson.JSONObject packageObj = new com.alibaba.fastjson.JSONObject();
packageObj.put("app_name", "教管易");
packageObj.put("app_package", "com.jiaoguanyi.store");
Aria.download(this)
.load(url) //读取下载地址
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString("com.jiaoguanyi.store") + ".apk", true)
.setExtendField(packageObj.toJSONString())
.create(); //启动下载}
break;
case SET_HOMEPAG_TAG:
setHomepagtag(extras);
break;
case APP_WEBSITE:
setAPPinsideWebsite(extras);
break;
case DISABLE_APPUPDATE:
Log.e("fht", extras);
setDisableUpdateList(extras);
break;
case HIDE_DESKTOP_ICON:
HTTPInterface.setHideDesktopIcon(context);
break;
case DISABLE_APP_SLIDE:
setDisableSlideList(extras);
break;
}
}
private void setDisableSlideList(String s) {
try {
@@ -659,7 +656,6 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
}
// args[1] = message::11--type::11--title::ok--extras::{"ban":"com.lizi.yuwen,com.iyuyan.jp2listensimple,com.netease.edu.study," +
// "cn.xuexi.android,com.tuixin.pospointsystem"
// ,"not":"com.duoduo.child.story,com.shanbay.words,com.jiongji.andriod.card,fm.jihua.kecheng,com.duia.duiaapp," +
@@ -692,7 +688,6 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
}
private void settingOneNet(String s) {
if (TextUtils.isEmpty(s)) {
Log.e("mjsheng", "settingNetControl extras is null");
@@ -753,7 +748,6 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
private void settingPowerOn(String s) {
if (TextUtils.isEmpty(s)) {
Log.e("mjsheng", "settingNetControlAndPowerOn extras is null");
@@ -845,7 +839,6 @@ public class MyJPushReceiver extends BroadcastReceiver {
// }
}
//应用id管控
private void writeDeselectIDtoSystem(String s1, String result) {
if (!TextUtils.isEmpty(s1) && !TextUtils.isEmpty(result)) {
@@ -885,7 +878,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
// Log.e(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)
// + "---" + bundle.getString(JPushInterface.EXTRA_TITLE) + "---" + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE)
// + "---" + bundle.getString(JPushInterface.EXTRA_EXTRA) + "----" + bundle.getString("package_name"));
processCustomMessage(context, bundle);
processCustomMessage(context, bundle);//屏蔽推送
} else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
Log.e(TAG, "[MyReceiver] 接收到推送下来的通知" + bundle.getString(JPushInterface.EXTRA_EXTRA));
// doDownloadAndInstall(bundle.getString(JPushInterface.EXTRA_EXTRA));

View File

@@ -5,6 +5,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
@@ -41,6 +42,7 @@ import com.mjsheng.myappstore.network.api.DeselectIDApi;
import com.mjsheng.myappstore.network.api.ForceDownloadApi;
import com.mjsheng.myappstore.network.api.NetAndLaunchApi;
import com.mjsheng.myappstore.network.api.SystemSettingApi;
import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.Configure;
import com.mjsheng.myappstore.utils.MySQLData;
import com.mjsheng.myappstore.utils.SaveListUtils;
@@ -50,7 +52,9 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@@ -93,8 +97,7 @@ public class InitJpushServer extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// 初始化 JPush
JPushInterface.init(this);
getAppLimitApi();//获取可以写入的app包名
HTTPInterface.getNetAndLaunchSetting(this);
timerImitate();
@@ -147,24 +150,7 @@ public class InitJpushServer extends Service {
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
Log.e("JPushInterface", "JPushInterface重新加载");
initJpush();
HTTPInterface.setJpushTags(InitJpushServer.this);
checkUpdate();
getNetworkState();
sendMACaddress();
}
});
}
private void getNetworkState() {
Observable.timer(1000, TimeUnit.MILLISECONDS)
.observeOn(rx.android.schedulers.AndroidSchedulers.mainThread())
.subscribe(new Action1<Long>() {
@Override
public void call(Long aLong) {
Log.e("JPushInterface", "reconnectNetworkState");
getLockedState();//
}
});
@@ -322,10 +308,35 @@ public class InitJpushServer extends Service {
result = result + "," + store;
}
Settings.System.putString(getContentResolver(), "qch_app_forbid", result);
Log.e("mjsheng", "qch_app_forbid :"+result);
Log.e("mjsheng", "qch_app_forbid :" + result);
} else {
Log.e("mjsheng", "writeAppPackageList is null:");
}
deleteOtherApp(result);
}
private void deleteOtherApp(String packageList) {
Log.e("deleteOtherApp", "packageList:" + packageList);
String[] result = packageList.split(",");
List<String> resultList = new ArrayList<>(Arrays.asList(result));
List<String> packageLists = ApkUtils.queryFilterAppInfo(InitJpushServer.this);
Log.e("deleteOtherApp", "packageLists:" + packageLists.toString());
if (resultList.size() > 0) {
for (final String packageName : packageLists) {
if (!resultList.contains(packageName)) {
new Thread(new Runnable() {
@Override
public void run() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ApkUtils.uninstall(InitJpushServer.this, packageName);
} else {
ApkUtils.deleteApkInSilence(packageName);
}
}
}).start();
Log.e("deleteOtherApp", "uninstall apkName:" + packageName);
}
}
}
}
@@ -477,7 +488,7 @@ public class InitJpushServer extends Service {
if ("com.jiaoguanyi.appstore".equals(forceDownloadData.getApp_package())) {
com.alibaba.fastjson.JSONObject packageObj = new com.alibaba.fastjson.JSONObject();
packageObj.put("app_name", forceDownloadData.getApp_name());
packageObj.put("app_package",forceDownloadData.getApp_package());
packageObj.put("app_package", forceDownloadData.getApp_package());
Aria.download(this)
.load(forceDownloadData.getApp_url()) //读取下载地址
.setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString("com.jiaoguanyi.appstore") + ".apk", true)
@@ -589,11 +600,12 @@ public class InitJpushServer extends Service {
String[] bans = net_not.split(",");
Settings.System.putString(getContentResolver(), "qch_jgy_network_disallow", net_not);
Log.e("fht", "ban::" + net_not);
}
MyApplication.getInstance().setFinished(true);
if (!net_ok.equals("")) {
String[] nots = net_ok.split(",");
Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", net_ok);
Log.e("fht", "not::" + net_ok);
}
@@ -743,6 +755,12 @@ public class InitJpushServer extends Service {
// Settings.System.putString(getApplicationContext().getContentResolver(), "DeselectBrowserArray", "http://www.baidu.com");
String ss = Settings.System.getString(getApplicationContext().getContentResolver(), "DeselectBrowserArray");
Log.e("jpttlocked2", "DeselectBrowserArray---------" + ss);
// 初始化 JPush
JPushInterface.init(InitJpushServer.this);
initJpush();
HTTPInterface.setJpushTags(InitJpushServer.this);
sendMACaddress();
// getAppLimitApi();//获取可以写入的app包名
getDeselectID();
// getDeselectBrowerID();
@@ -758,6 +776,8 @@ public class InitJpushServer extends Service {
// MyApplication.getInstance().getWhitePackageList();
}
} else if (code == -300) {
ApkUtils.uninstallAllApp(InitJpushServer.this);
}
}
@@ -770,7 +790,8 @@ public class InitJpushServer extends Service {
});// 请求方式和请求url
}
private void resetDevice() {
synchronized private void resetDevice() {
boolean isReset = MySQLData.GetBooleanData(this, CommonDatas.IS_RESET);
if (isReset) {
Utils.doMasterClear(this);

View File

@@ -579,11 +579,11 @@ public class ApkUtils {
private static String[] excludePackageName = {"com.easyold.uiuios"};
public static List<ApplicationInfo> queryFilterAppInfo(Context context) {
public static List<String> queryFilterAppInfo(Context context) {
PackageManager pm = context.getPackageManager();
// 查询所有已经安装的应用程序
List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除但还有安装目录的
List<ApplicationInfo> applicationInfos = new ArrayList<>();
List<String> applicationInfos = new ArrayList<>();
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
@@ -597,17 +597,13 @@ public class ApkUtils {
}
for (ApplicationInfo app : appInfos) {
// if((app.flags & ApplicationInfo.FLAG_SYSTEM) <= 0)//通过flag排除系统应用会将电话、短信也排除掉
// {
// applicationInfos.add(app);
// }
if ((app.flags & ApplicationInfo.FLAG_SYSTEM) <= 0)//通过flag排除系统应用会将电话、短信也排除掉
{
applicationInfos.add(app.packageName);
}
// if(app.uid > 10000){//通过uid排除系统应用在一些手机上效果不好
// applicationInfos.add(app);
// }
if (allowPackages.contains(app.packageName) && !Arrays.asList(excludePackageName).contains(app.packageName)) {
// if (allowPackages.contains(app.packageName)) {
applicationInfos.add(app);
}
}
return applicationInfos;
}
@@ -616,6 +612,7 @@ public class ApkUtils {
PackageManager pm = context.getPackageManager();
// 查询所有已经安装的应用程序
List<ApplicationInfo> appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除但还有安装目录的
List<String> packageList = new ArrayList<>();
// 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent
@@ -646,4 +643,22 @@ public class ApkUtils {
}
return packageList;
}
public static synchronized void uninstallAllApp(Context context) {
List<String> appList = ApkUtils.queryFilterAppInfo(context);
if (null != appList && appList.size() > 0) {
for (String packageName : appList) {
Log.e("fht", "uninstallAllApp packageName is:" + packageName);
if (packageName.equals("com.jiaoguanyi.store") || packageName.equals(BuildConfig.APPLICATION_ID)) {
continue;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
ApkUtils.uninstall(context, packageName);
} else {
ApkUtils.deleteApkInSilence(packageName);
}
}
}
}
}

View File

@@ -135,105 +135,6 @@
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_20"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="班级"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_class"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_20"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="学号"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_20"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="姓名"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
@@ -271,6 +172,110 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_class"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_20"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="班级"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_class"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_number"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_20"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="学号"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_name"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_20"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="姓名"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
</LinearLayout>
<TextView
@@ -279,7 +284,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_8"
android:text="连续点击版本号,自动下载新版本"
android:textSize="@dimen/sp_12"
android:textSize="@dimen/sp_9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"

View File

@@ -137,108 +137,6 @@
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
android:layout_marginTop="@dimen/dp_10">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="班级"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_class"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
android:layout_marginTop="@dimen/dp_10">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
android:layout_marginTop="@dimen/dp_10">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="姓名"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
@@ -276,6 +174,113 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_class"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
android:layout_marginTop="@dimen/dp_10">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="班级"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_class"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_number"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
android:layout_marginTop="@dimen/dp_10">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="学号"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/layout_name"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_30"
android:layout_marginTop="@dimen/dp_10">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="姓名"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginStart="@dimen/dp_5"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginEnd="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:layout_marginBottom="@dimen/dp_5"
android:text="暂无信息"
android:textColor="#000000"
android:textSize="@dimen/sp_12" />
</RelativeLayout>
</LinearLayout>
<TextView
@@ -284,7 +289,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_8"
android:text="连续点击版本号,自动下载新版本"
android:textSize="@dimen/sp_12"
android:textSize="@dimen/sp_9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"