import android.content.Intent; import android.content.IntentFilter; import android.os.BatteryManager; static int androidGetBattery() { Intent batteryIntent = androidContext().registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int level = batteryIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); int scale = batteryIntent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); // Error checking that probably isn't needed but I added just in case. if(level == -1 || scale == -1) { return -1; } return (int) (((float)level / (float)scale) * 100.0f); }
Began life as a copy of #1004076
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1004077 |
Snippet name: | androidGetBattery |
Eternal ID of this version: | #1004077/1 |
Text MD5: | 22b1d3c494a235c9850d0fe8790b0714 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-08-06 11:52:59 |
Source code size: | 601 bytes / 16 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 535 / 541 |
Referenced in: | [show references] |