Battery Level
in
Android Processing
•
10 months ago
Hello, I was searching to receive battery usage from my phone to my processing app, now that's done ;-) accords
this tutorial
By
William J. Francis
for more options see
http://developer.android.com/reference/android/os/BatteryManager.html#EXTRA_TECHNOLOGY
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.os.Bundle;
- PFont font;
- int level=0;
- int charging;
- int voltage;
- int temp;
- String tech;
- void setup(){
- size(screenWidth,screenHeight,A3D);
- font = loadFont("CharterBT-Bold-48.vlw");
- textFont(font, screenWidth/15);
- textAlign(CORNER,CENTER);
- smooth();
- }
- void draw(){
- stroke(255);
- fill(255);
- rect(0,0,screenWidth,screenHeight);
- stroke(0);
- fill(0);
- text("Niveau : "+level+" %",screenWidth/4,screenHeight/6);
- text("Technologie : "+tech,screenWidth/4,2*screenHeight/6);
- text("Voltage : "+voltage,screenWidth/4,3*screenHeight/6);
- text("Temperature : "+temp,screenWidth/4,4*screenHeight/6);
- text("Branchée : "+charging,screenWidth/4,5*screenHeight/6);
- }
- private BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
- @Override
- public void onReceive(Context c, Intent i) {
- level = i.getIntExtra("level", 0);
- voltage = i.getIntExtra("voltage", 0);
- charging = i.getIntExtra("plugged", 0);
- tech = i.getStringExtra("technology");
- temp = i.getIntExtra("temperature",0);
- }
- };
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- registerReceiver(mBatInfoReceiver, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
- }