I have test midlet which requests my location via JSR-179 Location API.
I use Nokia 6275i.
Its java: MIDP-2.0, GPS enabled (I see blue icon on top of my mobile device)
When I run this app I got the following error:
"java.lang.securityexception: Positioning Log denied Location access."
Google do not give clean results.
Please, anybody know what does mean this exception?
I tried add permissions javax.microedition.location.... No success.
My test midlet is here:
package hello;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.location.*;
public class CoordinateAlert extends MIDlet implements CommandListener {
private Display display;
private Form mainForm;
private Alert positionAlert;
public CoordinateAlert() {
mainForm = new Form("HelloMIDlet");
mainForm.append(new StringItem(null, "You will be alerted of your current position."));
mainForm.addCommand(new Command("Exit", Command.EXIT, 0));
mainForm.addCommand(new Command("OK", Command.OK, 1));
mainForm.setCommandListener(this);
}
public void startApp() {
display = Display.getDisplay(this);
display.setCurrent(mainForm);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
public void commandAction(Command c, Displayable s) {
String label = c.getLabel();
if (label.equals("Exit")) {
notifyDestroyed();
}
else if (label.equals("OK")) {
mainForm.set(0, new StringItem(null, "Tracking location ..."));
givePositionAlert ();
mainForm.set(0, new StringItem(null, "Again get alerted of your current position?"));
}
}
private void givePositionAlert () {
try {
Criteria cr = new Criteria();
cr.setHorizontalAccuracy(500);
LocationProvider lp = LocationProvider.getInstance(cr);
Location l = lp.getLocation(60);//60 seconds, timeout
Coordinates c = l.getQualifiedCoordinates();
if (c != null) {
String lat = c.convert(c.getLatitude(),c.DD_MM);
if (c.getLatitude() > 0) {
lat = "E " + lat;
}
else {
lat = "W " + lat;
}
String lon = c.convert(c.getLongitude(),c.DD_MM);
if (c.getLatitude() > 0) {
lon = "N " + lon;
}
else {
lon = "S " + lon;
}
positionAlert = new Alert("Location Alert");
positionAlert.setString("\nYour present location is \n" + lat + "\n" + lon);
positionAlert.setTimeout(Alert.FOREVER);
}
else {
positionAlert = new Alert("Location Error");
positionAlert.setString("Null Coordinate Received");
positionAlert.setTimeout(Alert.FOREVER);
}
}
catch (Exception e) { //LocationException OR InterruptedException
positionAlert = new Alert("Location Error");
positionAlert.setString("Exception Encountered " + e);
positionAlert.setTimeout(Alert.FOREVER);
}
display.setCurrent(positionAlert);
}
}
I obtain source code from this location: http://www.easywms.com/easywms/?q=en/node/3598
Thank you in advance.
Neo