Ir al contenido


Foto

Espacio usado y/o disponible en almacenamiento interno y SD. FMX, Android

FMX SD Card Android Java2Pas Uso de Disco android.os.StatFs android.os.Environment Battery Carga de Batería

  • Por favor identifícate para responder
3 respuestas en este tema

#1 erickahr

erickahr

    Newbie

  • Miembros
  • Pip
  • 7 mensajes

Escrito 06 diciembre 2016 - 05:39

Saludos, compañeros.

 

En esta entrada, quiero compartirles una pequeña práctica que realicé en Delphi XE7, en la cual obtengo información sobre los dispositivos de almacenamiento en un dispositivo Android.

 

Estuve buscando por algún tiempo en la red y no encontraba como realizar esta tarea, logré hacer la práctica en Android Studio, pero ahora la requería es Delphi. Desconozco si hay alguna forma más práctica y menos rebuscada de obtener estos datos, pero igual subo mi ejemplo, esperando que sea de utilidad para alguien.

 

Primero que nada, me encontré una utilería bastante interesante llamada Java2Pas, misma que me facilitó el trabajo al generar la interfaz para Firemonkey, las dos interfaces que necesité son Archivo adjunto  android.os.Environment.pas   6,53KB   7 descargas y Archivo adjunto  android.os.StatFs.pas   2,88KB   6 descargas (Estos que adjunto, son los archivos originales).

 

Por mi cuenta, modifiqué los PAS de las interfaces añadiendo las funciones que me permiten obtener:

  • Espacio usado de almacenamiento interno.
  • Espacio libre de almacenamiento interno.
  • Tamaño del disco almacenamiento interno*.
  • Espacio usado del dispositivo de almacenamiento predeterminado (Debería ser la SDCard, pero depende de la configuración del dispositivo).
  • Espacio libre del dispositivo de almacenamiento predeterminado (Debería ser la SDCard, pero depende de la configuración del dispositivo).
  • Tamaño del dispositivo de almacenamiento predeterminado (Debería ser la SDCard, pero depende de la configuración del dispositivo)*.

*Cabe mencionar que los tamaños de dispositivo los obtiene después del espacio que reserva Android para el sistema, así pues, un dispositivo de 16 GB podría mostrar un tamaño de 10 GB ya que el sistema utiliza 6 aproximadamente.

 

Quedaron así:

 

android.os.StatFs.pas


