update:2020.09.07
fix:去掉不需要显示的toast,增加高德地图定位,增加更新设备获取详细信息
add:
This commit is contained in:
2020-09-08 15:07:09 +08:00
parent 83d7be8caf
commit 63ed572385
10 changed files with 454 additions and 117 deletions

View File

@@ -805,7 +805,11 @@ public class ApkUtils {
installedList += s + ",";
Log.e("addShortcut", s);
}
installedList = installedList.substring(0, installedList.length() - 1);
if (installedList.length() != 0) {
installedList = installedList.substring(0, installedList.length() - 1);
} else {
Log.e("addShortcut", installedList);
}
boolean qch_force_app = Settings.System.putString(context.getContentResolver(), "qch_launcher_icon_app", installedList);
// String old = Settings.System.getString(context.getContentResolver(), "qch_launcher_icon_app");
// Log.e("addShortcut", old);

View File

@@ -207,6 +207,7 @@ public class Configure {
public static final String GET_STUDENTS_INFO = HTTP_TAG_HEAD_NEW + "Sn/getStudent";
//通过sn获取信息
public static final String SEND_SCREENSHOT = HTTP_TAG_HEAD_NEW + "Screenshot/addImg";
//上传截图
public static final String UPDATE_DEVICEINFO = HTTP_TAG_HEAD_NEW + "Mac/getInfo";
//上传设备信息
}

View File

