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
Contributor
Posts: 31
Registered: ‎11-14-2012
My Device: Blackberry 9780
My Carrier: Digicel

Assisted mode not working on Torch 9800?

The app I'm working on relies on an accurate GPS fix... I'm still toying around with GPS and trying to get the hang of it. I was thinking I will skip CELLSITE mode because this is way too inaccurate, so I thought of just trying to get an ASSISTED fix then jump to INTERNAL GPS after. Is that logic flawed? Currently, I'm not getting a GPS fix with the code here...

// Setup the GPS listener

public static void setupGPSListener() {
if (setupComplete) {
Utils.warn("GPS: Setup already done, no need to do this again");
return;
}

int gpsMode = -1;
gpsHandle.criteria = new BlackBerryCriteria();
if (GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_ASSIST)) {
// set the fail over mode to be cell site mode
Utils.log("GPS: Using assisted mode");
gpsMode = GPSInfo.GPS_MODE_ASSIST;
} else if (GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_AUTONOMOUS)) {
Utils.log("GPS: Using internal device");
gpsMode = GPSInfo.GPS_MODE_AUTONOMOUS;
} else if (GPSInfo.isGPSModeAvailable(GPSInfo.GPS_MODE_CELLSITE)) { // Use this as the ULTIMATE last resort
Utils.log("GPS: Using cell site mode");
gpsMode = GPSInfo.GPS_MODE_CELLSITE;
}

if (gpsMode != -1) {
Utils.log("GPS: Setting up listener");
GLPrerequisites.prerequisiteStarted(GLPrerequisites.PREREQ_GPS_LISTENER_SETUP);
GLPrerequisites.prerequisiteStarted(GLPrerequisites.PREREQ_GPS_FIX_ACQUIRED);

try {
gpsHandle.criteria.setMode(gpsMode);
gpsHandle.provider = (BlackBerryLocationProvider) LocationProvider.getInstance(gpsHandle.criteria);
gpsHandle.provider.setLocationListener(gpsHandle, 30, -1, -1); // <----- wasn't sure what values to use here? 
Utils.log("GPS: Listener setup");
setupComplete = true;
} catch (LocationException e) {
e.printStackTrace();
}
} else {
Utils.err("GPS: No GPS support available");
gpsHandle.setSupported(false);
Utils.err("GPS: No GPS available");
}
}

 

 

On a particular screen where I need to use the fix I use this code to try and get a fix...

while(!fixAcquired && attempts < 3){
try {
attempts++;
GPSHandle.getLocation(delay); // try to get a fix
fixAcquired = GPSHandle.isValid();

} catch (LocationException e) {
e.printStackTrace();
Utils.err("Location exception occurred: " + e.getMessage());
delay*=2;
} catch (InterruptedException e) {
Utils.err("Interruption exception occurred: " + e.getMessage());
delay*=2;
}
}

 

Finally.. the GPSHandle.getLocation(int delay) method is here...

public static BlackBerryLocation getLocation(int timeout) throws LocationException, InterruptedException {
if (gpsHandle.provider != null) {
if (isValid()) {
return gpsHandle.currentLocation;
}
BlackBerryLocationProvider provider = gpsHandle.provider;
BlackBerryLocation location = (BlackBerryLocation) provider.getLocation(timeout);
if (isValid(location)) {
GPSHandle.getHandle().currentLocation = (BlackBerryLocation) location;
return location;
}
}
return null;
}

 

Any pointers given will be greatly appreciated!