BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 07-23-2008, 12:16 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Oct 2005
Model: 7250
Carrier: ATT
Posts: 20
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default Bluetooth GPS hoses up on OS 4.2.X

Please Login to Remove!

I've pasted a simple application that stops getting fixes from a bluetooth GPS unit when it goes out of range or turned off... and then is turned back on/comes back in range. This is a one-shot TimerTask-based LocationProvider.getLocation that will return timeouts forever after the condition occurs. Pearl 8100/Globalsat BT-368i with OS 4.2.1. I have tested this with OS 4.5.0 (beta) and it DOES work there, but isn't a workable solution to require all my target customers to install a beta OS. Should be a simple test, could anyone spend 5 minutes and try this app out or lend some advice? Thanks!

Code:
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

import javax.microedition.location.*;
import java.util.*;

public class GPSDemo extends UiApplication 
{
    private static int _interval = 30; 
    private static int _cnt = 0;
    private EditField _status;
    private Timer timer = null;
 
    private final class GPSDemoScreen extends MainScreen
    {
        protected void makeMenu(Menu menu, int instance)
        {         
            menu.add( _close );    
            menu.add(_background);       
            menu.addSeparator(); 
            super.makeMenu(menu, instance);
        }
        
        public boolean onClose()
        {
            if (timer != null)
                timer.cancel();            
            return super.onClose();
        }
    }
    
    public static void main(String[] args)
    {
        new GPSDemo().enterEventDispatcher();
    }

    public GPSDemo()
    {
        GPSDemoScreen screen = new GPSDemoScreen();
        screen.setTitle(new LabelField("GPS", LabelField.USE_ALL_WIDTH));      
        _status = new EditField();
        screen.add(_status);                 
        pushScreen(screen);
        timer = new Timer();
        timer.scheduleAtFixedRate(new GPSTask(),5000,60000);
    }
    
    private final class GPSTask extends TimerTask
    {
        public void run()
        {
            LocationProvider lp = null;
            try {
                Criteria cr = new Criteria();
                lp = LocationProvider.getInstance(cr);
                Location l = lp.getLocation(30);
                if (l.isValid()) {
                    Coordinates c = l.getQualifiedCoordinates();
                    if ( c != null ) {
                        _cnt++;
                        updateLocationScreen("Got a fix: " + _cnt);                        
                    } else {
                        updateLocationScreen("Coords was null");
                    }
                } else {
                    updateLocationScreen("location not valid");
                }
            }
            catch (Exception e) {
                updateLocationScreen("Failed: " + e.getMessage());
            }
            if (lp != null) {
                lp.reset(); // Not sure if this is smart
                lp = null;
            }
        }
    }

    private void updateLocationScreen(final String msg)
    {
        invokeLater(new Runnable() {
            public void run()
            {
                _status.setText(msg);
                short[] explodeAudio =
                    {
                        300, 50, 500, 50, 300, 50, 500, 50, 300, 50
                    };
                if (Alert.isBuzzerSupported())
                    Alert.startBuzzer(explodeAudio, 100);
                else if (Alert.isAudioSupported())
                    Alert.startAudio(explodeAudio,100);
            }
        });
    }

    private MenuItem _close = new MenuItem("Close", 0, 10) {
        public void run()
        {          
            System.exit(0);
        }
    };
    
    private MenuItem _background = new MenuItem("Background", 1, 10) {
        public void run()
        {
            requestBackground();
        }
    };
}
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.