delphi
  1. unit android.os.StatFs;
  2.  
  3. interface
  4.  
  5. uses
  6. SysUtils,
  7. android.os.Environment,
  8. AndroidAPI.Helpers,
  9. AndroidAPI.JNIBridge,
  10. Androidapi.JNI.JavaTypes;
  11.  
  12. type
  13. TByteStringFormat = (bsfDefault, bsfBytes, bsfKB, bsfMB, bsfGB, bsfTB);
  14.  
  15. JStatFs = interface;
  16.  
  17. JStatFsClass = interface(JObjectClass)
  18. ['{DE76BDF6-C6A3-44F2-B699-2798F2BA4E88}']
  19. function getAvailableBlocks: Integer; deprecated; cdecl; // ()I A: $1
  20. function getAvailableBlocksLong: Int64; cdecl; // ()J A: $1
  21. function getAvailableBytes: Int64; cdecl; // ()J A: $1
  22. function getBlockCount: Integer; deprecated; cdecl; // ()I A: $1
  23. function getBlockCountLong: Int64; cdecl; // ()J A: $1
  24. function getBlockSize: Integer; deprecated; cdecl; // ()I A: $1
  25. function getBlockSizeLong: Int64; cdecl; // ()J A: $1
  26. function getFreeBlocks: Integer; deprecated; cdecl; // ()I A: $1
  27. function getFreeBlocksLong: Int64; cdecl; // ()J A: $1
  28. function getFreeBytes: Int64; cdecl; // ()J A: $1
  29. function getTotalBytes: Int64; cdecl; // ()J A: $1
  30. function init(path: JString): JStatFs; cdecl; // (Ljava/lang/String;)V A: $1
  31. procedure restat(path: JString); cdecl; // (Ljava/lang/String;)V A: $1
  32. end;
  33.  
  34. [JavaSignature('android/os/StatFs')]
  35. JStatFs = interface(JObject)
  36. ['{9CF05AFA-FD0A-4AE1-BF6A-86D06CD77216}']
  37. function getAvailableBlocks: Integer; deprecated; cdecl; // ()I A: $1
  38. function getAvailableBlocksLong: Int64; cdecl; // ()J A: $1
  39. function getAvailableBytes: Int64; cdecl; // ()J A: $1
  40. function getBlockCount: Integer; deprecated; cdecl; // ()I A: $1
  41. function getBlockCountLong: Int64; cdecl; // ()J A: $1
  42. function getBlockSize: Integer; deprecated; cdecl; // ()I A: $1
  43. function getBlockSizeLong: Int64; cdecl; // ()J A: $1
  44. function getFreeBlocks: Integer; deprecated; cdecl; // ()I A: $1
  45. function getFreeBlocksLong: Int64; cdecl; // ()J A: $1
  46. function getFreeBytes: Int64; cdecl; // ()J A: $1
  47. function getTotalBytes: Int64; cdecl; // ()J A: $1
  48. procedure restat(path: JString); cdecl; // (Ljava/lang/String;)V A: $1
  49. end;
  50.  
  51. TJStatFs = class(TJavaGenericImport<JStatFsClass, JStatFs>)
  52. end;
  53.  
  54. function GetBytesDPredeFree: Int64;
  55.  
  56. function GetDPredeFree(Format: TByteStringFormat = bsfDefault): string;
  57.  
  58. function GetBytesDPredeUsed: Int64;
  59.  
  60. function GetDPredeUsed(Format: TByteStringFormat = bsfDefault): string;
  61.  
  62. function GetBytesDPredeTotal: Int64;
  63.  
  64. function GetDPredeTotal(Format: TByteStringFormat = bsfDefault): string;
  65.  
  66. function GetBytesInStoraFree: Int64;
  67.  
  68. function GetInStoraFree(Format: TByteStringFormat = bsfDefault): string;
  69.  
  70. function GetBytesInStoraUsed: Int64;
  71.  
  72. function GetInStoraUsed(Format: TByteStringFormat = bsfDefault): string;
  73.  
  74. function GetBytesInStoraTotal: Int64;
  75.  
  76. function GetInStoraTotal(Format: TByteStringFormat = bsfDefault): string;
  77.  
  78. const
  79. KB = 1024;
  80. MB = KB * KB;
  81. GB = KB * MB;
  82. TB = Int64(KB) * GB;
  83.  
  84. implementation
  85.  
  86. function FormatByteString(Bytes: UInt64; Format: TByteStringFormat): string;
  87. begin
  88. if Format = bsfDefault then begin
  89. if Bytes < KB then begin
  90. Format := bsfBytes;
  91. end
  92. else if Bytes < MB then begin
  93. Format := bsfKB;
  94. end
  95. else if Bytes < GB then begin
  96. Format := bsfMB;
  97. end
  98. else if Bytes < TB then begin
  99. Format := bsfGB;
  100. end
  101. else begin
  102. Format := bsfTB;
  103. end;
  104. end;
  105.  
  106. case Format of
  107. bsfBytes:
  108. Result := SysUtils.Format('%d bytes', [Bytes]);
  109. bsfKB:
  110. Result := SysUtils.Format('%.2n KB', [Bytes / KB]);
  111. bsfMB:
  112. Result := SysUtils.Format('%.2n MB', [Bytes / MB]);
  113. bsfGB:
  114. Result := SysUtils.Format('%.2n GB', [Bytes / GB]);
  115. bsfTB:
  116. Result := SysUtils.Format('%.2n TB', [Bytes / TB]);
  117. end;
  118. end;
  119.  
  120. {Disco predeterminado / SD Card}
  121. function GetBytesDPredeFree: Int64;
  122. var
  123. Stat: JStatFs;
  124. begin
  125. Stat := TJStatFs.JavaClass.init(StringToJString(GetSDCardPath));
  126. Result := Stat.getAvailableBlocksLong * Stat.getBlockSizeLong;
  127. end;
  128.  
  129. function GetDPredeFree(Format: TByteStringFormat = bsfDefault): string;
  130. var
  131. Stat: JStatFs;
  132. begin
  133. Stat := TJStatFs.JavaClass.init(StringToJString(GetSDCardPath));
  134. Result := FormatByteString(Stat.getAvailableBlocksLong * Stat.getBlockSizeLong, Format);
  135. end;
  136.  
  137. function GetBytesDPredeUsed: Int64;
  138. var
  139. Stat: JStatFs;
  140. begin
  141. Stat := TJStatFs.JavaClass.init(StringToJString(GetSDCardPath));
  142. Result := (stat.getBlockCountLong - stat.getAvailableBlocksLong) * stat.getBlockSizeLong;
  143. end;
  144.  
  145. function GetDPredeUsed(Format: TByteStringFormat = bsfDefault): string;
  146. var
  147. Stat: JStatFs;
  148. begin
  149. Stat := TJStatFs.JavaClass.init(StringToJString(GetSDCardPath));
  150. Result := FormatByteString((stat.getBlockCountLong - stat.getAvailableBlocksLong)
  151. * stat.getBlockSizeLong, Format);
  152. end;
  153.  
  154. function GetBytesDPredeTotal: Int64;
  155. var
  156. Stat: JStatFs;
  157. begin
  158. Stat := TJStatFs.JavaClass.init(StringToJString(GetSDCardPath));
  159. Result := stat.getBlockCountLong * stat.getBlockSizeLong;
  160. end;
  161.  
  162. function GetDPredeTotal(Format: TByteStringFormat = bsfDefault): string;
  163. var
  164. Stat: JStatFs;
  165. begin
  166. Stat := TJStatFs.JavaClass.init(StringToJString(GetSDCardPath));
  167. Result := FormatByteString(stat.getBlockCountLong * stat.getBlockSizeLong, Format);
  168. end;
  169.  
  170. { Almacenamiento interno }
  171. function GetBytesInStoraFree: Int64;
  172. var
  173. Stat: JStatFs;
  174. begin
  175. Stat := TJStatFs.JavaClass.init(StringToJString(GetPhoneStoragePath));
  176. Result := Stat.getAvailableBlocksLong * Stat.getBlockSizeLong;
  177. end;
  178.  
  179. function GetInStoraFree(Format: TByteStringFormat = bsfDefault): string;
  180. var
  181. Stat: JStatFs;
  182. begin
  183. Stat := TJStatFs.JavaClass.init(StringToJString(GetPhoneStoragePath));
  184. Result := FormatByteString(Stat.getAvailableBlocksLong * Stat.getBlockSizeLong, Format);
  185. end;
  186.  
  187. function GetBytesInStoraUsed: Int64;
  188. var
  189. Stat: JStatFs;
  190. begin
  191. Stat := TJStatFs.JavaClass.init(StringToJString(GetPhoneStoragePath));
  192. Result := (stat.getBlockCountLong - stat.getAvailableBlocksLong) * stat.getBlockSizeLong;
  193. end;
  194.  
  195. function GetInStoraUsed(Format: TByteStringFormat = bsfDefault): string;
  196. var
  197. Stat: JStatFs;
  198. begin
  199. Stat := TJStatFs.JavaClass.init(StringToJString(GetPhoneStoragePath));
  200. Result := FormatByteString((stat.getBlockCountLong - stat.getAvailableBlocksLong)
  201. * stat.getBlockSizeLong, Format);
  202. end;
  203.  
  204. function GetBytesInStoraTotal: Int64;
  205. var
  206. Stat: JStatFs;
  207. begin
  208. Stat := TJStatFs.JavaClass.init(StringToJString(GetPhoneStoragePath));
  209. Result := stat.getBlockCountLong * stat.getBlockSizeLong;
  210. end;
  211.  
  212. function GetInStoraTotal(Format: TByteStringFormat = bsfDefault): string;
  213. var
  214. Stat: JStatFs;
  215. begin
  216. Stat := TJStatFs.JavaClass.init(StringToJString(GetPhoneStoragePath));
  217. Result := FormatByteString(stat.getBlockCountLong * stat.getBlockSizeLong, Format);
  218. end;
  219.  
  220.  
  221. end.

