Delphi XE5 android 获取电池电量

Posted on 2013-10-05 22:06 至今 阅读(...) 评论(...) 编辑 收藏
uses 

  AndroidAPI.JNI.GraphicsContentViewText, 
  AndroidAPI.JNI.JavaTypes, 
  AndroidAPI.JNI.OS; 


  



function BatteryPercent(const aContext: JContext): Integer; 
var 
  filter: JIntentFilter; 
  battery: JIntent; 
  level, scale: Integer; 

begin 

  filter := TJIntentFilter.Create; 
  filter.addAction(TJIntent.JavaClass.ACTION_BATTERY_CHANGED); 
  battery := aContext.registerReceiver(NIL, filter); 
  level := battery.getIntExtra(StringToJString('level'), -1); 
  scale := battery.getIntExtra(StringToJString('scale'), -1); 
  result := (100 * level) div scale; 



end; 
获取电池电量代码

 

posts - 34, comments - 79, trackbacks - 0, articles - 5

Copyright © 至今