Editing capabilites of Android SDK 100.0.0

1444
8
Jump to solution
04-19-2017 09:47 AM
RubénPérez_Planillo
New Contributor III

Hello!

I want to add new points into a FeatureTable (ServiceFeatureTable) that is located in ArcGIS Online.

When I checked the API reference:

ServiceFeatureTable| arcgis-android 

I cannot find any method that allow me to add data. I found this example for the Java version:

Add features—ArcGIS Runtime SDK for Java | ArcGIS for Developers 

but methods described there are not available in the Android SDK 100 version...  Also, I cannot find in this page:

Choosing the right version | ArcGIS for Developers 

this limitations....

Could somebody help with this? May I use the 10.2.9 SDK for editing purposes?

thanks in advance!

0 Kudos
1 Solution

Accepted Solutions
AlexanderNohe1
Occasional Contributor III

Here is a very quick sample of what I was able to do to edit an online feature service.

public class MainActivity extends AppCompatActivity {

    ServiceFeatureTable sft;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        sft = new ServiceFeatureTable("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/0");
        sft.addDoneLoadingListener(new Runnable() {
            @Override
            public void run() {
                Log.e("TEST", "Feature Loaded");
                Feature feature = sft.createFeature();
                sft.addFeatureAsync(feature);
                ListenableFuture<List<FeatureEditResult>> listListenableFuture = sft.applyEditsAsync();
                try {
                    for (FeatureEditResult featureEditResults : listListenableFuture.get()) {
                        Log.e("TEST", "Fetaure Edit Results");
                        Log.e("TEST", "ObjectID" +featureEditResults.getObjectId());
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }
            }
        });

        sft.loadAsync();


    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I hope this helps!

View solution in original post

8 Replies
AlexanderNohe1
Occasional Contributor III

Here is a very quick sample of what I was able to do to edit an online feature service.

public class MainActivity extends AppCompatActivity {

    ServiceFeatureTable sft;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        sft = new ServiceFeatureTable("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/0");
        sft.addDoneLoadingListener(new Runnable() {
            @Override
            public void run() {
                Log.e("TEST", "Feature Loaded");
                Feature feature = sft.createFeature();
                sft.addFeatureAsync(feature);
                ListenableFuture<List<FeatureEditResult>> listListenableFuture = sft.applyEditsAsync();
                try {
                    for (FeatureEditResult featureEditResults : listListenableFuture.get()) {
                        Log.e("TEST", "Fetaure Edit Results");
                        Log.e("TEST", "ObjectID" +featureEditResults.getObjectId());
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    e.printStackTrace();
                }
            }
        });

        sft.loadAsync();


    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I hope this helps!

RubénPérez_Planillo
New Contributor III

Thanks! It works!

Sometimes is very difficult to find good examples of SDK key functionality, something that rarely happens with javascript REST API.

AlexanderNohe1
Occasional Contributor III

Glad to have helped!  Could you go ahead and mark my answer as the correct answer?

Thanks,

Alexander

RubénPérez_Planillo
New Contributor III

Sure!

I guess I've done it..

A quick question: did it work with hosted ArcGIS Online layers instead of ArcGIS Server FeatureServer?

AlexanderNohe1
Occasional Contributor III

If you are planning on using the URL of the service directly, there should be no difference.

0 Kudos
RubénPérez_Planillo
New Contributor III

Hi again!

Sorry, but i'm a little bit lost with this, i cannot find any relevant example beyond the simplest one.

I notice that in your example you do not pass the geometry and the attributes to the feature to create. When I add geometry it works fine, but when i try to add attributes it did not do it. Also, I notice too that you choose not to use asynchronous capabilities, usind the .get() method that stop the process until the request end.

this is my modification of your code:

//SpatialReference webSR = SpatialReference.create(3857);
//Point pt = new Point(-17.2627, 28.1885, SpatialReferences.getWgs84());
//Point webPoint = (Point) GeometryEngine.project(pt, webSR);

Feature feature = sFeatureLayerUtils.featureTableMoni.createFeature(attributes,mapPoint);
//feature.setGeometry(mapPoint);

sFeatureLayerUtils.featureTableMoni.addFeatureAsync(feature);

ListenableFuture<List<FeatureEditResult>> listListenableFuture = sFeatureLayerUtils.featureTableMoni.applyEditsAsync();
try {

 //TODO Esto bloquea hasta que llega el resultado.
 for (FeatureEditResult featureEditResults : listListenableFuture.get()) {
 Log.e("TEST", "Fetaure Edit Results");
 Log.e("TEST", "ObjectID " +featureEditResults.getObjectId());
 }
} catch (InterruptedException e) {
 Log.e("ERROR", "InterruptedException en carga de monitorizacion: " + e.getMessage());
 e.printStackTrace();
} catch (ExecutionException e) {
 Log.e("ERROR", "ExecutionException en carga de monitorizacion: " + e.getMessage());
 e.printStackTrace();
}

any help in this will be very appreciated!

0 Kudos
AlexanderNohe1
Occasional Contributor III

Are you getting a specific error?

To update the attributes, I did the following:

public class MainActivity extends AppCompatActivity {

    ServiceFeatureTable sft;
    Portal portal;
    ListenableFuture<List<FeatureEditResult>> listListenableFuture;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        sft = new ServiceFeatureTable("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/0");
        sft.addDoneLoadingListener(new Runnable() {
            @Override
            public void run() {
                Log.e("TEST", "Feature Loaded");
                Feature feature = sft.createFeature();
                feature.getAttributes().put("description", "DESCIPTION");
                sft.addFeatureAsync(feature).addDoneListener(new Runnable() {
                    @Override
                    public void run() {
                        listListenableFuture = sft.applyEditsAsync();
                        listListenableFuture.addDoneListener(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    for (FeatureEditResult featureEditResults : listListenableFuture.get()) {
                                        Log.e("TEST", "Fetaure Edit Results");
                                        Log.e("TEST", "ObjectID" +featureEditResults.getObjectId());
                                        for (EditResult er : featureEditResults.getAttachmentResults()) {
                                            Log.e("TEST", "OBID" + er.getObjectId());
                                        }
                                    }
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                } catch (ExecutionException e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                    }
                });


            }
        });

        sft.loadAsync();


    }
}

You can certainly add geometry as necessary.  Some more documentation that may help you can be found here:

Edit features—ArcGIS Runtime SDK for Android | ArcGIS for Developers  

RubénPérez_Planillo
New Contributor III

Thanks! it helped a lot!

I was not very cautious with data types of attributes in the request.

So I'm finally adding features with all data I need.

Thanks again for your help!

0 Kudos