Android Open Source - Torch Battery






From Project

Back to project page Torch.

License

The source code is released under:

GNU General Public License

If you think the Android project Torch listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.aktarer.torch.features;
//  www  .  ja va 2 s  .co  m
import org.json.JSONObject;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;

import com.aktarer.torch.ServerThread;

public class Battery extends Base {
  public Battery(Context c, ServerThread t) {
    super(c, t);
    
    run();
  }

  public void run() {
    thread.setJSONOutput();
    
    context.registerReceiver(new BroadcastReceiver() {
      @Override
      public void onReceive(Context context, Intent intent) {
        if (intent != null) {
          int level = intent.getIntExtra("level", -1);

          JSONObject response = new JSONObject();

          try {
            response.put("level", level);
            response.put("temperature", intent.getIntExtra(
                BatteryManager.EXTRA_TEMPERATURE, 0));
            response.put("volatege", intent.getIntExtra(
                BatteryManager.EXTRA_VOLTAGE, 0));
            response.put("status", intent.getIntExtra(
                BatteryManager.EXTRA_STATUS, 0));
            response.put("pluggedIn", intent.getIntExtra(
                BatteryManager.EXTRA_PLUGGED, 0));

            context.unregisterReceiver(this);
          } catch (Exception e) {
          }

          try {
            thread.send(response.toString());
          } catch (Exception e) {
          }
        }
      }
    }, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
  }
}




Java Source Code List

com.aktarer.torch.BackgroundServiceStarter.java
com.aktarer.torch.BackgroundService.java
com.aktarer.torch.Main.java
com.aktarer.torch.ServerThread.java
com.aktarer.torch.Server.java
com.aktarer.torch.features.Base.java
com.aktarer.torch.features.Battery.java
com.aktarer.torch.features.Camcorder.java
com.aktarer.torch.features.Info.java
com.aktarer.torch.features.Listen.java
com.aktarer.torch.features.SnapshotTaker.java
com.aktarer.torch.features.Snapshot.java
com.aktarer.torch.util.SystemUiHiderBase.java
com.aktarer.torch.util.SystemUiHiderHoneycomb.java
com.aktarer.torch.util.SystemUiHider.java