@@ -29,20 +29,25 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Environment;
import android.os.PowerManager;
import android.os.StatFs;
import android.provider.Settings;
import android.support.annotation.RequiresApi;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;
import com.alibaba.fastjson.JSONObject;
import com.arialyy.aria.core.Aria;
import com.blankj.utilcode.util.EncryptUtils;
import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.PathUtils;
import com.google.zxing.BarcodeFormat;
@@ -51,10 +56,12 @@ import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.R;
import com.mjsheng.myappstore.MyApplication;
import com.mjsheng.myappstore.comm.CommonDatas;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileReader;
@@ -66,6 +73,7 @@ import java.lang.reflect.Method;
import java.net.NetworkInterface;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -74,6 +82,7 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -901,23 +910,29 @@ public class Utils {
}
synchronized public static void doMasterClear(Context context) {
if (getBatteryLevel(context) >= CommonDatas.MIN_POWER) {
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
Intent intent = new Intent("android.intent.action.FACTORY_RESET");
intent.setPackage("android");
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
intent.putExtra("android.intent.extra.REASON", "MasterClearConfirm");
intent.putExtra("android.intent.extra.WIPE_EXTERNAL_STORAGE", false);
intent.putExtra("com.android.internal.intent.extra.WIPE_ESIMS", false);
context.sendBroadcast(intent);
} else {
if (BuildConfig.DEBUG) {
ToastUtil.show("收到重置设备推送消息");
return;
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
Intent intent = new Intent("android.intent.action.FACTORY_RESET");
intent.setPackage("android");
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
intent.putExtra("android.intent.extra.REASON", "MasterClearConfirm");
intent.putExtra("android.intent.extra.WIPE_EXTERNAL_STORAGE", false);
intent.putExtra("com.android.internal.intent.extra.WIPE_ESIMS", false);
context.sendBroadcast(intent);
} else {
//10.0的不需要最小电量
if (getBatteryLevel(context) >= CommonDatas.MIN_POWER) {
Intent intent = new Intent("android.intent.action.MASTER_CLEAR");
// intent.setPackage("com.android.settings");
context.sendBroadcast(intent);
} else {
MySQLData.SetBooleanData(context, CommonDatas.IS_RESET, true);
}
} else {
MySQLData.SetBooleanData(context, CommonDatas.IS_RESET, true);
}
}
synchronized private static int getBatteryLevel(Context mContext) {
@@ -1034,7 +1049,7 @@ public class Utils {
* 屏幕截图
* 适用于lanucher版
*/
public void shotScreen() {
public void shotScreen() {
//adb截图方法
new Thread(new Runnable() {
@Override
@@ -1097,5 +1112,242 @@ public class Utils {
context.startActivity(intent);
}
public static String getAndroiodScreenProperty(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getRealMetrics(dm);
int width = dm.widthPixels; // 屏幕宽度(像素)
int height = dm.heightPixels; // 屏幕高度(像素)
float density = dm.density; // 屏幕密度0.75 / 1.0 / 1.5
int densityDpi = dm.densityDpi; // 屏幕密度dpi120 / 160 / 240
// 屏幕宽度算法:屏幕宽度(像素)/屏幕密度
int screenWidth = (int) (width / density); // 屏幕宽度(dp)
int screenHeight = (int) (height / density);// 屏幕高度(dp)
Log.e("h_bl", "屏幕宽度(像素):" + width);
Log.e("h_bl", "屏幕高度(像素):" + height);
Log.e("h_bl", "屏幕密度0.75 / 1.0 / 1.5" + density);
Log.e("h_bl", "屏幕密度dpi120 / 160 / 240" + densityDpi);
Log.e("h_bl", "屏幕宽度dp" + screenWidth);
Log.e("h_bl", "屏幕高度dp" + screenHeight);
return screenWidth + "×" + screenHeight;
}
public static String getIMEI(Context context) {
String IMEI = "unknow";
String IMEI1, IMEI2, IMEI3;
//获取手机设备号
TelephonyManager TelephonyMgr = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
//8.0及以后版本获取
// if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
// IMEI1 = TelephonyMgr.getDeviceId();
// } else
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
// try {
// Method method = TelephonyMgr.getClass().getMethod("getImei");
// IMEI2 = (String) method.invoke(TelephonyMgr);
// } catch (Exception e) {
// e.printStackTrace();
// Log.e("getIMEI", e.getMessage());
// }
// } else {//9.0到10.0获取
IMEI = Settings.System.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
}
Log.e("IMEI:", "IMEI: " + IMEI);
return IMEI.toUpperCase();
}
public static String getMachine(Context context) {
String device = Build.MODEL;//机型
String imei = getIMEI(context);
String system_version = Build.VERSION.RELEASE;
String firmware_version = getProperty("ro.build.display.id", "获取失败");
String rom = getProperty("ro.custom.build.version", "获取失败");
String screen_rate = getAndroiodScreenProperty(context);
JSONObject jsonObject = new JSONObject();
jsonObject.put("device", device);
jsonObject.put("imei", imei);
jsonObject.put("system_version", system_version);
jsonObject.put("firmware_version", firmware_version);
jsonObject.put("rom", rom);
jsonObject.put("screen_rate", screen_rate);
return jsonObject.toJSONString();
}
public static String getHardware(Context context) {
JSONObject jsonObject = new JSONObject();
String electric = getBattery(context) + "%";
String charging = String.valueOf(getIsCharging(context));
String memory = Formatter.formatFileSize(context, getAvailMemory(context)) + "\t 已用" + "/" + "" + Formatter.formatFileSize(context, getTotalMemory(context));
String storage = getRemnantSize(context) + "/" + getDataTotalSize(context);
// String CPU = ;
return jsonObject.toJSONString();
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public static int getBattery(Context context) {
try {
BatteryManager batteryManager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
return batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
} catch (Exception e) {
Log.e("getBattery", "getBattery" + e.getMessage());
}
return 0;
}
public static int getBatteryPercentage(Context context) {
IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, iFilter);
int level = batteryStatus != null ? batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) : -1;
int scale = batteryStatus != null ? batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1) : -1;
float batteryPct = level / (float) scale;
return (int) (batteryPct * 100);
}
public static int getIsCharging(Context context) {
IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, ifilter);
// Are we charging / charged?
int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING ||
status == BatteryManager.BATTERY_STATUS_FULL;
// How are we charging?
// int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
// boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
// boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
if (isCharging) {
return 1;
} else {
return 0;
}
}
/**
* 描述:获取可用内存.
*
* @param context
* @return
*/
public static long getAvailMemory(Context context) {
// 获取android当前可用内存大小
ActivityManager activityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(memoryInfo);
// 当前系统可用内存 ,将获得的内存大小规格化
return memoryInfo.availMem;
}
/**
* 描述:总内存.
*
* @param context
* @return
*/
public static long getTotalMemory(Context context) {
// 系统内存信息文件
String file = "/proc/meminfo";
String memInfo;
String[] strs;
long memory = 0;
try {
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader, 8192);
// 读取meminfo第一行系统内存大小
memInfo = bufferedReader.readLine();
strs = memInfo.split("\\s+");
// for (String str : strs) {
// L.d(AppUtil.class, str + "\t");
// }
// 获得系统总内存单位KB
memory = Integer.valueOf(strs[1]).intValue();
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
// Byte转位KB或MB
return memory * 1024;
}
public static String formatFileSize(long fileS) {
DecimalFormat df = new DecimalFormat("#.0");
String fileSizeString = "";
String wrongSize = "0B";
if (fileS == 0) {
return wrongSize;
}
if (fileS < 1024) {
fileSizeString = df.format((double) fileS) + "B";
} else if (fileS < 1048576) {
fileSizeString = df.format((double) fileS / 1024) + "KB";
} else if (fileS < 1073741824) {
fileSizeString = df.format((double) fileS / 1048576) + "MB";
} else {
fileSizeString = df.format((double) fileS / 1073741824) + "GB";
}
return fileSizeString;
}
public static void queryStorage() {
StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getPath());
//存储块总数量
long blockCount = statFs.getBlockCount();
//块大小
long blockSize = statFs.getBlockSize();
//可用块数量
long availableCount = statFs.getAvailableBlocks();
//剩余块数量这个包含保留块including reserved blocks即应用无法使用的空间
long freeBlocks = statFs.getFreeBlocks();
//这两个方法是直接输出总内存和可用空间也有getFreeBytes
//API level 18JELLY_BEAN_MR2引入
long totalSize = statFs.getTotalBytes();
long availableSize = statFs.getAvailableBytes();
Log.e("statfs", "total = " + getUnit(totalSize));
Log.e("statfs", "availableSize = " + getUnit(availableSize));
//这里可以看出 available 是小于 free ,free 包括保留块。
Log.e("statfs", "total = " + getUnit(blockSize * blockCount));
Log.e("statfs", "available = " + getUnit(blockSize * availableCount));
Log.e("statfs", "free = " + getUnit(blockSize * freeBlocks));
}
private static String[] units = {"B", "KB", "MB", "GB", "TB"};
/**
* 单位转换
*/
private static String getUnit(float size) {
int index = 0;
while (size > 1024 && index < 4) {
size = size / 1024;
index++;
}
return String.format(Locale.getDefault(), " %.2f %s", size, units[index]);
}
public static String getDataTotalSize(Context context) {
StatFs sf = new StatFs(context.getCacheDir().getAbsolutePath());
long blockSize = sf.getBlockSize();
long totalBlocks = sf.getBlockCount();
return Formatter.formatFileSize(context, blockSize * totalBlocks);
}
public static String getRemnantSize(Context context) {
StatFs sf = new StatFs(context.getCacheDir().getAbsolutePath());
long availableSize = sf.getAvailableBytes();
return Formatter.formatFileSize(context, availableSize);
}
}