|
|
资讯缩略图:
资讯发布日期:2025-12-19
资讯发布简介:AIWROK软件平台设备信息全面检测工具例子
资讯关键词:AIWROK软件平台设备信息全面检测工具例子
资讯所属分类:IT资讯
联系:
① 本信息收集于网络,如有不对的地方欢迎联系我纠正! ② 本信息免费收录,不存在价格的问题! ③ 如果您的网站也想这样出现在这里,请您加好友情链接,我当天会审核通过!
④友情链接关键字:软件网站分类目录 网址:http://www.postbbs.com/
资讯详细描述
 | |  |  | AIWROK软件平台设备信息全面检测工具例子
- /**
- * AIWROK平台设备信息全面检测工具
- * //🍎交流QQ群711841924群一,苹果内测群,528816639
- * 本工具旨在全面检测和展示Android设备的各项硬件和软件信息
- * 包括设备基本信息、屏幕参数、电池状态、存储空间、内存使用情况、网络状态等
- * 采用了多层容错机制和友好的可视化展示方式
- * 适用于AIWROK自动化平台环境
- */
- // 安全调用函数,防止方法不存在时报错
- function safeCall(methodName, caller, defaultValue) {
- try {
- if (typeof caller[methodName] === 'function') {
- var result = caller[methodName]();
- return result !== undefined && result !== null ? result : (defaultValue || "未知");
- } else {
- return defaultValue || "方法不可用";
- }
- } catch (e) {
- return defaultValue || "调用出错: " + e.message;
- }
- }
- // 更安全的调用函数,支持传参
- function safeCallWithArgs(methodName, caller, args, defaultValue) {
- try {
- if (typeof caller[methodName] === 'function') {
- var result = caller[methodName](args);
- return result !== undefined && result !== null ? result : (defaultValue || "未知");
- } else {
- return defaultValue || "方法不可用";
- }
- } catch (e) {
- return defaultValue || "调用出错: " + e.message;
- }
- }
- // 格式化存储空间大小
- function formatStorageSize(bytes) {
- if (bytes <= 0) return "0 B";
-
- var sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
- var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
- var size = Math.round(bytes / Math.pow(1024, i) * 100) / 100;
- return size + ' ' + sizes[i];
- }
- // 获取设备基本信息
- function getDeviceInfo() {
- printl("========== 设备基本信息 ==========");
-
- var info = {
- "设备品牌": safeCall("getBrand", device),
- "设备型号": safeCall("getModel", device),
- "系统版本": safeCall("getVersion", device),
- "设备ID": safeCall("getDeviceID", device),
- "设备整数ID": safeCall("getDeviceIntID", device),
- "IMEI": safeCall("getIMEI", device),
- "OAID": safeCall("getOAID", device),
- "IP地址": safeCall("getIP", device)
- };
-
- for (var key in info) {
- printl(key + ": " + info[key]);
- }
-
- return info;
- }
- // 获取屏幕信息
- function getScreenInfo() {
- printl("\n========== 屏幕信息 ==========");
-
- var width = 0, height = 0;
-
- // 尝试使用screen对象获取屏幕信息
- if (typeof screen !== 'undefined') {
- if (typeof screen.getScreenWidth === 'function') {
- try {
- width = screen.getScreenWidth();
- } catch (e) {
- printl("通过screen获取宽度失败: " + e.message);
- }
- }
-
- if (typeof screen.getScreenHeight === 'function') {
- try {
- height = screen.getScreenHeight();
- } catch (e) {
- printl("通过screen获取高度失败: " + e.message);
- }
- }
- }
-
- // 如果screen对象不可用或获取失败,尝试device对象
- if ((!width || !height) && typeof device !== 'undefined') {
- if (typeof device.getScreenWidth === 'function') {
- try {
- width = device.getScreenWidth();
- } catch (e) {
- printl("通过device获取宽度失败: " + e.message);
- }
- }
-
- if (typeof device.getScreenHeight === 'function') {
- try {
- height = device.getScreenHeight();
- } catch (e) {
- printl("通过device获取高度失败: " + e.message);
- }
- }
- }
-
- // 如果仍然没有获取到,则尝试使用默认值
- if (!width && typeof device !== 'undefined' && typeof device.width === 'number') {
- width = device.width;
- }
-
- if (!height && typeof device !== 'undefined' && typeof device.height === 'number') {
- height = device.height;
- }
-
- if (width && height) {
- printl("屏幕分辨率: " + width + " × " + height);
- printl("屏幕密度: " + width + " × " + height + " 像素");
- } else {
- printl("屏幕分辨率: 无法获取");
- }
-
- return { width: width, height: height };
- }
- // 获取电池信息
- function getBatteryInfo() {
- printl("\n========== 电池信息 ==========");
-
- var level = "未知";
- var status = "未知";
-
- if (typeof device !== 'undefined') {
- // 尝试多种方式获取电池信息
- if (typeof device.getBatteryLevel === 'function') {
- try {
- level = device.getBatteryLevel();
- if (level === null || level === undefined) {
- level = "未知";
- }
- } catch (e) {
- printl("获取电池电量失败: " + e.message);
- }
- }
-
- // 注意:device.getBatteryStatus 方法不存在,因此移除相关代码
- }
-
- // 格式化电池信息显示
- if (level !== "未知" && !isNaN(level)) {
- printl("电池电量: " + level + "%");
-
- // 根据电量显示状态图标
- var batteryIcon = "🔋";
- if (level > 80) batteryIcon = "🔋";
- else if (level > 50) batteryIcon = "🔋";
- else if (level > 20) batteryIcon = "🔋";
- else batteryIcon = "🪫";
-
- printl("电量状态: " + batteryIcon + " " + level + "%");
- } else {
- printl("电池电量: " + level);
- }
-
- // 移除对不存在方法的调用
- // printl("电池状态: " + status);
-
- return { level: level };
- }
- // 获取存储信息
- function getStorageInfo() {
- printl("\n========== 存储信息 ==========");
-
- // 尝试多种方式获取存储信息
- if (typeof file !== 'undefined') {
- var totalSpace = -1;
- var freeSpace = -1;
-
- // 尝试获取总空间
- if (typeof file.getTotalSpace === 'function') {
- try {
- totalSpace = file.getTotalSpace("/sdcard/");
- if (totalSpace <= 0) {
- // 尝试其他路径
- totalSpace = file.getTotalSpace("/");
- }
- } catch (e) {
- printl("获取总存储空间失败: " + e.message);
- }
- }
-
- // 尝试获取可用空间
- if (typeof file.getFreeSpace === 'function') {
- try {
- freeSpace = file.getFreeSpace("/sdcard/");
- if (freeSpace <= 0) {
- // 尝试其他路径
- freeSpace = file.getFreeSpace("/");
- }
- } catch (e) {
- printl("获取可用存储空间失败: " + e.message);
- }
- }
-
- // 如果通过file对象的方法获取成功
- if (totalSpace > 0 && freeSpace >= 0) {
- var usedSpace = totalSpace - freeSpace;
- var usedPercentage = ((usedSpace / totalSpace) * 100).toFixed(1);
- printl("总存储空间: " + formatStorageSize(totalSpace));
- printl("已使用空间: " + formatStorageSize(usedSpace) + " (" + usedPercentage + "%)");
- printl("可用空间: " + formatStorageSize(freeSpace));
-
- // 显示存储使用情况的进度条
- var progressBarLength = 20;
- var filledLength = Math.round((usedSpace / totalSpace) * progressBarLength);
- var bar = "[" + Array(filledLength + 1).join("█") + Array(progressBarLength - filledLength + 1).join("░") + "]";
- printl("使用情况: " + bar);
- return;
- }
- }
-
- // 尝试通过device对象获取存储信息(只尝试确实存在的方法)
- if (typeof device !== 'undefined') {
- try {
- // 检查是否有获取存储信息的方法(不调用不存在的方法)
- var deviceMethods = [];
- for (var prop in device) {
- if (typeof device[prop] === 'function' && prop.indexOf('Storage') !== -1) {
- deviceMethods.push(prop);
- }
- }
-
- if (deviceMethods.length > 0) {
- printl("设备存储相关方法: " + deviceMethods.join(', '));
- }
- } catch (e) {
- // 忽略错误
- }
- }
-
- // 尝试通过环境变量获取存储信息
- try {
- if (typeof java !== 'undefined' && java.lang && java.lang.System) {
- var system = java.lang.System;
- if (system) {
- var properties = system.getProperties();
- if (properties) {
- var fileSeparator = properties.get("file.separator") || "/";
- var sdcardPath = "/sdcard";
-
- // 尝试使用Java File类获取存储信息
- if (java.io && java.io.File) {
- var File = java.io.File;
- var sdcardFile = new File(sdcardPath);
- if (sdcardFile.exists()) {
- totalSpace = sdcardFile.getTotalSpace();
- freeSpace = sdcardFile.getFreeSpace();
-
- if (totalSpace > 0 && freeSpace >= 0) {
- var usedSpace = totalSpace - freeSpace;
- var usedPercentage = ((usedSpace / totalSpace) * 100).toFixed(1);
- printl("总存储空间: " + formatStorageSize(totalSpace));
- printl("已使用空间: " + formatStorageSize(usedSpace) + " (" + usedPercentage + "%)");
- printl("可用空间: " + formatStorageSize(freeSpace));
-
- // 显示存储使用情况的进度条
- var progressBarLength = 20;
- var filledLength = Math.round((usedSpace / totalSpace) * progressBarLength);
- var bar = "[" + Array(filledLength + 1).join("█") + Array(progressBarLength - filledLength + 1).join("░") + "]";
- printl("使用情况: " + bar);
- return;
- }
- }
- }
- }
- }
- }
- } catch (e) {
- printl("通过Java API获取存储信息失败: " + e.message);
- }
-
- printl("存储信息: 无法获取");
- }
- // 获取内存信息
- function getMemoryInfo() {
- printl("\n========== 内存信息 ==========");
-
- if (typeof app !== 'undefined') {
- // 尝试使用app.getMemoryPercent()获取内存使用百分比
- if (typeof app.getMemoryPercent === 'function') {
- try {
- var memoryPercent = app.getMemoryPercent();
- if (memoryPercent !== null && memoryPercent !== undefined) {
- printl("内存使用率: " + memoryPercent + "%");
-
- // 根据内存使用率显示状态图标
- var memoryIcon = "🧠";
- if (memoryPercent > 80) memoryIcon = "⚠️";
- else if (memoryPercent > 60) memoryIcon = "MemoryWarning";
- printl("内存状态: " + memoryIcon + " " + memoryPercent + "%");
- return;
- }
- } catch (e) {
- printl("获取内存使用率失败: " + e.message);
- }
- }
-
- // 尝试使用app.getMemory()获取内存信息
- if (typeof app.getMemory === 'function') {
- try {
- var memory = app.getMemory();
- // getMemory返回的是JSON字符串,需要解析
- if (typeof memory === 'string' && memory.length > 0) {
- var memoryObj = JSON.parse(memory);
- if (memoryObj && memoryObj.used) {
- printl("当前应用内存占用: " + formatStorageSize(memoryObj.used));
- if (memoryObj.total) {
- printl("应用内存总量: " + formatStorageSize(memoryObj.total));
- }
- return;
- }
- } else if (typeof memory === 'number' && memory > 0) {
- // 如果直接返回数字
- printl("当前应用内存占用: " + formatStorageSize(memory));
- return;
- }
- } catch (e) {
- printl("解析内存信息失败: " + e.message);
- }
- }
- }
-
- printl("内存信息: 无法获取");
- }
- // 获取网络信息
- function getNetworkInfo() {
- printl("\n========== 网络信息 ==========");
-
- var hasNetworkInfo = false;
-
- // WiFi信息(更安全的检查方式)
- if (typeof wifi !== 'undefined') {
- if (typeof wifi.isWifiEnabled === 'function') {
- try {
- var isWifiEnabled = wifi.isWifiEnabled();
- printl("WiFi状态: " + (isWifiEnabled ? "已启用" : "已禁用"));
- hasNetworkInfo = true;
-
- if (isWifiEnabled && typeof wifi.getSSID === 'function') {
- var ssid = wifi.getSSID();
- if (ssid) {
- printl("WiFi名称: " + ssid);
- }
- }
- } catch (e) {
- printl("获取WiFi信息失败: " + e.message);
- }
- } else {
- // 检查wifi对象有哪些可用方法
- var wifiMethods = [];
- for (var prop in wifi) {
- if (typeof wifi[prop] === 'function') {
- wifiMethods.push(prop);
- }
- }
-
- if (wifiMethods.length > 0) {
- printl("WiFi可用方法: " + wifiMethods.join(', '));
- hasNetworkInfo = true;
- } else {
- printl("WiFi功能: 不可用");
- }
- }
- } else {
- printl("WiFi模块: 未找到");
- }
-
- // 尝试通过HTTP请求检查网络连接
- if (typeof okHttp !== 'undefined') {
- try {
- printl("正在测试网络连接...");
- var http = new okHttp();
- var response = http.get("http://www.baidu.com");
-
- if (response && response.length > 0) {
- printl("网络连接: 可访问百度");
- hasNetworkInfo = true;
- } else {
- printl("网络连接: 无法访问百度 (空响应)");
- }
- } catch (e) {
- printl("网络连接测试失败: " + e.message);
- // 即使测试失败,也标记为有网络信息
- hasNetworkInfo = true;
- }
- } else {
- printl("HTTP客户端: 未找到");
- }
-
- // 尝试获取设备网络信息
- if (typeof device !== 'undefined') {
- // 检查是否有获取IP的方法
- if (typeof device.getIP === 'function') {
- try {
- var ip = device.getIP();
- if (ip && ip !== "unknown") {
- printl("设备IP: " + ip);
- hasNetworkInfo = true;
- }
- } catch (e) {
- printl("获取设备IP失败: " + e.message);
- }
- } else {
- // 检查device对象有哪些网络相关方法
- var networkMethods = [];
- for (var prop in device) {
- if (typeof device[prop] === 'function' && (prop.indexOf('Network') !== -1 || prop.indexOf('IP') !== -1)) {
- networkMethods.push(prop);
- }
- }
-
- if (networkMethods.length > 0) {
- printl("设备网络相关方法: " + networkMethods.join(', '));
- hasNetworkInfo = true;
- }
- }
- }
-
- if (!hasNetworkInfo) {
- printl("网络信息: 无法获取");
- }
- }
- // 获取当前运行的应用信息
- function getRunningAppInfo() {
- printl("\n========== 应用信息 ==========");
-
- if (typeof app !== 'undefined') {
- var packageName = "未知";
-
- // 尝试多种方式获取包名
- if (typeof app.getTopPackName === 'function') {
- try {
- packageName = app.getTopPackName();
- } catch (e) {
- printl("通过getTopPackName获取包名失败: " + e.message);
- }
- }
-
- if ((packageName === "未知" || !packageName) && typeof app.getCurrentPackage === 'function') {
- try {
- packageName = app.getCurrentPackage();
- } catch (e) {
- printl("通过getCurrentPackage获取包名失败: " + e.message);
- }
- }
-
- printl("当前应用包名: " + (packageName || "未知"));
-
- if (packageName && packageName !== "未知" && typeof app.getAppName === 'function') {
- try {
- var appName = app.getAppName(packageName);
- if (appName) {
- printl("当前应用名称: " + appName);
- }
- } catch (e) {
- printl("获取应用名称失败: " + e.message);
- }
- }
- return;
- }
-
- printl("应用信息: app对象不可用");
- }
- // 生成设备信息报告
- function generateDeviceInfoReport() {
- printl("==============================================");
- printl(" AIWROK 设备信息报告");
- printl("==============================================");
- printl("报告生成时间: " + new Date().toLocaleString());
- printl("");
-
- // 获取各类信息
- getDeviceInfo();
- getScreenInfo();
- getBatteryInfo();
- getStorageInfo();
- getMemoryInfo();
- getNetworkInfo();
- getRunningAppInfo();
-
- printl("\n==============================================");
- printl(" 报告结束");
- printl("==============================================");
- }
- // 主函数
- function main() {
- printl("AIWROK实用设备信息示例开始执行...");
- generateDeviceInfoReport();
- printl("\n设备信息获取完成。");
- }
- // 执行主函数
- main();
复制代码
| |  | |  |
|
untoAIWROK创建和放大日志窗口并展示动态内容nextnocontent
|