What is error in this extenson code?

someone please help me ! it is showing me error.

package mohin.patel.batterylvl;

import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import android.os.BatteryManager;



@DesignerComponent(
  version = 1,
  description = "This extension is used to measure battery level",
  category = ComponentCategory.EXTENSION,
  nonVisible = true,
  iconName = "")

@SimpleObject(external = true)
public final class batterylvl extends AndroidNonvisibleComponent {

  
  public batterylvl(ComponentContainer container) {
    super(container.$form());
  }
@SimpleFunction(description = "Returns Battery level")
public int batteryLevel()
{
	BatteryManager bm = (BatteryManager)getSystemService(BATTERY_SERVICE);
	int batLevel= bm.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
	return batLevel;
}
	
}

Maybe you could tell us what the error is?

cannot find symbol
[javac] BatteryManager bm = (BatteryManager)getSystemService(BATTERY_SERVICE);
[javac] ^
[javac] symbol: variable BATTERY_SERVICE
[javac] location: class batterylvl
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 error
[javac] 4 warnings

what about using the battery manager extension?
https://puravidaapps.com/battery.php
Taifun

1 Like