Android 根据内存大小显示MTP模式连接PC时的名称

发布于:2025-02-11 ⋅ 阅读:(54) ⋅ 点赞:(0)

项目有两种内存,要求根据连接电脑拷贝文件时的盘符名称根据内存大小显示不同名称。

frameworks/base/media/java/android/mtp/MtpDatabase.java

+//mh@
+import android.app.ActivityManager;
...
@@ -894,7 +896,19 @@ public class MtpDatabase implements AutoCloseable {
    private int getDeviceProperty(int property, long[] outIntValue, char[] outStringValue) {
        switch (property) {
             case MtpConstants.DEVICE_PROPERTY_SYNCHRONIZATION_PARTNER:
             case MtpConstants.DEVICE_PROPERTY_DEVICE_FRIENDLY_NAME:
                 // writable string properties kept in shared preferences
                 String value = mDeviceProperties.getString(Integer.toString(property), "");
+                //mh@start 两种内存,大于1G加pro
+                if(getTotalMem() > 1000l) {
+                    value = value + " PRO";
+                }
+                //mh@end
                 int length = value.length();
                 if (length > 255) {
                     length = 255;
          ...
+   //mh@start
+	private long getTotalMem() {
+		ActivityManager activityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
+       ActivityManager.MemoryInfo memInfo = new ActivityManager.MemoryInfo();
+       activityManager.getMemoryInfo(memInfo);
+       long totalMem = memInfo.totalMem / 1000000;
+       Log.d("mh.log", "MtpDatabase--getDeviceProperty--totalMem:" + totalMem);
+       return totalMem;
+	}
+	//mh@end

网站公告

今日签到

点亮在社区的每一天
去签到