android.os.Environment.pas


delphi
  1. //
  2. // Generated by JavaToPas v1.5 20150831 - 132355
  3. ////////////////////////////////////////////////////////////////////////////////
  4. unit android.os.Environment;
  5.  
  6. interface
  7.  
  8. uses
  9. Androidapi.Helpers,
  10. AndroidAPI.JNIBridge,
  11. Androidapi.JNI.JavaTypes;
  12.  
  13. type
  14. sdCardState = (sdCardWritable, sdCardReadOnly, sdCardNotAvailable);
  15.  
  16. JEnvironment = interface;
  17.  
  18. JEnvironmentClass = interface(JObjectClass)
  19. ['{2185A416-0AE4-4FD9-AF1F-29622A58D6AD}']
  20. function _GetDIRECTORY_ALARMS: JString; cdecl; // A: $9
  21. function _GetDIRECTORY_DCIM: JString; cdecl; // A: $9
  22. function _GetDIRECTORY_DOCUMENTS: JString; cdecl; // A: $9
  23. function _GetDIRECTORY_DOWNLOADS: JString; cdecl; // A: $9
  24. function _GetDIRECTORY_MOVIES: JString; cdecl; // A: $9
  25. function _GetDIRECTORY_MUSIC: JString; cdecl; // A: $9
  26. function _GetDIRECTORY_NOTIFICATIONS: JString; cdecl; // A: $9
  27. function _GetDIRECTORY_PICTURES: JString; cdecl; // A: $9
  28. function _GetDIRECTORY_PODCASTS: JString; cdecl; // A: $9
  29. function _GetDIRECTORY_RINGTONES: JString; cdecl; // A: $9
  30. function _GetMEDIA_BAD_REMOVAL: JString; cdecl; // A: $19
  31. function _GetMEDIA_CHECKING: JString; cdecl; // A: $19
  32. function _GetMEDIA_EJECTING: JString; cdecl; // A: $19
  33. function _GetMEDIA_MOUNTED: JString; cdecl; // A: $19
  34. function _GetMEDIA_MOUNTED_READ_ONLY: JString; cdecl; // A: $19
  35. function _GetMEDIA_NOFS: JString; cdecl; // A: $19
  36. function _GetMEDIA_REMOVED: JString; cdecl; // A: $19
  37. function _GetMEDIA_SHARED: JString; cdecl; // A: $19
  38. function _GetMEDIA_UNKNOWN: JString; cdecl; // A: $19
  39. function _GetMEDIA_UNMOUNTABLE: JString; cdecl; // A: $19
  40. function _GetMEDIA_UNMOUNTED: JString; cdecl; // A: $19
  41. function getDataDirectory: JFile; cdecl; // ()Ljava/io/File; A: $9
  42. function getDownloadCacheDirectory: JFile; cdecl; // ()Ljava/io/File; A: $9
  43. function getExternalStorageDirectory: JFile; cdecl; // ()Ljava/io/File; A: $9
  44. function getExternalStoragePublicDirectory(&type: JString): JFile; cdecl; // (Ljava/lang/String;)Ljava/io/File; A: $9
  45. function getExternalStorageState: JString; cdecl; overload; // ()Ljava/lang/String; A: $9
  46. function getExternalStorageState(path: JFile): JString; cdecl; overload; // (Ljava/io/File;)Ljava/lang/String; A: $9
  47. function getRootDirectory: JFile; cdecl; // ()Ljava/io/File; A: $9
  48. function getStorageState(path: JFile): JString; deprecated; cdecl; // (Ljava/io/File;)Ljava/lang/String; A: $9
  49. function init: JEnvironment; cdecl; // ()V A: $1
  50. function isExternalStorageEmulated: boolean; cdecl; overload; // ()Z A: $9
  51. function isExternalStorageEmulated(path: JFile): boolean; cdecl; overload;// (Ljava/io/File;)Z A: $9
  52. function isExternalStorageRemovable: boolean; cdecl; overload; // ()Z A: $9
  53. function isExternalStorageRemovable(path: JFile): boolean; cdecl; overload;// (Ljava/io/File;)Z A: $9
  54. property DIRECTORY_ALARMS: JString read _GetDIRECTORY_ALARMS; // Ljava/lang/String; A: $9
  55. property DIRECTORY_DCIM: JString read _GetDIRECTORY_DCIM; // Ljava/lang/String; A: $9
  56. property DIRECTORY_DOCUMENTS: JString read _GetDIRECTORY_DOCUMENTS; // Ljava/lang/String; A: $9
  57. property DIRECTORY_DOWNLOADS: JString read _GetDIRECTORY_DOWNLOADS; // Ljava/lang/String; A: $9
  58. property DIRECTORY_MOVIES: JString read _GetDIRECTORY_MOVIES; // Ljava/lang/String; A: $9
  59. property DIRECTORY_MUSIC: JString read _GetDIRECTORY_MUSIC; // Ljava/lang/String; A: $9
  60. property DIRECTORY_NOTIFICATIONS: JString read _GetDIRECTORY_NOTIFICATIONS; // Ljava/lang/String; A: $9
  61. property DIRECTORY_PICTURES: JString read _GetDIRECTORY_PICTURES; // Ljava/lang/String; A: $9
  62. property DIRECTORY_PODCASTS: JString read _GetDIRECTORY_PODCASTS; // Ljava/lang/String; A: $9
  63. property DIRECTORY_RINGTONES: JString read _GetDIRECTORY_RINGTONES; // Ljava/lang/String; A: $9
  64. property MEDIA_BAD_REMOVAL: JString read _GetMEDIA_BAD_REMOVAL; // Ljava/lang/String; A: $19
  65. property MEDIA_CHECKING: JString read _GetMEDIA_CHECKING; // Ljava/lang/String; A: $19
  66. property MEDIA_EJECTING: JString read _GetMEDIA_EJECTING; // Ljava/lang/String; A: $19
  67. property MEDIA_MOUNTED: JString read _GetMEDIA_MOUNTED; // Ljava/lang/String; A: $19
  68. property MEDIA_MOUNTED_READ_ONLY: JString read _GetMEDIA_MOUNTED_READ_ONLY; // Ljava/lang/String; A: $19
  69. property MEDIA_NOFS: JString read _GetMEDIA_NOFS; // Ljava/lang/String; A: $19
  70. property MEDIA_REMOVED: JString read _GetMEDIA_REMOVED; // Ljava/lang/String; A: $19
  71. property MEDIA_SHARED: JString read _GetMEDIA_SHARED; // Ljava/lang/String; A: $19
  72. property MEDIA_UNKNOWN: JString read _GetMEDIA_UNKNOWN; // Ljava/lang/String; A: $19
  73. property MEDIA_UNMOUNTABLE: JString read _GetMEDIA_UNMOUNTABLE; // Ljava/lang/String; A: $19
  74. property MEDIA_UNMOUNTED: JString read _GetMEDIA_UNMOUNTED; // Ljava/lang/String; A: $19
  75. end;
  76.  
  77. [JavaSignature('android/os/Environment')]
  78. JEnvironment = interface(JObject)
  79. ['{8C3C74C2-670C-4DC6-AE2B-1CFCF52E8359}']
  80. end;
  81.  
  82. TJEnvironment = class(TJavaGenericImport<JEnvironmentClass, JEnvironment>)
  83. end;
  84.  
  85. function GetSDcardState: sdCardState;
  86.  
  87. function GetSDCardPath: string;
  88.  
  89. function GetPhoneStoragePath: string;
  90.  
  91. const
  92. TJEnvironmentMEDIA_BAD_REMOVAL = 'bad_removal';
  93. TJEnvironmentMEDIA_CHECKING = 'checking';
  94. TJEnvironmentMEDIA_EJECTING = 'ejecting';
  95. TJEnvironmentMEDIA_MOUNTED = 'mounted';
  96. TJEnvironmentMEDIA_MOUNTED_READ_ONLY = 'mounted_ro';
  97. TJEnvironmentMEDIA_NOFS = 'nofs';
  98. TJEnvironmentMEDIA_REMOVED = 'removed';
  99. TJEnvironmentMEDIA_SHARED = 'shared';
  100. TJEnvironmentMEDIA_UNKNOWN = 'unknown';
  101. TJEnvironmentMEDIA_UNMOUNTABLE = 'unmountable';
  102. TJEnvironmentMEDIA_UNMOUNTED = 'unmounted';
  103.  
  104. implementation
  105.  
  106. function GetSDcardState: sdCardState;
  107. var
  108. state: JString;
  109. begin
  110. state := TJEnvironment.JavaClass.getExternalStorageState;
  111. if state.equals(TJEnvironment.JavaClass.MEDIA_MOUNTED) then
  112. Result := sdCardWritable
  113. else if state.equals(TJEnvironment.JavaClass.MEDIA_MOUNTED_READ_ONLY) then
  114. Result := sdCardReadOnly
  115. else
  116. Result := sdCardNotAvailable;
  117. end;
  118.  
  119. function GetSDCardPath: string;
  120. var
  121. vFile: JFile;
  122. begin
  123. vFile := TJEnvironment.JavaClass.getExternalStorageDirectory;
  124. Result := JStringToString(vFile.getPath);
  125. end;
  126.  
  127. function GetPhoneStoragePath: string;
  128. var
  129. vFile: JFile;
  130. begin
  131. vFile := TJEnvironment.JavaClass.getDataDirectory;
  132. Result := JStringToString(vFile.getPath);
  133. end;
  134.  
  135. end.

