×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    45

    JSR-179 API provider reset to stop GPS location activity

    Hi

    I have coded two location applications - one that uses getLocation() for synchronous calls to GPS - second that uses LocationListener for subscribing to periodic location updates.

    I want each application to stop the internal GPS module location activity after a set time, such as few minutes, to save battery life. I am using the Nokia Energy Profiler application to test the applications on Nokia E90.

    1) The first application works fine - after the getLocation has returned, I call provider.reset(), GPS module location activity stops and battery life is saved.

    2) The second application doesn't allow GPS module location activity to stop if there is already a GPS satellite fix, causing Nokia E90 battery life to drop to below 10 hours. It uses the framework TouristRoute JSR179API example from Forum Nokia. I stop the periodic listener updates and reset the provider by calling:

    provider.setLocationListener(null,-1,0,0);
    provider.reset();

    Then this application stops receiving GPS updates from the LocationListener, however with a existing GPS satellite fix the GPS location module continues consuming power until I exit the application (if there was no GPS satellite fix then the GPS power consumption stops after 30-45 seconds as expected and battery life is saved) Any suggestions how to stop the GPS location module activity without having to exit the application?

    Thanks
    Guy
    Last edited by nicholso; 2008-01-09 at 13:31. Reason: updating the information

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    45

    Re: JSR-179 API provider reset to stop GPS location activity

    This is a simplified version of the second application using the location listener method. I also tried calling the functions in reverse order with still the same problem that the GPS power consumption does not drop, e.g:
    provider.reset();
    provider.setLocationListener(null, -1, 0, 0);

    Code:
    /* Here is sample code which compiles and runs on emulator and E90
     * StopGPS() stops the location updates, but if the GPS module 
     * has a satellite fix, power consumption does not drop...
     */
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.location.*;
    import javax.microedition.io.*;
    import java.io.*; 
    
    public class MyMidlet extends MIDlet implements CommandListener, LocationListener { 
        
        Command Exit = new Command("Exit",Command.EXIT,0);
        Command StopGPS = new Command("Stop GPS", Command.ITEM, 0);
        Command StartGPS = new Command("Start GPS", Command.ITEM, 0);
        
        public Form f=new Form("LocationListener"); 
        
        public LocationProvider provider;
        public Location location;
        public QualifiedCoordinates qc;
    
        public void startApp() {
            // test whether location API is supported
             if (System.getProperty("microedition.location.version") == null) {
                destroyApp(true);
                notifyDestroyed();
            }  
                    
            f.addCommand(Exit);
            f.setCommandListener(this);
            Display.getDisplay(this).setCurrent(f);  
            StartGPS();   
        }
        
        public void pauseApp() { }
        
        public void destroyApp(boolean destroy) { }
        
        public void commandAction(Command c, Displayable s)  {
            if (c == Exit) {
                destroyApp(true);
                notifyDestroyed();
            }
            if (c == StartGPS) {
                StartGPS();
            }
            if (c == StopGPS) {
                StopGPS();
            }
        }
        
         public void StartGPS() {
            try {
                provider = LocationProvider.getInstance(null);
                provider.setLocationListener(this, -1, 0, 0);
    
                f.removeCommand(StartGPS);
                f.addCommand(StopGPS);
                f.deleteAll();
                f.append("Searching...");
            } catch ( SecurityException e ) {  // added catch 22/8/2008
                f.removeCommand(StopGPS);
                f.addCommand(StartGPS);
            }catch (Exception e ) {
                f.append("Exception in StartGPS()");            
            }
        }
         
         public void StopGPS() {
            try {
                provider.setLocationListener(null, -1, 0, 0); // here   
                provider.reset();  // here
    
                f.removeCommand(StopGPS);
                f.addCommand(StartGPS);
                f.deleteAll();
                f.append("Location listener stopped.");
            } catch (Exception e ) {
                f.append("Exception in StopGPS()");   
            }
        }
        
        public void locationUpdated(final LocationProvider prov, final Location loc) {
            new Thread() {
                public void run() {
                    if (loc != null && loc.isValid()) {
                        qc = loc.getQualifiedCoordinates();
                        
                        f.deleteAll();
                        
                        f.append("Latest update:\n");
                        f.append(" Lat: "+ qc.getLatitude() +"°\n");
                        f.append(" Lon: "+ qc.getLongitude() +"°\n");
                        
                      } else {
                        f.deleteAll();
                        f.append("Location null or invalid object:\n");
                    }
                }
            }.start();
        }
    
        public void providerStateChanged(LocationProvider prov, int newState) {
        }  
    }
    Last edited by nicholso; 2008-08-22 at 04:26.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    45

    Unhappy Re: JSR-179API provider reset to stop GPS location activity

    Further testing - this problem occurs with both Assisted-GPS enabled or disabled. My working assumption is that when the Nokia E90 GPS & JSR-179 implementation has a satellite fix, then the location provider GPS module won't power down and won't release references to my application with provider.reset() and setLocationListener(null,..) function calls until the application location listener object is destroyed which only happens for sure on application exit... This assumption then implies the E90 implementation of GPS and JSR-179 doesn't work as described in the JSR-179 API
    Last edited by nicholso; 2008-01-10 at 06:09.

  4. #4
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: JSR-179API provider reset to stop GPS location activity

    Hello nicholso,

    ..causing Nokia E90 battery life to drop to below 10 hours.

    what's the (approximate) value for battery life which you receive when you run the MyMIDlet app?

    Regards,
    r2j7
    Last edited by r2j7; 2008-01-11 at 13:46.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    45

    Re: JSR-179API provider reset to stop GPS location activity

    Hi!

    All these tests below are with a Nokia E90 (CE marked unit)

    with MyMidlet running and location updates being received ... after A-GPS has finished the cellular data call..., Nokia Energy Profiler indicates a battery life of 8 hours:-
    http://www.geocities.com/guy_nich/GPSShot01.png

    If there is no GPS satellite fix and StopGPS() is called, the battery life improves after thirty seconds as expected, and power consumption eventually drops to a low standby level:-
    http://www.geocities.com/guy_nich/GPSShot02.png

    But if there is GPS satellite fix and StopGPS() is called, power consumption stays around 0.5W and does not drop (eventually causing a battery life indication of under 12 hours). This condition is the error I have found - the GPS module does not power down for this case.
    http://www.geocities.com/guy_nich/GPSShot03.png

    If the MyMidlet is exited, then GPS module will power down whatever the satellite fix status.

    Thanks, Guy

    I also rewrote the application to see if the way how MyMidlet creates the location listener object could be the cause of this error (..this code creates a new object each time StartGPS() is called..), but still this error is observed
    Code:
    package utmMain;
    /*
     * UTMloclist.java
     * Created on 09 January 2008, 11:59
     * @author  nicholso
     * @version 0.2
     */
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.location.*;
    import javax.microedition.io.*;
      
    import java.io.*; 
    
    public class MyMidlet extends MIDlet implements CommandListener { // 0.2 removed LocationListener
        
        Command Exit = new Command("Exit",Command.EXIT,0);
        Command StopGPS = new Command("Stop", Command.ITEM, 0);
        Command StartGPS = new Command("Start!", Command.ITEM, 0);
        
        public Form f=new Form("Listener"); 
        
        public LocationProvider provider;
        public Location location;
        public LocationListener myListener;
        public QualifiedCoordinates qc = null;
        double lat = 0.0;
        double lon = 0.0;
        float acc = (float)0.0;
        long timeMS = 0;
        
        public void startApp() {
                   
            f.addCommand(Exit);
            f.setCommandListener(this);
            Display.getDisplay(this).setCurrent(f);
            
            // test whether location API is supported, if so then find a provider and start the application
            if (System.getProperty("microedition.location.version") == null) {
                f.append ("Location API not supported");
            } else {    
                try {
                    StartGPS();  
                } catch ( Exception e  ) {
                    f.append("Provider exception");
                }
            }
        }
        
        public void pauseApp() { }
        
        public void destroyApp(boolean destroy) { 
            provider.setLocationListener(null, -1, 0, 0);     
            provider.reset();
        }
        
        public void commandAction(Command c, Displayable s)  {
            if (c == Exit) {
                destroyApp(true);
                notifyDestroyed();
            }
            if (c == StartGPS) {
                StartGPS();
            }
            if (c == StopGPS) {
                StopGPS();
            }
        }
        
         public void StartGPS() {
            try {   
    
                provider = LocationProvider.getInstance(null); // least restrictive criteria...         
    
                // 0.2 create new listener object each time StartGPS() is called
                myListener = new MyLocationListener(); 
                provider.setLocationListener(myListener, 2, 1, 2);
                
                f.removeCommand(StartGPS);
                f.addCommand(StopGPS);
                f.deleteAll();
                f.append("GPS started...");
            } catch (Exception e ) {
                // f.append("Exception in StartGPS()");            
            }
        }
         
         public void StopGPS() {
            try {
     
                provider.setLocationListener(null, -1, 0, 0);     
                provider.reset();  
                
                f.removeCommand(StopGPS);
                f.addCommand(StartGPS);
                f.deleteAll();
                f.append("Last known location:\n");
                showLocation();
                f.append(" Location listener stopped.\n");
            } catch (Exception e ) {
                f.append("Exception in StopGPS()");   
            }
        }
         
        public void showLocation() {
            f.append(" Lat: "+ lat +"°\n");
            f.append(" Lon: "+ lon +"°\n");
          }
    
    /* 0.2 now MyLocationListener placed inside class - e.g.: a separated object from MyMidlet */
    
        public class MyLocationListener implements LocationListener {     
            public void locationUpdated(final LocationProvider prov, final Location loc) {
    
                new Thread() {
                    public void run() {
                        if (loc != null && loc.isValid()) {
                            qc = loc.getQualifiedCoordinates();
                            lat = qc.getLatitude();
                            lon = qc.getLongitude();
                            acc = qc.getHorizontalAccuracy();
                            timeMS = loc.getTimestamp();
    
                            f.deleteAll();
    
                            f.append("Latest location:\n");
                            showLocation();
                        } else {
                            // if Location is not valid...
                            f.deleteAll();
                            f.append("Last known location:\n");
                            showLocation();
    
                            int test = prov.getState();
                            if (  test == LocationProvider.AVAILABLE )
                                f.append(" Available. Searching...\n");                        
                            else if ( test == LocationProvider.TEMPORARILY_UNAVAILABLE )
                                f.append(" Temporarily unavailable...\n");
                            else
                                f.append(" Out of Service...\n");     
                        }
                    }
                }.start();
    
            }
    
            public void providerStateChanged(LocationProvider prov, int newState) {
            }  
        }
        
    }
    Last edited by nicholso; 2008-01-16 at 06:02. Reason: E90

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    45

    Re: JSR-179API provider reset to stop GPS location activity

    I repeated the tests with an N95 (CE marked unit), and same error is observed: if the function calls are made with an existing GPS satellite fix, the battery life is only 8hours and power consumption is around 0.44W.
    http://www.geocities.com/guy_nich/n95.png

    If there is no satellite fix, the power consumption drops to normal standby levels.

  7. #7
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,430

    Re: JSR-179API provider reset to stop GPS location activity

    Hi nicholso,

    I am able reproduce the same in E90. But saw that if we exit he MIDlet, the battery life is getting improved.

    For me the EnergyProfiler takes some time to give a stable graph.

    Regards
    Gopal

  8. #8
    Registered User
    Join Date
    Nov 2007
    Posts
    16

    Re: JSR-179API provider reset to stop GPS location activity

    Hi,

    I have the same problem on my Nokia 6110 Navigator.

    Did anyone find a workaround? I tried periodically calling getLocation, allowing the GPS to power down between samples. At least on my Nokia 6110, getLocation seems to be quite buggy and will eventually hang the MIDlet.

    Details here

    Cheers, Stewart

  9. #9
    Registered User
    Join Date
    Jul 2005
    Posts
    29

    Re: JSR-179API provider reset to stop GPS location activity

    Hi !

    I have the same problem.
    Could not solve it.

    Neither

    provider.reset()

    nor

    provider.setLocationListener(null, 1, -1, -1)

    helps on

    Navigator 6110

    regards

    Michael

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    45

    Re: JSR-179API provider reset to stop GPS location activity

    There is a "known issue" article in the Developers Wiki about this issue.

    http://wiki.forum.nokia.com/index.ph...d_battery_life

    For my application, exiting the midlet does not provide a solution. I have not found a proper work-around to allow an active midlet using location listener to start and stop the GPS module (stop here means "power-down").
    Last edited by nicholso; 2008-04-24 at 09:22.

  11. #11
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595

    Re: JSR-179API provider reset to stop GPS location activity

    Hello nicholso,

    ..For my application, exiting the midlet does not provide a solution.
    Just to check: I've noticed that the battery level normalized rather slowly after exiting the MIDlet.

    Have you tried to test this after some period (15 seconds or so) from exiting the MIDlet?

    Regards,
    r2j7
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

  12. #12
    Registered User
    Join Date
    Mar 2003
    Posts
    45

    Re: JSR-179API provider reset to stop GPS location activity

    hi r2j7

    Sure - the GPS powers-down when the user exits midlet. Yes - it does take time like 15-30 seconds.

    But my comment was this doesn't provide a solution for developer applications... e.g.: the use case where -within- the application the user can turn off gps, or the application can power off gps after inactivity of set time.

    Please try google s60 maps application or Nokia Location tagger from Nokia's beta labs ... Each powers down GPS within the application and doesn't require user to exit the application. This saves precious battery life whilst the user can continue to use the application.

    By contrast the current J2ME implementation requires that if user/J2ME application wants to power down GPS, then user/J2ME application MUST exit the midlet.

    Thanks for trying to help, but the real issue is within the J2ME implementation,
    Guy
    Last edited by nicholso; 2008-05-13 at 06:50.

  13. #13
    Registered User
    Join Date
    Nov 2008
    Posts
    7

    Unhappy Re: JSR-179API provider reset to stop GPS location activity

    We have a project with JSR-179 API on N95,we have same problems with you about power consumption;

    We have question marks about gps system on mobile phone;

    1-Gps on mobile phone works everytime ? or it will be activited when applications begin getting info from gps ?

    2-In our application when we set locationListener 5 minutes interval,what will be about power consumption,is it more different from setting loationlistener 2 seconds?

    3-I have read an article that says if you don't get info from gps during 10 minutes it will turn sleep mode is that true? If that is true ,when changing over sleep mode to active mode,will the power consumption peak?

    thanks,

  14. #14
    Registered User
    Join Date
    Dec 2008
    Posts
    5

    Re: JSR-179API provider reset to stop GPS location activity

    Have you tried to test (2) and (3) with energy profiler?

    Bye,
    Eritreo.

  15. #15
    Registered User
    Join Date
    Nov 2008
    Posts
    7

    Re: JSR-179API provider reset to stop GPS location activity

    I couldn't try because I'm working on s60 emulator and can't install energy profiler on it for testing, I couldn't find solution,researched too many documents about gps power consumption

Similar Threads

  1. Location API (JSR 179) without GPS..
    By d33 in forum Mobile Java General
    Replies: 21
    Last Post: 2008-08-01, 13:51
  2. Replies: 7
    Last Post: 2008-02-08, 12:02
  3. Location api jsr 179 and Bluetooth GPS
    By prategiov in forum Mobile Java General
    Replies: 21
    Last Post: 2007-12-04, 23:36
  4. Location API JSR 179
    By scarasimon in forum Series 40 & S60 Platform Feedback Archive
    Replies: 1
    Last Post: 2007-11-15, 18:13
  5. Location API, but no GPS
    By redsmurph in forum Mobile Java General
    Replies: 3
    Last Post: 2007-01-30, 20:59

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •