Jump to content
Sign in to follow this  
Al T

(solved) How do you "getMemoryInfo(MemoryInfo)" in Delphi XE8?

Recommended Posts

Here's the code that works in Delphi 11, but it wont work in XE8 because "[DCC Error] Unit1.pas(210): E2003 Undeclared identifier: 'TAndroidHelper'

 

 

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  System.Math,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  IdBaseComponent, IdThreadComponent, FMX.StdCtrls, FMX.Layouts,
  FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo, System.IOUtils,
  AndroidAPI.JNIBridge,
  Androidapi.JNI.JavaTypes,
  android.os.StatFs,
  Posix.Unistd, FMX.Memo.Types, Unit2, System.ImageList, FMX.ImgList,
  Androidapi.Log,
  Androidapi.JNI.App,
  Androidapi.JNI.GraphicsContentViewText,
  Androidapi.Helpers,
  credits, OptionsUnit;
  
{ MISC CODE IN BETWEEN }

function AndroidGetMemory: Int64;
var
  MemoryInfo: JActivityManager_MemoryInfo;
  AvailMb: Int64;
begin
  MemoryInfo:= TJActivityManager_MemoryInfo.JavaClass.init;
  TJActivityManager.Wrap((TAndroidHelper.Context.getSystemService(
    TJContext.JavaClass.ACTIVITY_SERVICE) as ILocalObject).GetObjectID)
    .getMemoryInfo(MemoryInfo);
  AvailMb := MemoryInfo.availMem;
  result := AvailMb;
end;

I found the problem in the code above and changed it to this:

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 shr 20;
  //AvailMb:= MemoryInfo.availMem shr 20; in MB
  AvailMb:= MemoryInfo.availMem;
  result := AvailMb;
end;

SharedActivityContext was deprecated in Delphi 11 and uses TAndroidHelper.Context

Edited by Al T

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×