Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 121
Registered: ‎11-19-2008
My Device: Not Specified

Obtaining GPS from a system module doesn't work

I keep having problems obtaining the GPS location from a system module (with the option Auto-run on startup also selected). The exact same code succeeds in obtaining the GPS coords when run from the UI-enabled part of the application.

 

I wonder is there some limitation that prevents the getting of GPS coords from a system module?

 

I have structured the application to to have an alternate CLDC application entry point. The alternative application entry point starts the UI, which in turn has no problem obtaining the GPS coords.

 

Any help would be appreciated. Below is the code that I use to get the GPS coords.

 

public Location _getGPSLocation() throws LocationException, InterruptedException{
        Criteria criteria = new Criteria();
        criteria.setHorizontalAccuracy(Criteria.NO_REQUIREMENT);
        criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT);
        criteria.setPreferredPowerConsumption(Criteria.NO_REQUIREMENT);
        criteria.setCostAllowed(true);

        LocationProvider locationProvider = LocationProvider.getInstance(criteria);
        Location location = locationProvider.getLocation(30);
       
        return location;
    }

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Obtaining GPS from a system module doesn't work

I have code that runs as an autostarted System module in the background and obtains GPS locations with no problem.

 

Do you continuously try to obtain the location in the System module or is this a one-off you want to do at start-up.  If a one-off, I would make sure that the system has actually started before your GPS stuff kicks in - if only because the first time it might want to prompt the user for permission. 

 

If this is no help, can you tell us if you having problems with the Simulator or device, what device is involved and what OS Level you are developing on and is on the device.  Giving us a "summary" version of your application that we can look at and try might also help.

 

Sorry can't be of more use immediately.

Developer
Posts: 121
Registered: ‎11-19-2008
My Device: Not Specified

Re: Obtaining GPS from a system module doesn't work

I don't believe permissions are the problem because when I tested this on a physical device (8330 with OS 4.3.0) I made sure that the GPS permission is set to Allow for the app right after the app got installed.

 

For a simulator I am using the 8800 simulator that comes with the JDE 4.2.1.

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Obtaining GPS from a system module doesn't work

So do you see the problem on the Simulator?  Are you going for a one-off location at start up or continuously getting the current location?

Developer
Posts: 121
Registered: ‎11-19-2008
My Device: Not Specified

Re: Obtaining GPS from a system module doesn't work

Yes, i see the problem in the Simulator as well. The background system thread polls the GPS every 5 mins, and they all fail.I launch the background GPS thread from an alternate application entry point, like this:

 

public static void main(String[] args){
        if ( args != null && args.length > 0 && args[0].equals("gui") ){
           
            MyApplication app = new MyApplication();
           
            app.enterEventDispatcher();
        }else{
            MyGPSThread calcThread = new MyGPSThread ();
            calcThread.start();
        }
    }

 

When I get rid of the alternate entry point and launch the GPS thread from the thread that calls

Application.enterEventDispatcher() it all works.

 

The GPS background thread that you say you have working, how does it get launched?

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Obtaining GPS from a system module doesn't work

Good question - how does it get launched! 

 

I've just reviewed the code.  I've split my code into two parts (i.e. two separate cods), that share a Library and some RuntimeStore (Library is its own cod, so three cods in total).  I have a UiApplication that runs the icon.  I have an Application that does the data collection.  So when I said I had a background System module, I neglected to mention that it was a standalone application.  Sorry.

 

And I think this is your problem.  You start the Thread, but it is NOT associated with an Application, so it will never be scheduled.  To do what you want to do, you are going to have to start MyApplication (i.e. Issue the "enterEventDisplatcher()'), then let the icon just bring it to he foreground. 

 

You will probably need to delay the initialization until you are sure the BB has finished loading - there is a couple of good KB articles on this, I suggest this:

How To - Display a GUI when the BlackBerry device starts up
Article Number: DB-00539

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/How_To_...

I think if you remove the

UiApplication.getUiApplication().requestForeground();

then your screen will stay in the Background ready for someone to click on the icon.

This article is also a good one:

How to - Detect system availability on startup 
Article Number: DB-00642

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800901/How_to_-_Detec...

Alternatively split the code the way I have done.  This has the "advantage" that the GPS Tracker runs in the background and no-one can see it.

 

Hope this helps.