Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//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" );  
        //      Log.i("Battery: ", "status:  " + status);
        //      Log.i("Battery: ", "health: " + health);
        //      Log.i("Battery: ", "present: " + present);
        //      Log.i("Battery: ", "level: " + level);
        //      Log.i("Battery: ", "scale: " + scale);
        //      Log.i("Battery: ", "plugged: " + plugged);
        //      Log.i("Battery: ", "voltage: " + voltage);
        //      Log.i("Battery: ", "temperature: " + temperature);
        //      Log.i("Battery: ", "technology: " + technology);
        return level / (float) scale;
    }
}