Android获取设备信息

使用java:

 List<TableMessage> dataList=new ArrayList<TableMessage>();//获取设备信息Hashtable<String,String> ht= MyDeviceInfo.getDeviceAllInfo2(LoginActivity.this);for (Map.Entry<String, String> entry : ht.entrySet()) {String key = entry.getKey();String value = entry.getValue();Log.d("Hashtable", "Key: " + key + ", Value: " + value);dataList.add(new TableMessage(key,value));}// String cpuABI = Build.CPU_ABI; // CPU架构(如arm64、x86)//int cpuCount = Runtime.getRuntime().availableProcessors(); // 逻辑核心数
//        String info = "架构:" + cpuABI + "+
//        核心数:" + cpuCount;// dataList.add(new TableMessage("核心数:",cpuCount+""));DialogTableDeviceInfo dialogTableDeviceInfo=new DialogTableDeviceInfo();dialogTableDeviceInfo.show(LoginActivity.this,"设备信息",dataList);

显示xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TextViewandroid:id="@+id/TextViewTitleSucces"android:layout_width="match_parent"android:layout_height="wrap_content"android:text=""android:textAlignment="center"android:textColor="@color/btnsetting"android:textSize="16sp" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:layout_marginTop="5dp"android:orientation="horizontal"><ScrollViewandroid:layout_width="fill_parent"android:layout_height="match_parent"><HorizontalScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="horizontal"><!--  此处省略的组件的配置  --><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><LinearLayoutandroid:id="@+id/LinearLayout1"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal"><TextViewandroid:id="@+id/TextViewId"android:layout_width="30dp"android:layout_height="wrap_content"android:background="@drawable/border_background"android:text="@string/txt_dialog_id"android:textAlignment="center" /><TextViewandroid:id="@+id/TextViewName"android:layout_width="140dp"android:layout_height="wrap_content"android:background="@drawable/border_background"android:text="@string/txt_login_menu_about_name"android:textAlignment="center" /><TextViewandroid:id="@+id/TextViewQuantity"android:layout_width="300dp"android:layout_height="wrap_content"android:background="@drawable/border_background"android:text="@string/txt_login_menu_about_size"android:textAlignment="center" /></LinearLayout><androidx.recyclerview.widget.RecyclerViewandroid:id="@+id/recyclerView"android:layout_width="match_parent"android:layout_height="match_parent"android:clipToPadding="false"android:padding="0dp"android:scrollbars="horizontal|vertical" /></LinearLayout></RelativeLayout></HorizontalScrollView></ScrollView></LinearLayout>
<!--    <ListView-->
<!--        android:id="@+id/ListView_table"-->
<!--        android:layout_width="match_parent"-->
<!--        android:layout_height="wrap_content"-->
<!--        android:layout_weight="1"--><!--        android:scrollbars="horizontal|vertical">--><!--    </ListView>--><!--    <ListView-->
<!--        android:id="@+id/ListView_table_fail"-->
<!--        android:layout_width="match_parent"-->
<!--        android:layout_height="wrap_content"-->
<!--        android:layout_weight="1"--><!--        android:scrollbars="horizontal|vertical" />--></LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="wrap_content"android:textAlignment="center"tools:ignore="MissingDefaultResource"><TextViewandroid:id="@+id/TextViewId"android:layout_width="30dp"android:layout_height="wrap_content"android:background="@drawable/border_background"android:text="@string/txt_dialog_id"android:textAlignment="center" /><TextViewandroid:id="@+id/TextViewName"android:layout_width="140dp"android:layout_height="wrap_content"android:background="@drawable/border_background"android:paddingRight="5dp"android:text=""android:textAlignment="textEnd" /><TextViewandroid:id="@+id/TextViewQuantity"android:layout_width="400dp"android:layout_height="wrap_content"android:background="@drawable/border_background"android:text=""android:textAlignment="viewStart" /></LinearLayout>

设备信息java代码:

