Question

I want to get longitude and latitude of the phone mobile by this code:

    public void commandAction(Command com, Displayable d) {
        if (com == position)
        {
            try
            {
                Criteria cr = new Criteria();
                cr.setHorizontalAccuracy(500);
                LocationProvider lp = LocationProvider.getInstance(cr);
                // get the location, one minute timeout
                Location l = lp.getLocation(60);
                Coordinates coords = l.getQualifiedCoordinates();
                if (coords != null)
                {
                    double longitude = coords.getLongitude();
                    double latitude = coords.getLatitude();
                    String sLong = String.valueOf(longitude);
                    String sLat = String.valueOf(latitude);
                    Tlongitude.setString(sLong);
                    Tlatitude.setString(sLat);
                }
            } catch (LocationException ex) {
                Tlongitude.setString("LocationException");
                Tlatitude.setString("LocationException");
            } catch (InterruptedException ex) {
                Tlongitude.setString("InterruptedException");
                Tlatitude.setString("InterruptedException");
            }
        }
    }

The problem is that when clicking the "position" command then a system alert is shown saying : java.lang.SecurityException : Application not authorized to access the restricted API .

So what should I do?

Était-ce utile?

La solution

add the relevant permission to your application and sign it with a certificate in the corresponding security domain.

The JSR179 specification defines 7 permissions under javax.microedition.location. Choose the ones you need based on what you need your code to do.

Lucifer's solution (Verisign or Thawte) will help if the location function group is in the trusted third party security domain for the phones you want to run your code on. The phone's mobile network operator or manufacturer might have decided to put location in their security domain instead, though.

https://stackoverflow.com/q/1716755 contains a brief explanation of the MIDP security model.

Autres conseils

You are trying to access a Location API, which a restricted API. To achieve this you must signed your mobile application with a signing certificate like Verisign,Thawte etc.

The cost of the Certificate is around 20K Indian Rupees.

You can visit my other answers here and here regarding Signing Certificate.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top