Search code examples
androidrestsecuritygeojsonesri

Access GeoJSON-String with Esri REST-API in Android with Token


I have been stuggeling wiht that for a while and found no working solution: I want to get a GeoJSON-String from an own ArcGIS Web Server. I want to use the REST-API and got it working in the browser. I just have to type in my username and password and after my authentification i can use the link to get the GeoJSON-String. In Android I tried it with different solutions, one - of course - was to follow the instructions on the Esri-Website. Here they explain how to set the Username and the Password to create a UserCredential. The UserCredential now is passed to the Method to create a new ArcGISDynamicMapServiceLayer together with the REST-Link. So they get a new Layer, but there is no method, where you can pass the UserCredential and the Link to get just a String. Because I want to get polygons I thought, that the ArcGISFeatureLayer could help me out. But if I pass the given User-Informations and the Link i just get back an null-Objekt.

Here is a snippet of my most-hopefull code:

String url = "https://domain.de/arcgis/rest/services/FeatureEditor/FeatureEditor/FeatureServer/13/query?where=fahrzeug_id+%3D+21+AND+auftrag_revisionnewest+%3D+1+AND+auftrag_id+%3D+45&geometryType=esriGeometryEnvelope&spatialRel=esriSpatialRelIntersects&units=esriSRUnit_Foot&outFields=*&returnGeometry=true&outSR=4326&returnDistinctValues=false&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnZ=false&returnM=false&f=geojson";
UserCredentials creds = new UserCredentials();
creds.setSSLRequired(true);
creds.setUserAccount("username", "password");
ArcGISFeatureLayer featureLayer = new ArcGISFeatureLayer(url,(ArcGISFeatureLayer.Options)null,creds);

So the best would be to get just the GeoJSON-String as accessable with the Link. But how can I access the HTTP with the Username and Password?


Solution

  • If you want to do that style of query within the ArcGIS Android SDK you'll have to do it with creating a FeatureLayer and then using the Query class to define the equivalent of your query string. This gives you back a FeatureSet that contains features which should have the information you're looking for, but it won't be in the form of GeoJSON. There's a toJSON method on the FeatureSet that might give you what you're looking for, but I'm not positive. If you just want a pure JSON response, you're going to have to do the HTTP requests yourself, setting up whatever authentication the REST API needs within your request and then handling the response.