Con estas dos unidades, serán capaces de obtener lo necesario para graficar el espacio en disco de su dispositivo Android u obtener el espacio disponible antes de descargar o almacenar un archivo que podría ser relativamente grande, entre otros usos que se les ocurran.

 

Andaba inspirado, así que en mi proyecto añadí un par de monerías a mi proyecto y quedó de esta manera:


delphi
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. System.SysUtils,
  7. System.Types,
  8. System.UITypes,
  9. System.Classes,
  10. System.Variants,
  11. FMX.Types,
  12. FMX.Controls,
  13. FMX.Forms,
  14. FMX.Graphics,
  15. FMX.Dialogs,
  16. FMX.StdCtrls,
  17. FMXTee.Series,
  18. FMXTee.Engine,
  19. FMXTee.Procs,
  20. FMXTee.Chart,
  21. FMX.Objects,
  22. FMX.Layouts,
  23. AndroidAPI.JNI.GraphicsContentViewText,
  24. AndroidAPI.JNI.JavaTypes,
  25. AndroidAPI.JNI.OS,
  26. FMX.platform.Android,
  27. Androidapi.JNIBridge,
  28. Androidapi.Jni,
  29. androidapi.JNI.Net,
  30. FMX.Helpers.Android,
  31. Androidapi.Helpers;
  32.  
  33. type
  34. TForm1 = class(TForm)
  35. btn1: TButton;
  36. lblBatt: TLabel;
  37. loBatt: TLayout;
  38. loPred: TLayout;
  39. lblPred: TLabel;
  40. loInt: TLayout;
  41. lblInt: TLabel;
  42. imgDiscoInt: TImage;
  43. rctnglIntOcupa: TRectangle;
  44. lblTitPred: TLabel;
  45. lblTitInt: TLabel;
  46. lblTitBatt: TLabel;
  47. loDiscInt: TLayout;
  48. loDiscPred: TLayout;
  49. rctnglPredOcupa: TRectangle;
  50. imgDiscoPred: TImage;
  51. vrtscrlbx1: TVertScrollBox;
  52. loimgBatt: TLayout;
  53. rctnglBatt: TRectangle;
  54. imgBatt: TImage;
  55. procedure btn1Click(Sender: TObject);
  56. private
  57. public
  58. end;
  59.  
  60. const
  61. BateryHealthStr: array[1..7] of string = ('unknown', 'Good', 'Overhead',
  62. 'Dead', 'Over voltage', 'unspecified failure', 'Cold');
  63. BateryPluggedStr: array[1..4] of string = ('AC plugged', 'USB plugged',
  64. 'unknown', 'Wireless plugged');
  65. BateryStatusStr: array[1..5] of string = ('Unknown', 'Charging', 'Discharging',
  66. 'Not charging', 'Full');
  67.  
  68. var
  69. Form1: TForm1;
  70.  
  71. implementation
  72.  
  73. uses
  74. android.os.Environment,
  75. android.os.StatFs;
  76.  
  77. {$R *.fmx}
  78.  
  79. procedure TForm1.btn1Click(Sender: TObject);
  80. var
  81. aColor: TAlphaColorRec;
  82. PercUso, PercLib: Double;
  83. rightMa: Integer;
  84.  
  85. filter: JIntentFilter;
  86. intentBatt: JIntent;
  87. iLevel, iScale: Integer;
  88. i: Integer;
  89. Str: JString;
  90. b: boolean;
  91. myContext: JContext;
  92. begin
  93. { BATERÍA }
  94. myContext := SharedActivityContext;
  95.  
  96. filter := TJIntentFilter.Create;
  97. filter.addAction(TJIntent.JavaClass.ACTION_BATTERY_CHANGED);
  98. intentBatt := myContext.registerReceiver(nil, filter);
  99.  
  100. i := intentBatt.getIntExtra(StringToJString('health'), -1);
  101. lblBatt.Text := 'Salut: ' + BateryHealthStr[i] + #13 + #10;
  102.  
  103. iLevel := intentBatt.getIntExtra(StringToJString('level'), -1);
  104. lblBatt.Text := lblBatt.Text + 'Level: ' + IntToStr(iLevel) + #13 + #10;
  105.  
  106. i := intentBatt.getIntExtra(StringToJString('plugged'), -1);
  107. lblBatt.Text := lblBatt.Text + 'Enchufado: ' + BateryPluggedStr[i] + #13 + #10;
  108.  
  109. b := intentBatt.getBooleanExtra(StringToJString('present'), False);
  110. lblBatt.Text := lblBatt.Text + 'Presente: ' + BoolToStr(b, True) + #13 + #10;
  111.  
  112. iScale := intentBatt.getIntExtra(StringToJString('scale'), -1);
  113. lblBatt.Text := lblBatt.Text + 'Escala: ' + IntToStr(iScale) + #13 + #10;
  114.  
  115. i := intentBatt.getIntExtra(StringToJString('status'), -1);
  116. lblBatt.Text := lblBatt.Text + 'Estado: ' + BateryStatusStr[i] + #13 + #10;
  117.  
  118. Str := intentBatt.getStringExtra(StringToJString('technology'));
  119. lblBatt.Text := lblBatt.Text + 'Tecnología: ' + JStringToString(Str) + #13 + #10;
  120.  
  121. i := intentBatt.getIntExtra(StringToJString('temperature'), -1);
  122. lblBatt.Text := lblBatt.Text + 'Temperatura: ' + FloatToStr(i / 10) + '°' + #13 + #10;
  123.  
  124. i := intentBatt.getIntExtra(StringToJString('voltage'), -1);
  125. lblBatt.Text := lblBatt.Text + 'Voltaje: ' + FloatToStr(i / 1000) + ' v.' + #13 + #10;
  126.  
  127. i := (100 * iLevel) div iScale;
  128. lblBatt.Text := lblBatt.Text + IntToStr(i) + '%';
  129.  
  130. aColor.R := Round(255 * (1 - (i / 100)));
  131. aColor.G := Round(255 * (i / 100));
  132. aColor.B := 0;
  133. aColor.A := 150;
  134. rctnglBatt.Fill.Color := TAlphaColor(aColor);
  135. rctnglBatt.Scale.X := (i / 100);
  136.  
  137. { ALMACENAMIENTO INTERNO }
  138. PercUso := GetBytesInStoraUsed / GetBytesInStoraTotal;
  139. PercLib := GetBytesInStoraFree / GetBytesInStoraTotal;
  140. aColor.R := Round(255 * PercUso);
  141. aColor.G := Round(255 * PercLib);
  142. aColor.B := 0;
  143. aColor.A := 150;
  144. rctnglIntOcupa.Fill.Color := TAlphaColor(aColor);
  145. rctnglIntOcupa.Scale.X := PercUso;
  146. lblInt.Text := GetPhoneStoragePath + #13 + #10 +
  147. GetInStoraFree + ' Libres' + #13 + #10 +
  148. GetInStoraUsed + ' Utilizados' + #13 + #10 +
  149. GetInStoraTotal + ' en disco' + #13 + #10 +
  150. IntToStr(Round(PercLib * 100)) + ' % libre';
  151.  
  152. { SD / DISP. ALMACENAMIENTO PREDETERMINADO }
  153. PercUso := GetBytesDPredeUsed / GetBytesDPredeTotal;
  154. PercLib := GetBytesDPredeFree / GetBytesDPredeTotal;
  155. aColor.R := Round(255 * PercUso);
  156. aColor.G := Round(255 * PercLib);
  157. aColor.B := 0;
  158. aColor.A := 150;
  159. rctnglPredOcupa.Fill.Color := TAlphaColor(aColor);
  160. rctnglPredOcupa.Scale.X := PercUso;
  161. lblPred.Text := GetSDCardPath + #13 + #10 +
  162. GetDPredeFree + ' Libres' + #13 + #10 +
  163. GetDPredeUsed + ' Utilizados' + #13 + #10 +
  164. GetDPredeTotal + ' en disco' + #13 + #10 +
  165. IntToStr(Round(PercLib * 100)) + ' % libre';
  166. end;
  167.  
  168. end.

