|
|
|
Android อ่าน Battery Percentage ของเครื่องมือถือ มาโชว์ได้ยังไงครับ |
|
|
|
|
|
|
|
Code (Android-Java)
private Handler handler = new Handler;
private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, Intent intent) {
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 100);
Log.i(TAG, "level: " + level + "; scale: " + scale);
int percent = (level*100)/scale;
final String text = String.valueOf(percent) + "%";
handler.post( new Runnable() {
public void run() {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}
});
}
};
|
|
|
|
|
Date :
2013-07-23 06:31:37 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|