Java tutorial
//package com.java2s; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; public class Main { public static float getCurrentBattery(Context context) { Intent batteryInfoIntent = context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED)); int status = batteryInfoIntent.getIntExtra("status", 0); int health = batteryInfoIntent.getIntExtra("health", 1); boolean present = batteryInfoIntent.getBooleanExtra("present", false); int level = batteryInfoIntent.getIntExtra("level", 0); int scale = batteryInfoIntent.getIntExtra("scale", 0); int plugged = batteryInfoIntent.getIntExtra("plugged", 0); int voltage = batteryInfoIntent.getIntExtra("voltage", 0); int temperature = batteryInfoIntent.getIntExtra("temperature", 0); String technology = batteryInfoIntent.getStringExtra("technology"); return level / (float) scale; } }