Archivo adjunto  Screenshot_2016-12-06-16-28-41.png   76,4KB   1 descargas

 

Aqui, Archivo adjunto  testAlmacenamiento2.rar   139,55KB   18 descargas les dejo el proyecto completo.

 

Espero que sea de ayuda. Saludos.

 

 

 


  • 2

#2 Agustin Ortu

Agustin Ortu

    Advanced Member

  • Moderadores
  • PipPipPip
  • 831 mensajes
  • LocationArgentina

Escrito 06 diciembre 2016 - 11:12

Muy interesante, gracias por compartir


  • 1

#3 ELKurgan

ELKurgan

    Advanced Member

  • Miembro Platino
  • PipPipPip
  • 566 mensajes
  • LocationEspaña

Escrito 07 diciembre 2016 - 12:06

Gracias por compartir

 

Saludos


  • 1

#4 fredycc

fredycc

    Advanced Member

  • Moderadores
  • PipPipPip
  • 874 mensajes
  • LocationOaxaca, México

Escrito 07 diciembre 2016 - 08:45

Muy interesante la explicación y como lo has logrado.

 

Gracias por compartir.


  • 1





Etiquetado también con una o más de estas palabras: FMX, SD, Card, Android, Java2Pas, Uso de Disco, android.os.StatFs, android.os.Environment, Battery, Carga de Batería

IP.Board spam blocked by CleanTalk.