|
@ -1,5 +1,6 @@ |
|
|
package com.ouxuan.oxface; |
|
|
package com.ouxuan.oxface; |
|
|
|
|
|
|
|
|
|
|
|
import android.app.ActivityManager; |
|
|
import android.content.Context; |
|
|
import android.content.Context; |
|
|
import android.content.Intent; |
|
|
import android.content.Intent; |
|
|
import android.content.pm.PackageManager; |
|
|
import android.content.pm.PackageManager; |
|
@ -142,6 +143,7 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi |
|
|
|
|
|
|
|
|
// 底部按钮 |
|
|
// 底部按钮 |
|
|
private Button btnOpenDoor; |
|
|
private Button btnOpenDoor; |
|
|
|
|
|
private Button btnMemoryInfo; // 新增的内存信息按钮 |
|
|
// private Button btnScanQR; |
|
|
// private Button btnScanQR; |
|
|
// private Button btnSettings; |
|
|
// private Button btnSettings; |
|
|
|
|
|
|
|
@ -281,12 +283,16 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi |
|
|
|
|
|
|
|
|
// 初始化底部按钮 |
|
|
// 初始化底部按钮 |
|
|
btnOpenDoor = findViewById(R.id.button_open_door); |
|
|
btnOpenDoor = findViewById(R.id.button_open_door); |
|
|
|
|
|
btnMemoryInfo = findViewById(R.id.button_memory_info); // 初始化内存信息按钮 |
|
|
// btnScanQR = findViewById(R.id.button_scan_qr); |
|
|
// btnScanQR = findViewById(R.id.button_scan_qr); |
|
|
// btnSettings = findViewById(R.id.button_settings); |
|
|
// btnSettings = findViewById(R.id.button_settings); |
|
|
|
|
|
|
|
|
if (btnOpenDoor != null) { |
|
|
if (btnOpenDoor != null) { |
|
|
btnOpenDoor.setOnClickListener(this); |
|
|
btnOpenDoor.setOnClickListener(this); |
|
|
} |
|
|
} |
|
|
|
|
|
if (btnMemoryInfo != null) { // 设置内存信息按钮点击事件 |
|
|
|
|
|
btnMemoryInfo.setOnClickListener(this); |
|
|
|
|
|
} |
|
|
// if (btnScanQR != null) { |
|
|
// if (btnScanQR != null) { |
|
|
// btnScanQR.setOnClickListener(this); |
|
|
// btnScanQR.setOnClickListener(this); |
|
|
// } |
|
|
// } |
|
@ -621,6 +627,9 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi |
|
|
} else if (id == R.id.button_open_door) { |
|
|
} else if (id == R.id.button_open_door) { |
|
|
// 开门按钮点击事件 |
|
|
// 开门按钮点击事件 |
|
|
handleOpenDoorClick(); |
|
|
handleOpenDoorClick(); |
|
|
|
|
|
} else if (id == R.id.button_memory_info) { |
|
|
|
|
|
// 内存信息按钮点击事件 |
|
|
|
|
|
displayMemoryInfo(); |
|
|
} |
|
|
} |
|
|
// else if (id == R.id.button_scan_qr) { |
|
|
// else if (id == R.id.button_scan_qr) { |
|
|
// // 扫码按钮点击事件 |
|
|
// // 扫码按钮点击事件 |
|
@ -1371,4 +1380,61 @@ public class OXFaceOnlineActivity extends BaseActivity implements View.OnClickLi |
|
|
} |
|
|
} |
|
|
}, 2000); |
|
|
}, 2000); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 查询并显示当前应用的内存信息 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void displayMemoryInfo() { |
|
|
|
|
|
Runtime runtime = Runtime.getRuntime(); |
|
|
|
|
|
long maxMemory = runtime.maxMemory() / (1024 * 1024); // MB |
|
|
|
|
|
long totalMemory = runtime.totalMemory() / (1024 * 1024); // MB |
|
|
|
|
|
long freeMemory = runtime.freeMemory() / (1024 * 1024); // MB |
|
|
|
|
|
long usedMemory = totalMemory - freeMemory; // MB |
|
|
|
|
|
|
|
|
|
|
|
// 获取系统内存信息(需要API 16及以上) |
|
|
|
|
|
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); |
|
|
|
|
|
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo(); |
|
|
|
|
|
activityManager.getMemoryInfo(memoryInfo); |
|
|
|
|
|
|
|
|
|
|
|
long totalMem = memoryInfo.totalMem / (1024 * 1024); // MB |
|
|
|
|
|
long availMem = memoryInfo.availMem / (1024 * 1024); // MB |
|
|
|
|
|
long threshold = memoryInfo.threshold / (1024 * 1024); // MB |
|
|
|
|
|
boolean isLowMemory = memoryInfo.lowMemory; |
|
|
|
|
|
|
|
|
|
|
|
// 构建内存信息字符串 |
|
|
|
|
|
StringBuilder memoryInfoStr = new StringBuilder(); |
|
|
|
|
|
memoryInfoStr.append("应用内存信息:\n"); |
|
|
|
|
|
memoryInfoStr.append("最大可用内存: ").append(maxMemory).append(" MB\n"); |
|
|
|
|
|
memoryInfoStr.append("已分配内存: ").append(totalMemory).append(" MB\n"); |
|
|
|
|
|
memoryInfoStr.append("已使用内存: ").append(usedMemory).append(" MB\n"); |
|
|
|
|
|
memoryInfoStr.append("空闲内存: ").append(freeMemory).append(" MB\n\n"); |
|
|
|
|
|
|
|
|
|
|
|
memoryInfoStr.append("系统内存信息:\n"); |
|
|
|
|
|
memoryInfoStr.append("总内存: ").append(totalMem).append(" MB\n"); |
|
|
|
|
|
memoryInfoStr.append("可用内存: ").append(availMem).append(" MB\n"); |
|
|
|
|
|
memoryInfoStr.append("内存阈值: ").append(threshold).append(" MB\n"); |
|
|
|
|
|
memoryInfoStr.append("低内存状态: ").append(isLowMemory ? "是" : "否"); |
|
|
|
|
|
|
|
|
|
|
|
// 显示内存信息(可以通过Toast或者对话框显示) |
|
|
|
|
|
Toast.makeText(this, memoryInfoStr.toString(), Toast.LENGTH_LONG).show(); |
|
|
|
|
|
|
|
|
|
|
|
// 同时输出到日志 |
|
|
|
|
|
LogManager.logInfo(TAG, "内存信息:\n" + memoryInfoStr.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 获取当前应用内存使用情况的简要信息 |
|
|
|
|
|
* @return 内存使用情况字符串 |
|
|
|
|
|
*/ |
|
|
|
|
|
private String getMemoryUsageSummary() { |
|
|
|
|
|
Runtime runtime = Runtime.getRuntime(); |
|
|
|
|
|
long maxMemory = runtime.maxMemory() / (1024 * 1024); // MB |
|
|
|
|
|
long totalMemory = runtime.totalMemory() / (1024 * 1024); // MB |
|
|
|
|
|
long freeMemory = runtime.freeMemory() / (1024 * 1024); // MB |
|
|
|
|
|
long usedMemory = totalMemory - freeMemory; // MB |
|
|
|
|
|
float memoryUsageRatio = (float) usedMemory / maxMemory; |
|
|
|
|
|
|
|
|
|
|
|
return String.format("内存: %d/%d MB (%.1f%%)", |
|
|
|
|
|
usedMemory, maxMemory, memoryUsageRatio * 100); |
|
|
|
|
|
} |
|
|
} |
|
|
} |