onLaunch: function () {
var internalMemSize = {};
var internalMemSizeGB = 0;
var internalMemSizeMB = 0;
var usedMemSizeGB = 0;
var usedMemSizeMB = 0;
if (plus.os.name == "Android") {
var environment = plus.android.importClass("android.os.Environment");
var statFs = plus.android.importClass("android.os.StatFs");
var files = plus.android.importClass("java.io.File");
var Files = environment.getDataDirectory();
var StatFs = new statFs(Files.getPath());
var blockSize = parseFloat(StatFs.getBlockSize());
var blockCount = parseFloat(StatFs.getBlockCount());
var availableBlocks = parseFloat(StatFs.getAvailableBlocks());
internalMemSize = blockSize blockCount;
var availableMemSize = blockSize availableBlocks;
var usedMemSize = internalMemSize - availableMemSize;
} else if (plus.os.name == "iOS") {
var BundleClass = plus.ios.importClass("NSBundle");
var BundleObj = BundleClass.mainBundle();
var filenamagerobj = plus.ios.newObject("NSFileManager");
var FileAttr = plus.ios.invoke(filenamagerobj, "attributesOfFileSystemForPath:error:", BundleObj.bundlePath(), null);
var totalCapacity = plus.ios.invoke(FileAttr, "objectForKey:", "NSFileSystemSize");
var availableCapacity = plus.ios.invoke(FileAttr, "objectForKey:", "NSFileSystemFreeSize");
var NSFileSystemFormatter = plus.ios.newObject("NSNumberFormatter");
internalMemSize = plus.ios.invoke(NSFileSystemFormatter, "stringFromNumber:", totalCapacity);
var availableMemSize = plus.ios.invoke(NSFileSystemFormatter, "stringFromNumber:", availableCapacity);
var usedMemSize = totalCapacity - availableCapacity;
}
if (internalMemSize) {
internalMemSizeGB = (internalMemSize / (1024 * 1024 * 1024)).toFixed(2);
internalMemSizeMB = (internalMemSize / (1024 * 1024)).toFixed(2);
usedMemSizeGB = (usedMemSize / (1024 * 1024 * 1024)).toFixed(2);
usedMemSizeMB = (usedMemSize / (1024 * 1024)).toFixed(2);
}
console.log('Total Internal Memory Size: ', internalMemSizeGB, 'GB (', internalMemSizeMB, 'MB)');
console.log('Used Internal Memory Size: ', usedMemSizeGB, 'GB (', usedMemSizeMB, 'MB)');
},在App.vue中
5 个回复
星桦呀
同问,大佬有解决方法了吗
DCloud_Android_DQQ
暂无官方api,建议使用插件实现
未设置昵称
/**
*/
export default function() {
var internalMemSize = {};
if (plus.os.name == "Android") {
var environment = plus.android.importClass("android.os.Environment");
var statFs = plus.android.importClass("android.os.StatFs");
var files = plus.android.importClass("java.io.File");
var Files = environment.getDataDirectory();
var StatFs = new statFs(Files.getPath());
var blockSize = parseFloat(StatFs.getBlockSize());
var blockCount = parseFloat(StatFs.getBlockCount());
internalMemSize = blockSize * blockCount;
} else if (plus.os.name == "iOS") {
var BundleClass = plus.ios.importClass("NSBundle");
var BundleObj = BundleClass.mainBundle();
var filenamagerobj = plus.ios.newObject("NSFileManager");
var FileAttr = plus.ios.invoke(filenamagerobj, "attributesOfFileSystemForPath:error:", BundleObj.bundlePath(),null);
var surplus = plus.ios.invoke(FileAttr, "objectForKey:", "NSFileSystemFreeSize");
var NSFileSystemFreeSize = plus.ios.newObject("NSNumberFormatter");
internalMemSize = plus.ios.invoke(NSFileSystemFreeSize, "stringFromNumber:", surplus);
}
return internalMemSize
}
迷茫的七酱
老哥 返回的这个数字是什么单位。kb?
2023-02-24 12:35
未设置昵称
回复 迷茫的七酱: 对
2023-03-14 20:04
371467676
回复 未设置昵称: 这个是只获取到了全部储存空间大小吧
2023-04-11 14:10
FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866
获取当前应用、可用、总的运行内存和储存空间(ios):https://ext.dcloud.net.cn/plugin?id=11027
s***@163.com
onLaunch: function () {
var internalMemSize = {};
var internalMemSizeGB = 0;
var internalMemSizeMB = 0;
var usedMemSizeGB = 0;
var usedMemSizeMB = 0;
if (plus.os.name == "Android") {
var environment = plus.android.importClass("android.os.Environment");
var statFs = plus.android.importClass("android.os.StatFs");
var files = plus.android.importClass("java.io.File");
var Files = environment.getDataDirectory();
var StatFs = new statFs(Files.getPath());
var blockSize = parseFloat(StatFs.getBlockSize());
var blockCount = parseFloat(StatFs.getBlockCount());
var availableBlocks = parseFloat(StatFs.getAvailableBlocks());
internalMemSize = blockSize blockCount;
var availableMemSize = blockSize availableBlocks;
var usedMemSize = internalMemSize - availableMemSize;
},在App.vue中