• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting Battery Level

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone see whats wrong with this... It builds ok in WTK 2.5.1 but when loaded to i415 Motorola phone it says "Unhandled Exception"

Just trying to get the battery level from the phone. I KNOW this CAN be done on Motorola i415 but I just cannot seem to figure it out. 3 days is enough searching... please help!

Code:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.location.*;



public class HelloMidp extends MIDlet implements CommandListener {
private Command exitCommand;



Display display;
Form mainForm;

public HelloMidp () {
exitCommand = new Command("Exit", Command.EXIT, 1);
mainForm = new Form ("HelloMidp");
String batt = System.getProperty("batterylevel");
mainForm.append (batt);




}

protected void startApp()
{
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(this);
Display.getDisplay(this).setCurrent(mainForm);

}
/**
* This method is called to notify the MIDlet to enter a paused
* state. The MIDlet should use this opportunity to release
* shared resources.
*/
protected void pauseApp() {}

/**
* If the MIDlet was using resources, it should release
* them in this method.
*/
protected void destroyApp(boolean bool) {}

public void commandAction(Command cmd, Displayable disp)
{
if (cmd == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
}
}
[ June 16, 2007: Message edited by: Bear Bibeault ]
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
it seems that in

String batt = System.getProperty("batterylevel");
mainForm.append (batt);

you're appending a null to the form causing an unexpected exception.

Consider that (from Motorola developer support website):
http://developer.motorola.com/techresources/techsupport/

"...some of the system properties may return null as they may not be supported on early devices and some system propoerties require the MIDlet to be trusted otherwise return null..."

Regards,
Edoardo
 
s rolands
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Thanks for the reply. I think you are right about it being null, but , I DO know for a fact this phone can do this. (I have a application that does it on my phone). I think the problem is I forgot to Install the SDK for my phone. I have done that but it now needs to be added to my WTK somehow? Here's more info :

I have installed WTK, and it has been working but I realized I forgot to add the iden SDK for my motorola phone. I installed the SDK but I assume I need to link the files to WTK somehow?

What I am wanting to do :

----------------------------------



The SDK has a class file called StatusManager which can retrieve phone battery level...

From documentation:
"Field Detail
BATTERY_LEVEL

public static final int BATTERY_LEVEL

This is the value passed to the status manager to retrive the battery levels

The return value is in the range of [0 - 3] with 0 being no charge and 3 being a full battery.
BATTERY_LEVEL has a value of 0"

QUESTION IS: Where do I put the SDK files so WTK can use them? I am lost here.
I found the StatusManager.class file in :
C:\Program Files\Motorola\iDEN SDK for J2ME (MIDP 2_0)\lib\i730\com\mot\iden\device\

Can someone give me the detailed process of using the SDK with WTK... please??

Do I use the StatusManager.class file alone with my Midlet... or?
 
s rolands
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Such a simple question, but nobody can answer it? Guess I am just to much of a "newbie".
reply
    Bookmark Topic Watch Topic
  • New Topic