uses
Androidapi.Helpers,
Androidapi.JNIBridge,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.App;
var
MemoryInfo: JActivityManager_MemoryInfo;
TotalMb: Int64;
AvailMb: Int64;
begin
MemoryInfo:= TJActivityManager_MemoryInfo.JavaClass.init;
TJActivityManager.Wrap((TAndroidHelper.Context.getSystemService(
TJContext.JavaClass.ACTIVITY_SERVICE) as ILocalObject).GetObjectID)
.getMemoryInfo(MemoryInfo);
TotalMb:= MemoryInfo.totalMem; // use shr 20 after totalmem to get MegaBytes
AvailMb:= MemoryInfo.availMem; // use shr 20 after availMem to get MegaBytes
end;
在Delphi XE中运行:
uses
Androidapi.Helpers,
Androidapi.JNIBridge,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNI.App;
function AndroidGetMemory: Int64;
var
MemoryInfo: JActivityManager_MemoryInfo;
TotalMb: Int64;
AvailMb: Int64;
begin
MemoryInfo:= TJActivityManager_MemoryInfo.JavaClass.init;
TJActivityManager.Wrap((SharedActivityContext.getSystemService(
TJContext.JavaClass.ACTIVITY_SERVICE) as ILocalObject).GetObjectID)
.getMemoryInfo(MemoryInfo);
TotalMb:= MemoryInfo.totalMem; // use shr 20 after totalmem to get MegaBytes
AvailMb:= MemoryInfo.availMem; // use shr 20 after availMem to get MegaBytes
result := AvailMb;
end;
2条答案
按热度按时间sbdsn5lh1#
不确定它对Delphi Android应用程序有多大用处,但我在这里添加了Debug类的导入:
https://github.com/DelphiWorlds/KastriFree/blob/master/API/DW.Androidapi.JNI.Debug.pas
我假设这是要使用的相关类,因为Delphi生成本机可执行文件。以下是一些示例代码:
yrdbyhpb2#
在Delphi 10和11中工作:
在Delphi XE中运行: