Edit feature attachments

View on GitHubSample viewer app

Add, delete, and download attachments for features from a service.

Image of edit feature attachments

Use case

Attachments provide a flexible way to manage additional information that is related to your features. Attachments allow you to add files to individual features, including: PDFs, text documents, or any other type of file. For example, if you have a feature representing a building, you could use attachments to add multiple photographs of the building taken from several angles, along with PDF files containing the building's deed and tax information.

How to use the sample

Tap a feature on the map to open a callout displaying the number of attachments. Tap on the info button to view/edit the attachments. Select an entry from the list to download and view the attachment in the gallery. Tap on the floating action button '+' to add an attachment or long press to delete.

How it works

  1. Create a ServiceFeatureTable from a URL.
  2. Create a FeatureLayer object from the service feature table.
  3. Select features from the feature layer with selectFeature.
  4. To fetch the feature's attachments, cast to an ArcGISFeature and use ArcGISFeature.fetchAttachmentsAsync().
  5. To add an attachment to the selected ArcGISFeature, create an attachment and use ArcGISFeature.addAttachmentAsync().
  6. To delete an attachment from the selected ArcGISFeature, use the ArcGISFeature.deleteAttachmentAsync().
  7. After a change, apply the changes to the server using ServiceFeatureTable.applyEditsAsync().

Additional information

Attachments can only be added to and accessed on service feature tables when their hasAttachments property is true.

Relevant API

  • ArcGISFeature.deleteAttachmentAsync
  • ArcGISFeature.fetchAttachmentsAsync
  • Attachment.fetchDataAsync
  • FeatureLayer
  • ServiceFeatureTable
  • ServiceFeatureTable.applyEditsAsync
  • ServiceFeatureTable.updateFeatureAsync

Tags

Edit and Manage Data, image, picture, JPEG, PNG, PDF, TXT

Sample Code

CustomList.javaCustomList.javaEditAttachmentActivity.javaMainActivity.java
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Copyright 2016 Esri
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.esri.arcgisruntime.sample.arrayadapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import com.esri.arcgisruntime.sample.editfeatureattachments.R;

public class CustomList extends ArrayAdapter<String>{

    private final Activity context;
    private final ArrayList<String> attachmentName;
    public CustomList(Activity context,
                      ArrayList<String> attachmentList) {
        super(context, R.layout.attachment_entry, attachmentList);
        this.context = context;
        attachmentName = attachmentList;
    }
    @NonNull
    @Override
    public View getView(int position, View convertView, @NonNull ViewGroup parent) {
        CustomList.ViewHolder holder;
        if (convertView == null) {
            LayoutInflater inflater = context.getLayoutInflater();
            convertView = inflater.inflate(R.layout.attachment_entry, null, true);

            holder = new CustomList.ViewHolder();
            holder.textTitle = convertView.findViewById(R.id.AttachmentName);

            convertView.setTag(holder);
        } else {
            holder = (CustomList.ViewHolder) convertView.getTag();
        }

        holder.textTitle.setText(attachmentName.get(position));

        return convertView;
    }

    private static class ViewHolder {
        TextView textTitle;
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.