package com.demo.util;import static android.content.Context.ACTIVITY_SERVICE;
import static android.util.Log.ERROR;
import static com.demo.util.FileUtilsPi.externalMemoryAvailable;import android.app.ActivityManager;
import android.content.Context;
import android.icu.text.DecimalFormat;
import android.os.Build;
import android.os.Environment;
import android.os.StatFs;
import android.telephony.TelephonyManager;
import android.util.Log;import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Hashtable;
import java.util.Locale;
public class MyDeviceInfo {//内存(RAM)信息获取public void getMemoryInfo() {String str1 = "/proc/meminfo";String str2="";try {FileReader fr = new FileReader(str1);BufferedReader localBufferedReader = new BufferedReader(fr, 8192);while ((str2 = localBufferedReader.readLine()) != null) {Log.d("TAG", "---" + str2);}} catch (IOException e) {}}/*** 获取可用手机内存(RAM)* @return*/public static long getAvailMemory(Context context) {ActivityManager am = (ActivityManager)context.getSystemService(ACTIVITY_SERVICE);ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();am.getMemoryInfo(mi);return mi.availMem;}/*** 获取手机内部空间大小* @return*/public static long getTotalInternalStorgeSize() {File path = Environment.getDataDirectory();StatFs mStatFs = new StatFs(path.getPath());long blockSize = mStatFs.getBlockSize();long totalBlocks = mStatFs.getBlockCount();return totalBlocks * blockSize;}/*** 获取手机内部可用空间大小* @return*/public static long getAvailableInternalStorgeSize() {File path = Environment.getDataDirectory();StatFs mStatFs = new StatFs(path.getPath());long blockSize = mStatFs.getBlockSize();long availableBlocks = mStatFs.getAvailableBlocks();return availableBlocks * blockSize;}/*** 获取手机外部空间大小* @return*/public static long getTotalExternalStorgeSize() {if (externalMemoryAvailable()) {File path = Environment.getExternalStorageDirectory();StatFs mStatFs = new StatFs(path.getPath());long blockSize = mStatFs.getBlockSize();long totalBlocks = mStatFs.getBlockCount();return totalBlocks * blockSize;} else {return ERROR;}}/*** 获取手机外部可用空间大小* @return*/public static long getAvailableExternalStorgeSize() {if (externalMemoryAvailable()) {File path = Environment.getExternalStorageDirectory();StatFs mStatFs = new StatFs(path.getPath());long blockSize = mStatFs.getBlockSize();long availableBlocks = mStatFs.getAvailableBlocks();return availableBlocks * blockSize;} else {return ERROR;}}/* 返回为字符串数组[0]为大小[1]为单位KB或MB */public static String formatSize(long size) {String suffix = "";float fSzie = 0;if (size >= 1024) {suffix = "KB";fSzie = size / 1024;if (fSzie >= 1024) {suffix = "MB";fSzie /= 1024;if (fSzie >= 1024) {suffix = "GB";fSzie /= 1024;}}}DecimalFormat formatter = new DecimalFormat("#0.00");// 字符显示格式/* 每3个数字用,分隔,如1,000 */formatter.setGroupingSize(3);StringBuilder resultBuffer = new StringBuilder(formatter.format(fSzie));if (suffix != null) {resultBuffer.append(suffix);}return resultBuffer.toString();}/* 返回为字符串数组[0]为大小[1]为单位KB或MB */public static String[] formatSizeArr(long size) {String[] arr = new String[2];String suffix = "";float fSzie = 0;arr[0]="";if (size >= 1024) {suffix = "KB";fSzie = size / 1024;if (fSzie >= 1024) {suffix = "MB";fSzie /= 1024;if (fSzie >= 1024) {suffix = "GB";fSzie /= 1024;}}}DecimalFormat formatter = new DecimalFormat("#0.00");// 字符显示格式/* 每3个数字用,分隔,如1,000 */formatter.setGroupingSize(3);StringBuilder resultBuffer = new StringBuilder(formatter.format(fSzie));if (suffix != null) {resultBuffer.append(suffix);}return arr;}/*** 获取设备宽度(px)**/public static int getDeviceWidth(Context context) {return context.getResources().getDisplayMetrics().widthPixels;}/*** 获取设备高度(px)*/public static int getDeviceHeight(Context context) {return context.getResources().getDisplayMetrics().heightPixels;}/*** 获取设备的唯一标识, 需要 “android.permission.READ_Phone_STATE”权限*/public static String getIMEI(Context context) {TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);String deviceId = tm.getDeviceId();if (deviceId == null) {return "UnKnown";} else {return deviceId;}}/*** 获取厂商名* **/public static String getDeviceManufacturer() {return android.os.Build.MANUFACTURER;}/*** 获取产品名* **/public static String getDeviceProduct() {return android.os.Build.PRODUCT;}/*** 获取手机品牌*/public static String getDeviceBrand() {return android.os.Build.BRAND;}/*** 获取手机型号*/public static String getDeviceModel() {return android.os.Build.MODEL;}/*** 获取手机主板名*/public static String getDeviceBoard() {return android.os.Build.BOARD;}/*** 设备名* **/public static String getDeviceDevice() {return android.os.Build.DEVICE;}/***** fingerprit 信息* **/public static String getDeviceFubgerprint() {return android.os.Build.FINGERPRINT;}/*** 硬件名** **/public static String getDeviceHardware() {return android.os.Build.HARDWARE;}/*** 主机** **/public static String getDeviceHost() {return android.os.Build.HOST;}/**** 显示ID* **/public static String getDeviceDisplay() {return android.os.Build.DISPLAY;}/*** ID** **/public static String getDeviceId() {return android.os.Build.ID;}/*** 获取手机用户名** **/public static String getDeviceUser() {return android.os.Build.USER;}/*** 获取手机 硬件序列号* **/public static String getDeviceSerial() {return android.os.Build.SERIAL;}/*** 获取手机Android 系统SDK** @return*/public static int getDeviceSDK() {return android.os.Build.VERSION.SDK_INT;}/*** 获取手机Android 版本** @return*/public static String getDeviceAndroidVersion() {return android.os.Build.VERSION.RELEASE;}/*** 获取当前手机系统语言。*/public static String getDeviceDefaultLanguage() {return Locale.getDefault().getLanguage();}/*** 获取当前系统上的语言列表(Locale列表)*/public static String getDeviceSupportLanguage() {Log.e("wangjie", "Local:" + Locale.GERMAN);Log.e("wangjie", "Local:" + Locale.ENGLISH);Log.e("wangjie", "Local:" + Locale.US);Log.e("wangjie", "Local:" + Locale.CHINESE);Log.e("wangjie", "Local:" + Locale.TAIWAN);Log.e("wangjie", "Local:" + Locale.FRANCE);Log.e("wangjie", "Local:" + Locale.FRENCH);Log.e("wangjie", "Local:" + Locale.GERMANY);Log.e("wangjie", "Local:" + Locale.ITALIAN);Log.e("wangjie", "Local:" + Locale.JAPAN);Log.e("wangjie", "Local:" + Locale.JAPANESE);StringBuilder sb=new StringBuilder();sb.append(Locale.CHINESE+"、"+Locale.US);return sb.toString();}public static String getDeviceAllInfo(Context context) {return "\n\n1. IMEI:\n\t\t" + getIMEI(context)+ "\n\n2. 设备宽度:\n\t\t" + getDeviceWidth(context)+ "\n\n3. 设备高度:\n\t\t" + getDeviceHeight(context)+ "\n\n4. 是否有内置SD卡:\n\t\t" + SDCardUtils.isSDCardMount()+ "\n\n5. RAM 信息:\n\t\t" + SDCardUtils.getRAMInfo(context)+ "\n\n6. 内部存储信息\n\t\t" + SDCardUtils.getStorageInfo(context, 0)+ "\n\n7. SD卡 信息:\n\t\t" + SDCardUtils.getStorageInfo(context, 1)//                + "\n\n8. 是否联网:\n\t\t" + Utils.isNetworkConnected(context)
//
//                + "\n\n9. 网络类型:\n\t\t" + Utils.GetNetworkType(context)+ "\n\n10. 系统默认语言:\n\t\t" + getDeviceDefaultLanguage()+ "\n\n11. 硬件序列号(设备名):\n\t\t" + android.os.Build.SERIAL+ "\n\n12. 手机型号:\n\t\t" + android.os.Build.MODEL+ "\n\n13. 生产厂商:\n\t\t" + android.os.Build.MANUFACTURER+ "\n\n14. 手机Fingerprint标识:\n\t\t" + android.os.Build.FINGERPRINT+ "\n\n15. Android 版本:\n\t\t" + android.os.Build.VERSION.RELEASE+ "\n\n16. Android SDK版本:\n\t\t" + android.os.Build.VERSION.SDK_INT+ "\n\n17. 安全patch 时间:\n\t\t" + android.os.Build.VERSION.SECURITY_PATCH//                + "\n\n18. 发布时间:\n\t\t" + Utils.Utc2Local(android.os.Build.TIME)+ "\n\n19. 版本类型:\n\t\t" + android.os.Build.TYPE+ "\n\n20. 用户名:\n\t\t" + android.os.Build.USER+ "\n\n21. 产品名:\n\t\t" + android.os.Build.PRODUCT+ "\n\n22. ID:\n\t\t" + android.os.Build.ID+ "\n\n23. 显示ID:\n\t\t" + android.os.Build.DISPLAY+ "\n\n24. 硬件名:\n\t\t" + android.os.Build.HARDWARE+ "\n\n25. 产品名:\n\t\t" + android.os.Build.DEVICE+ "\n\n26. Bootloader:\n\t\t" + android.os.Build.BOOTLOADER+ "\n\n27. 主板名:\n\t\t" + android.os.Build.BOARD+ "\n\n28. CodeName:\n\t\t" + android.os.Build.VERSION.CODENAME+ "\n\n29. 语言支持:\n\t\t" + getDeviceSupportLanguage();}public static String GetDeivceAllInfo2(){String DeviceMessage="产品 :" + android.os.Build.PRODUCT+"\nCPU_ABI :" + android.os.Build.CPU_ABI+ "\n 标签 :" + android.os.Build.TAGS+ "\n VERSION_CODES.BASE:" + android.os.Build.VERSION_CODES.BASE+ "\n 型号:" + android.os.Build.MODEL+"\n SDK : " + android.os.Build.VERSION.SDK+"\n Android 版本 : " + android.os.Build.VERSION.RELEASE+ "\n 驱动 : " + android.os.Build.DEVICE+"\n DISPLAY: " + android.os.Build.DISPLAY+"\n 品牌 : " + android.os.Build.BRAND+"\n 基板 : " + android.os.Build.BOARD+"\n 设备标识 : " + android.os.Build.FINGERPRINT+"\n 版本号 : " + android.os.Build.ID+ "\n 制造商 : " + android.os.Build.MANUFACTURER+"\n 用户 : " + android.os.Build.USER+"\n CPU_ABI2 : "+android.os.Build.CPU_ABI2+"\n 硬件 : "+ android.os.Build.HARDWARE+"\n 主机地址 :"+android.os.Build.HOST+"\n 未知信息 : "+android.os.Build.UNKNOWN+"\n  版本类型 : "+android.os.Build.TYPE+"\n  时间 : "+String.valueOf(android.os.Build.TIME)+"\n  Radio : "+android.os.Build.RADIO+"\n  序列号 : "+android.os.Build.SERIAL;return DeviceMessage;}public static  Hashtable<String,String> getDeviceAllInfo2(Context context) {Hashtable<String,String> ht=new Hashtable<String,String>();//  ht.put("IMEI:",getIMEI(context));ht.put("设备宽度:",getDeviceWidth(context)+"");ht.put("设备高度:",getDeviceHeight(context)+"");ht.put("RAM 信息:",SDCardUtils.getRAMInfo(context)+"");ht.put("内部存储信息:",SDCardUtils.getStorageInfo(context, 0)+"");ht.put("是否有内置SD卡:",SDCardUtils.isSDCardMount()+"");ht.put("SD卡信息:",SDCardUtils.getStorageInfo(context, 1)+"");ht.put("系统默认语言:",getDeviceDefaultLanguage()+"");ht.put("硬件序列号(设备名):", android.os.Build.SERIAL+"");ht.put("设备型号:",android.os.Build.MODEL+"");ht.put("生产厂商:",android.os.Build.MANUFACTURER+"");//  ht.put("手机Fingerprint标识:",android.os.Build.FINGERPRINT+"");ht.put("Android 版本:",android.os.Build.VERSION.RELEASE+"");ht.put("Android SDK版本:",android.os.Build.VERSION.SDK_INT+"");ht.put("安全patch 时间:",android.os.Build.VERSION.SECURITY_PATCH+"");ht.put("版本类型:",android.os.Build.TYPE+"");ht.put("用户名:",android.os.Build.USER+"");ht.put("ID:",android.os.Build.ID+"");ht.put("显示ID:",android.os.Build.DISPLAY+"");ht.put("硬件名:",android.os.Build.HARDWARE+"");ht.put("产品名:",android.os.Build.DEVICE+"");ht.put("Bootloader:",android.os.Build.BOOTLOADER+"");ht.put("主板名:",android.os.Build.BOARD+"");ht.put("主机:", Build.HOST+"");ht.put("CodeName:",android.os.Build.VERSION.CODENAME+"");ht.put("语言支持:",getDeviceSupportLanguage()+"");//支持卡槽数量(sdk_version>=23才可取值,否则为0slot_count//  ht.put(" 支持卡槽数量:",android.os.Build.+"");ht.put("CPU名字:", Build.CPU_ABI+"");ht.put("CPU_ABI2:", android.os.Build.CPU_ABI2+"");ht.put("CPU核心数:", Runtime.getRuntime().availableProcessors()+"");//        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
//        if (activityManager == null) {
//            throw new IllegalStateException("ActivityManager is not available");
//        }
//
//        // 创建MemoryInfo对象并填充数据
//        ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
//        activityManager.getMemoryInfo(memoryInfo);
//
//        // 提取总运行内存和可用运行内存
//        long totalMemory = memoryInfo.totalMem; // 总运行内存(含已用)
//        long availableMemory = memoryInfo.availMem; // 可用运行内存(不含已用)
// 转换为 MB(保留两位小数)
//        String totalMemoryMB = String.format("%.2f GB", totalMemory / (1024.0 * 1024*1024));
//        String availableMemoryMB = String.format("%.2f GB", availableMemory / (1024.0 * 1024*1024));
//        ht.put("运行内存:", "总运行内存/可用运行内存"+totalMemoryMB+"/"+availableMemoryMB+"");// ht.put(" 蓝牙mac地址:", android.os.Build+"");//        String message= "\n\n1. IMEI:\n\t\t" + getIMEI(context)
//
//                + "\n\n2. 设备宽度:\n\t\t" + getDeviceWidth(context)
//
//                + "\n\n3. 设备高度:\n\t\t" + getDeviceHeight(context)
//
//                + "\n\n4. 是否有内置SD卡:\n\t\t" + SDCardUtils.isSDCardMount()
//
//                + "\n\n5. RAM 信息:\n\t\t" + SDCardUtils.getRAMInfo(context)
//
//                + "\n\n6. 内部存储信息\n\t\t" + SDCardUtils.getStorageInfo(context, 0)
//
//                + "\n\n7. SD卡 信息:\n\t\t" + SDCardUtils.getStorageInfo(context, 1)
//+ "\n\n8. 是否联网:\n\t\t" + Utils.isNetworkConnected(context)+ "\n\n9. 网络类型:\n\t\t" + Utils.GetNetworkType(context)
//
//                + "\n\n10. 系统默认语言:\n\t\t" + getDeviceDefaultLanguage()
//
//                + "\n\n11. 硬件序列号(设备名):\n\t\t" + android.os.Build.SERIAL
//
//                + "\n\n12. 手机型号:\n\t\t" + android.os.Build.MODEL
//
//                + "\n\n13. 生产厂商:\n\t\t" + android.os.Build.MANUFACTURER
//
//                + "\n\n14. 手机Fingerprint标识:\n\t\t" + android.os.Build.FINGERPRINT
//
//                + "\n\n15. Android 版本:\n\t\t" + android.os.Build.VERSION.RELEASE
//
//                + "\n\n16. Android SDK版本:\n\t\t" + android.os.Build.VERSION.SDK_INT
//
//                + "\n\n17. 安全patch 时间:\n\t\t" + android.os.Build.VERSION.SECURITY_PATCH
//+ "\n\n18. 发布时间:\n\t\t" + Utils.Utc2Local(android.os.Build.TIME)
//
//                + "\n\n19. 版本类型:\n\t\t" + android.os.Build.TYPE
//
//                + "\n\n20. 用户名:\n\t\t" + android.os.Build.USER
//
//                + "\n\n21. 产品名:\n\t\t" + android.os.Build.PRODUCT
//
//                + "\n\n22. ID:\n\t\t" + android.os.Build.ID
//
//                + "\n\n23. 显示ID:\n\t\t" + android.os.Build.DISPLAY
//
//                + "\n\n24. 硬件名:\n\t\t" + android.os.Build.HARDWARE
//
//                + "\n\n25. 产品名:\n\t\t" + android.os.Build.DEVICE
//
//                + "\n\n26. Bootloader:\n\t\t" + android.os.Build.BOOTLOADER
//
//                + "\n\n27. 主板名:\n\t\t" + android.os.Build.BOARD
//
//                + "\n\n28. CodeName:\n\t\t" + android.os.Build.VERSION.CODENAME
//                + "\n\n29. 语言支持:\n\t\t" + getDeviceSupportLanguage();getCPUInfo();return ht;}public static String getCPUInfo() {StringBuilder cpuInfo = new StringBuilder();try {// 执行cat命令读取文件Process process = Runtime.getRuntime().exec("cat /proc/cpuinfo");BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));String line;while ((line = reader.readLine()) != null) {cpuInfo.append(line).append("");Log.d("MemoryInfo", "Available RAM: " + line);}reader.close();} catch (IOException e) {e.printStackTrace();return "获取失败";}return cpuInfo.toString();}public static  String getRAM(Context context){//        // 获取内存信息
//        ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
//        ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
//        activityManager.getMemoryInfo(memoryInfo);
//提取数据并转换单位
//        long totalMemory = memoryInfo.totalMem;
//        long availableMemory = memoryInfo.availMem;
//转换为 MB(保留两位小数)
//        String totalMemoryMB = String.format("%.2f MB", totalMemory / (1024.0 * 1024));
//        String availableMemoryMB = String.format("%.2f MB", availableMemory / (1024.0 * 1024));
//
//        Log.d("MemoryInfo", "Total RAM: " + totalMemoryMB);
//        Log.d("MemoryInfo", "Available RAM: " + availableMemoryMB);return "";}/*** 获取CPU总运行内存和可用运行内存(单位:字节)** @param context 应用上下文* @return 包含总运行内存和可用运行内存的数组,索引0为总内存,索引1为可用内存*/public static String[] getCpuAndAvailableMemory(Context context) {// 获取ActivityManager实例ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);if (activityManager == null) {throw new IllegalStateException("ActivityManager is not available");}// 创建MemoryInfo对象并填充数据ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();activityManager.getMemoryInfo(memoryInfo);// 提取总运行内存和可用运行内存long totalMemory = memoryInfo.totalMem; // 总运行内存(含已用)long availableMemory = memoryInfo.availMem; // 可用运行内存(不含已用)转换为 MB(保留两位小数)String totalMemoryMB = String.format("%.2f MB", totalMemory / (1024.0 * 1024));String availableMemoryMB = String.format("%.2f MB", availableMemory / (1024.0 * 1024));return new String[]{totalMemoryMB, availableMemoryMB};}
}
package com.uhf200.demo.util;import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;import com.uhf200.demo.R;
import com.uhf200.demo.ui.model.TableMessage;import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;public class DialogTableDeviceInfo {public static AlertDialog alertDialog3; //输入弹出框public static ListView dialog_ListView;public static DialogAdapter dialogAdapter;private static List<TableMessage> mArrCard;//返回失败的信息public static ListView dialog_ListView_fail;public static DialogFailAdapter dialogFailAdapter;private static List<TableMessage> mArrCard_fail;public  void show(Context context, String title_succes,List<TableMessage> dataList) {AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);alertBuilder.setTitle("设备信息");mArrCard=new ArrayList<TableMessage>();mArrCard_fail=new ArrayList<TableMessage>();mArrCard=dataList;// 引入自己设计的xml//成功的提示信息View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_table_device_info,null);TextView TextViewSucces= dialogView.findViewById(R.id.TextViewTitleSucces);LinearLayout LinearLayout1= dialogView.findViewById(R.id.LinearLayout1);LinearLayout LinearLayout2= dialogView.findViewById(R.id.LinearLayout2);//        dialog_ListView = (ListView) dialogView.findViewById(R.id.ListView_table);
//
//        dialogAdapter = new DialogAdapter(context, mArrCard);
//
//        dialog_ListView.setAdapter(dialogAdapter);
//
//        dialog_ListView.setVerticalScrollBarEnabled(true);//失败的信息//        dialog_ListView_fail = (ListView) dialogView.findViewById(R.id.ListView_table_fail);
//
//        dialogFailAdapter = new DialogFailAdapter(context, mArrCard_fail);
//
//        dialog_ListView_fail.setAdapter(dialogFailAdapter);
//
//        dialog_ListView_fail.setVerticalScrollBarEnabled(true);// TableLayout tableLayout = dialogView.findViewById(R.id.table_layout);TextViewSucces.setText(title_succes);//        dialogAdapter.notifyDataSetChanged();
//        dialogFailAdapter.notifyDataSetChanged();alertBuilder.setView(dialogView);alertBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int i) {alertDialog3.dismiss();}});//成功的信息RecyclerView recyclerView = dialogView.findViewById(R.id.recyclerView);// 设置垂直列表布局recyclerView.setLayoutManager(new LinearLayoutManager(context));// 准备测试数据List<TableMessage> userList = new ArrayList<>();
//        for (int i=0;i<100;i++){
//            userList.add(new TableMessage("张三"+i, "2"+i));
//        }
//
//        userList.add(new TableMessage("李四", "30"));
//        userList.add(new TableMessage("王五", "28"));// 添加更多数据...if(dataList.size()>0){userList=dataList;}else {TextViewSucces.setVisibility(View.GONE);recyclerView.setVisibility(View.GONE);LinearLayout1.setVisibility(View.GONE);LinearLayout2.setVisibility(View.GONE);}// 创建并设置 AdapterUserAdapter adapter = new UserAdapter(userList);recyclerView.setAdapter(adapter);//添加数据
//        for (int i = 0; i < dataList.size(); i++) {
//
//            TableMessage tableMessage=dataList.get(i);
//            addDataRow(context,tableLayout, i + 1,
//                    tableMessage.getName(),
//                    tableMessage.getQuantity());
//        }//        alertBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//            @Override
//            public void onClick(DialogInterface dialogInterface, int i) {
//
//                alertDialog3.dismiss();
//
//            }
//        });alertDialog3 = alertBuilder.create();alertDialog3.show();}public  void show(Context context, String title_succes,String title_fail,List<TableMessage> dataList,  List<TableMessage> dataList_fail,String errorMessage) {AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);alertBuilder.setTitle("设备信息");mArrCard=new ArrayList<TableMessage>();mArrCard_fail=new ArrayList<TableMessage>();mArrCard=dataList;mArrCard_fail=dataList_fail;// 引入自己设计的xml//成功的提示信息View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_table_device_info,null);TextView TextViewSucces= dialogView.findViewById(R.id.TextViewTitleSucces);LinearLayout LinearLayout1= dialogView.findViewById(R.id.LinearLayout1);LinearLayout LinearLayout2= dialogView.findViewById(R.id.LinearLayout2);//        dialog_ListView = (ListView) dialogView.findViewById(R.id.ListView_table);
//
//        dialogAdapter = new DialogAdapter(context, mArrCard);
//
//        dialog_ListView.setAdapter(dialogAdapter);
//
//        dialog_ListView.setVerticalScrollBarEnabled(true);//失败的信息//        dialog_ListView_fail = (ListView) dialogView.findViewById(R.id.ListView_table_fail);
//
//        dialogFailAdapter = new DialogFailAdapter(context, mArrCard_fail);
//
//        dialog_ListView_fail.setAdapter(dialogFailAdapter);
//
//        dialog_ListView_fail.setVerticalScrollBarEnabled(true);// TableLayout tableLayout = dialogView.findViewById(R.id.table_layout);TextViewSucces.setText(title_succes);//        dialogAdapter.notifyDataSetChanged();
//        dialogFailAdapter.notifyDataSetChanged();alertBuilder.setView(dialogView);alertBuilder.setPositiveButton("确定", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialogInterface, int i) {alertDialog3.dismiss();}});//成功的信息RecyclerView recyclerView = dialogView.findViewById(R.id.recyclerView);// 设置垂直列表布局recyclerView.setLayoutManager(new LinearLayoutManager(context));// 准备测试数据List<TableMessage> userList = new ArrayList<>();
//        for (int i=0;i<100;i++){
//            userList.add(new TableMessage("张三"+i, "2"+i));
//        }
//
//        userList.add(new TableMessage("李四", "30"));
//        userList.add(new TableMessage("王五", "28"));// 添加更多数据...if(dataList.size()>0){userList=dataList;}else {TextViewSucces.setVisibility(View.GONE);recyclerView.setVisibility(View.GONE);LinearLayout1.setVisibility(View.GONE);LinearLayout2.setVisibility(View.GONE);}// 创建并设置 AdapterUserAdapter adapter = new UserAdapter(userList);recyclerView.setAdapter(adapter);//添加数据
//        for (int i = 0; i < dataList.size(); i++) {
//
//            TableMessage tableMessage=dataList.get(i);
//            addDataRow(context,tableLayout, i + 1,
//                    tableMessage.getName(),
//                    tableMessage.getQuantity());
//        }//        alertBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//            @Override
//            public void onClick(DialogInterface dialogInterface, int i) {
//
//                alertDialog3.dismiss();
//
//            }
//        });alertDialog3 = alertBuilder.create();alertDialog3.show();}private static void addDataRow(Context context,TableLayout tableLayout,int index,String name,String quantity) {TableRow dataRow = new TableRow(tableLayout.getContext());dataRow.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,TableRow.LayoutParams.WRAP_CONTENT));// 序号列TextView tvIndex = createTextView(context,String.valueOf(index),Color.BLACK,Gravity.LEFT);dataRow.addView(tvIndex);// 名称列TextView tvName = createTextView(context,name,Color.BLACK,Gravity.START);dataRow.addView(tvName);// 数量列TextView tvQuantity = createTextView(context,quantity,Color.BLACK,Gravity.CENTER);dataRow.addView(tvQuantity);// 添加底部边框
//        View divider = new View(tableLayout.getContext());
//        divider.setLayoutParams(new TableRow.LayoutParams(
//                TableRow.LayoutParams.MATCH_PARENT,
//                2));
//        divider.setBackgroundColor(Color.LTGRAY);
//        dataRow.addView(divider);tableLayout.addView(dataRow);}private static TextView createTextView(Context context,String text,int textColor,int gravity) {TextView tv = new TextView(context);tv.setLayoutParams(new TableRow.LayoutParams(0,TableRow.LayoutParams.WRAP_CONTENT,1f));tv.setText(text);tv.setTextColor(textColor);tv.setGravity(gravity);tv.setPadding(16, 12, 16, 12);return tv;}public  class DialogAdapter extends BaseAdapter {private  Context context;private LayoutInflater inflater;public List<TableMessage> arraylist;public int i=1;//刷新数据public int optionindex;public DialogAdapter(Context context) {super();this.context = context;inflater = LayoutInflater.from(context);arraylist = new ArrayList<TableMessage>();}public DialogAdapter( Context context, List<TableMessage> arraylist) {super();inflater = LayoutInflater.from(context);this.context = context;this.arraylist = arraylist;}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn arraylist.size();}@Overridepublic Object getItem(int arg0) {// TODO Auto-generated method stubreturn arg0;}@Overridepublic long getItemId(int arg0) {// TODO Auto-generated method stubreturn arg0;}@Overridepublic View getView(final int position, View convertView, ViewGroup parent) {// TODO Auto-generated method stubViewDialog viewDialog=null;try {if (convertView == null) {viewDialog=new ViewDialog();convertView=inflater.inflate(R.layout.device_item_info, null);viewDialog.tvId = (TextView)convertView.findViewById(R.id.TextViewId);viewDialog.tv_Name= (TextView) convertView.findViewById(R.id.TextViewName);viewDialog.tv_Quantity= (TextView) convertView.findViewById(R.id.TextViewQuantity);}else {viewDialog = (ViewDialog)convertView.getTag();// resetViewHolder(viewDialog);}TableMessage tableMessage = arraylist.get(position);viewDialog.tvId.setText((position+1)+"");viewDialog.tv_Name.setText(tableMessage.getName());viewDialog.tv_Quantity.setText(tableMessage.getQuantity());return convertView;} catch (Exception e) {Log.d("debugAdd", "3测试添加数据有误" + e.toString());return convertView;// throw new RuntimeException(e);}/// return view;}protected void resetViewHolder(ViewDialog p_ViewHolder){p_ViewHolder.tvId.setText(null);p_ViewHolder.tv_Name.setText(null);p_ViewHolder.tv_Quantity.setText(null);}private class ViewDialog{private TextView tvId;private TextView tv_Name;private TextView tv_Quantity;}}public  class DialogFailAdapter extends BaseAdapter {private  Context context;private LayoutInflater inflater;public List<TableMessage> arraylist;public Hashtable<String,String> ht_AssetNames;public int i=1;//刷新数据public int optionindex;public DialogFailAdapter(Context context) {super();this.context = context;inflater = LayoutInflater.from(context);arraylist = new ArrayList<TableMessage>();ht_AssetNames=new Hashtable<String,String>();}public DialogFailAdapter( Context context, List<TableMessage> arraylist) {super();inflater = LayoutInflater.from(context);this.context = context;this.arraylist = arraylist;ht_AssetNames=new Hashtable<String,String>();}@Overridepublic int getCount() {// TODO Auto-generated method stubreturn arraylist.size();}@Overridepublic Object getItem(int arg0) {// TODO Auto-generated method stubreturn arg0;}@Overridepublic long getItemId(int arg0) {// TODO Auto-generated method stubreturn arg0;}@Overridepublic View getView(final int position, View view, ViewGroup parent) {// TODO Auto-generated method stubViewDialog3 viewDialog3=null;try {if (view == null) {viewDialog3=new ViewDialog3();view=inflater.inflate(R.layout.device_item_info, null);viewDialog3.tvId = (TextView)view.findViewById(R.id.TextViewId3);viewDialog3.tv_Name= (TextView) view.findViewById(R.id.TextViewName3);viewDialog3.tv_Quantity= (TextView) view.findViewById(R.id.TextViewQuantity3);}else {viewDialog3 = (ViewDialog3)view.getTag();// resetViewHolder3(viewDialog3);}TableMessage tableMessage = arraylist.get(position);viewDialog3.tvId.setText((position+1)+"");viewDialog3.tv_Name.setText(tableMessage.getName());viewDialog3.tv_Quantity.setText(tableMessage.getQuantity());return view;} catch (Exception e) {Log.d("debugAdd", "3测试添加数据有误" + e.toString());return view;// throw new RuntimeException(e);}/// return view;}protected void resetViewHolder3(ViewDialog3 p_ViewHolder){p_ViewHolder.tvId.setText(null);p_ViewHolder.tv_Name.setText(null);p_ViewHolder.tv_Quantity.setText(null);}private class ViewDialog3{private TextView tvId;private TextView tv_Name;private TextView tv_Quantity;}}public class UserAdapter extends RecyclerView.Adapter<UserAdapter.ViewHolder> {private List<TableMessage> userList;public UserAdapter(List<TableMessage> userList) {this.userList = userList;}@NonNull@Overridepublic ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.device_item_info, parent, false);return new ViewHolder(view);}@Overridepublic void onBindViewHolder(@NonNull ViewHolder holder, int position) {// 获取当前数据TableMessage tableMessage = userList.get(position);// 设置序号(position 从 0 开始,需 +1)holder.tvId.setText(String.valueOf(position + 1));// 设置姓名和年龄holder.tv_Name.setText(tableMessage.getName());holder.tv_Quantity.setText(tableMessage.getQuantity());}@Overridepublic int getItemCount() {return userList.size();}// ViewHolder 内部类public  class ViewHolder extends RecyclerView.ViewHolder {TextView tvId, tv_Name, tv_Quantity;public ViewHolder(@NonNull View itemView) {super(itemView);tvId = itemView.findViewById(R.id.TextViewId);tv_Name = itemView.findViewById(R.id.TextViewName);tv_Quantity = itemView.findViewById(R.id.TextViewQuantity);}}}public class UserFailAdapter extends RecyclerView.Adapter<UserFailAdapter.ViewHolder> {private List<TableMessage> userList;public UserFailAdapter(List<TableMessage> userList) {this.userList = userList;}@NonNull@Overridepublic ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.device_item_info, parent, false);return new ViewHolder(view);}@Overridepublic void onBindViewHolder(@NonNull ViewHolder holder, int position) {// 获取当前数据TableMessage tableMessage = userList.get(position);// 设置序号(position 从 0 开始,需 +1)holder.tvId.setText(String.valueOf(position + 1));// 设置姓名和年龄holder.tv_Name.setText(tableMessage.getName());holder.tv_Quantity.setText(tableMessage.getQuantity());}@Overridepublic int getItemCount() {return userList.size();}// ViewHolder 内部类public  class ViewHolder extends RecyclerView.ViewHolder {TextView tvId, tv_Name, tv_Quantity;public ViewHolder(@NonNull View itemView) {super(itemView);tvId = itemView.findViewById(R.id.TextViewId3);tv_Name = itemView.findViewById(R.id.TextViewName3);tv_Quantity = itemView.findViewById(R.id.TextViewQuantity3);}}}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.pswp.cn/web/82074.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WIN11使用vscode搭建c语言开发环境

安装 VS Code 下载地址: Visual Studio Code - Code Editing. Redefined 安装时勾选 "添加到 PATH"&#xff08;方便在终端中调用 code 命令 下载 MSYS2 官网&#xff1a;MSYS2 下载 msys2-x86_64-xxxx.exe&#xff08;64位版本&#xff09;并安装。 默认安装路径…

微信小程序带数组参数跳转页面,微信小程序跳转页面带数组参数

在微信小程序中&#xff0c;带数组参数跳转页面需要通过JSON序列化和URL编码处理&#xff0c;以下是具体实现方法 传递数组参数‌&#xff08;发送页面&#xff09; wx.navigateTo({url: /pages/targetPage?arr encodeURIComponent(JSON.stringify(yourArray)) });接收数组参…

Mac M1编译OpenCV获取libopencv_java490.dylib文件

Window OpenCV下载地址 https://opencv.org/releases/OpenCV源码下载 https://github.com/opencv/opencv/tree/4.9.0 https://github.com/opencv/opencv_contrib/tree/4.9.0OpenCV依赖 brew install libjpeg libpng libtiff cmake3 ant freetype构建open CV cmake -G Ninja…

前端面试准备-3

1.let、const、var的区别 ①&#xff1a;let和const为块级作用域&#xff0c;var为全局作用域 ②&#xff1a;let和var可以重新赋值定义&#xff0c;而const不可以 ③&#xff1a;var会提升到作用域顶部&#xff0c;但不会初始化&#xff1b;let和const也会提升到作用不顶部…

Java 中 Lock 接口详解:灵活强大的线程同步机制

在 Java 中&#xff0c;Lock 是一个接口&#xff0c;它提供了比 synchronized 关键字更灵活、更强大的线程同步机制。以下将详细介绍 Lock 接口及其实现类&#xff0c;以及它与 synchronized 相比的优点。 Lock 接口及其实现类介绍 Lock 接口 Lock 接口定义了一系列用于获取…

实验分享|基于sCMOS相机科学成像技术的耐高温航空涂层材料损伤检测实验

1实验背景 航空发动机外壳的耐高温涂层材料在长期高温、高压工况下易产生微小损伤与裂纹&#xff0c;可能导致严重安全隐患。传统光学检测手段受限于分辨率与灵敏度&#xff0c;难以捕捉微米级缺陷&#xff0c;且检测效率低下。 某高校航空材料实验室&#xff0c;采用科学相机…

python训练营day40

知识点回顾&#xff1a; 彩色和灰度图片测试和训练的规范写法&#xff1a;封装在函数中展平操作&#xff1a;除第一个维度batchsize外全部展平dropout操作&#xff1a;训练阶段随机丢弃神经元&#xff0c;测试阶段eval模式关闭dropout 作业&#xff1a;仔细学习下测试和训练代码…

Baklib企业CMS全流程管控与智能协作

企业CMS全流程管控方案解析 现代企业内容管理中&#xff0c;全流程管控的实现依赖于对生产、审核、发布及迭代环节的系统化整合。通过动态发布引擎与元数据智能标记技术&#xff0c;系统可自动匹配内容与目标场景&#xff0c;实现标准化模板驱动的快速部署。针对多分支机构的复…

Qt程序添加调试输出窗口:CONFIG += console

目录 1.背景 2.解决方案 3.原理详解 4.控制台窗口的行为 5.条件编译&#xff08;仅调试模式显示控制台&#xff09; 6.替代方案 7.总结 1.背景 在Qt程序开发中&#xff0c;开发者经常遇到这样的困扰&#xff1a; 开发机上程序运行正常 发布到其他机器后程序无法启动 …

《江西棒球资讯》棒球运动发展·棒球1号位

联赛体系结构 | League Structure MLB模式 MLB采用分层体系&#xff08;大联盟、小联盟&#xff09;&#xff0c;强调梯队建设和长期发展。 MLB operates a tiered system (Major League, Minor League) with a focus on talent pipelines and long-term development. 中国现…

Python爬虫实战:研究Tornado框架相关技术

1. 引言 1.1 研究背景与意义 网络爬虫作为一种自动获取互联网信息的程序,在信息检索、数据挖掘、舆情分析等领域有着广泛的应用。随着互联网数据量的爆炸式增长,对爬虫的性能和效率提出了更高的要求。传统的同步爬虫在处理大量 URL 时效率低下,而异步爬虫可以显著提高并发…

Vue-列表过滤排序

列表过滤 基础环境 数据 persons: [{ id: "001", name: "刘德华", age: 19 },{ id: "002", name: "马德华", age: 20 },{ id: "003", name: "李小龙", age: 21 },{ id: "004", name: "释小龙&q…

JDK21深度解密 Day 9:响应式编程模型重构

【JDK21深度解密 Day 9】响应式编程模型重构 引言&#xff1a;从Reactor到虚拟线程的范式转变 在JDK21中&#xff0c;虚拟线程的引入彻底改变了传统的异步编程模型。作为"JDK21深度解密"系列的第91天&#xff0c;我们将聚焦于响应式编程模型重构这一关键主题。通过…

UE5打包项目设置Project Settings(打包widows exe安装包)

UE5打包项目Project Settings Edit-Project Settings- Packaging-Ini Section Denylist-Advanced 1&#xff1a;打包 2&#xff1a;高级设置 3&#xff1a;勾选创建压缩包 4&#xff1a;添加要打包地图Map的数量 5&#xff1a;选择要打包的地图Maps 6&#xff1a;Project-Bui…

Fastapi 学习使用

Fastapi 学习使用 Fastapi 可以用来快速搭建 Web 应用来进行接口的搭建。 参考文章&#xff1a;https://blog.csdn.net/liudadaxuexi/article/details/141062582 参考文章&#xff1a;https://blog.csdn.net/jcgeneral/article/details/146505880 参考文章&#xff1a;http…

java helloWord java程序运行机制 用idea创建一个java项目 标识符 关键字 数据类型 字节

HelloWord public class Hello{public static void main(String[] args) {System.out.print("Hello,World!");} }java程序运行机制 用idea创建一个java项目 建立一个空项目 新建一个module 注释 标识符 关键字 标识符注意点 数据类型 public class Demo02 {public st…

随机响应噪声-极大似然估计

一、核心原因&#xff1a;噪声机制的数学可逆性 在随机响应机制&#xff08;Randomized Response&#xff09;中使用极大似然估计&#xff08;Maximum Likelihood Estimation, MLE&#xff09;是为了从扰动后的噪声数据中无偏地还原原始数据的统计特性。随机响应通过已知概率的…

SMT贴片机工艺优化与效率提升策略

内容概要 现代电子制造领域中&#xff0c;SMT贴片机作为核心生产设备&#xff0c;其工艺优化与效率提升直接影响企业竞争力。本文聚焦设备参数校准、吸嘴选型匹配、SPI检测技术三大技术模块&#xff0c;结合生产流程重构与设备维护周期优化两大管理维度&#xff0c;形成系统性…

AI提示工程(Prompt Engineering)高级技巧详解

AI提示工程(Prompt Engineering)高级技巧详解 文章目录 一、基础设计原则二、高级提示策略三、输出控制技术四、工程化实践五、专业框架应用提示工程是与大型语言模型(LLM)高效交互的关键技术,精心设计的提示可以显著提升模型输出的质量和相关性。以下是经过验证的详细提示工…

光电设计大赛智能车激光对抗方案分享:低成本高效备赛攻略

一、赛题核心难点与备赛痛点解析 全国大学生光电设计竞赛的 “智能车激光对抗” 赛题&#xff0c;要求参赛队伍设计具备激光对抗功能的智能小车&#xff0c;需实现光电避障、目标识别、轨迹规划及激光精准打击等核心功能。从历年参赛情况看&#xff0c;选手普遍面临三大挑战&a…