"ArcGIS Runtime SDK for Android Development note"-off-line integration technology: Offline vector data synchronization

Source: Internet
Author: User
Tags throwable

1. Preface

In the previous article, we realized the editing operation of offline elements, this article mainly introduces the synchronization function of the offline data in the last part of the online integration technology, through the data upload, server-side versioning management, to achieve the entire process of data production management.

Reprint Please specify source: http://www.cnblogs.com/gis-luq/p/5858062.html

2, the demo implementation process 2.1, the Demo UI implementation

Activity_main.xml

<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.example.syncgdb.MainActivity">    <!--Mapview -    <Com.esri.android.map.MapViewAndroid:id= "@+id/map"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent"mapoptions. Maptype= "Topo"mapoptions. Zoomlevel= "5"Mapoptions.center= "28.671298, 104.066404" />    <ButtonAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Offline data Synchronization"Android:id= "@+id/btnsync"Android:layout_alignparenttop= "true"Android:layout_alignparentright= "true"Android:layout_alignparentend= "true" /></Relativelayout>
2.3, the realization of offline geo-database synchronization basic ideas:
    1. Get the. geodatabase File storage Path
    2. Get featureserviceinfo Service parameter information according to Featureservice service
    3. Synchronize offline geodatabases based on featureserviceinfo information
    4. Feedback synchronization results in the UI thread

Full code

 Packagecom.example.syncgdb;Importandroid.app.Activity;ImportAndroid.app.ProgressDialog;ImportAndroid.content.Context;Importandroid.os.Environment;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.Toast;ImportCom.esri.android.map.FeatureLayer;ImportCom.esri.android.map.MapView;ImportCom.esri.core.ags.FeatureServiceInfo;Importcom.esri.core.geodatabase.Geodatabase;Importcom.esri.core.geodatabase.GeodatabaseFeatureTable;Importcom.esri.core.geodatabase.GeodatabaseFeatureTableEditErrors;ImportCom.esri.core.map.CallbackListener;ImportCom.esri.core.tasks.geodatabase.GeodatabaseStatusCallback;ImportCom.esri.core.tasks.geodatabase.GeodatabaseStatusInfo;ImportCom.esri.core.tasks.geodatabase.GeodatabaseSyncTask;Importcom.esri.core.tasks.geodatabase.SyncGeodatabaseParameters;ImportJava.io.File;Importjava.io.FileNotFoundException;ImportJava.util.Map; Public classMainactivityextendsappcompatactivity {protected Static FinalString TAG = "Syncgdb"; Privatecontext Context; PrivateMapview Mmapview;//Map Container    Private StaticString Onlinefeaturelayerurl = "Http://192.168.1.212:6080/arcgis/rest/services/testdata/FeatureServer";//Online Featurelayer Address    Private StaticString Localgdbfilepath;//offline GDB address    PrivateGeodatabasesynctask Gdbsynctask;//offline geodatabase Download Task    PrivateProgressDialog Mprogressdialog;//Status Box@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);  This. Context = This;  This. Mmapview =(Mapview) Findviewbyid (R.ID.MAP); //set up an offline geodatabase storage pathLocalgdbfilepath =Creategeodatabasefilepath (); //loading an offline geodatabaseAddfeaturelayer (Localgdbfilepath); Mprogressdialog=NewProgressDialog (context); //Set the Click Progress dialog box outside the Area dialog box does not disappearMprogressdialog.setcanceledontouchoutside (false); Mprogressdialog.settitle (Synchronizing offline geodatabase copy to server); //bind button Settings Download eventButton Btnsyncgdb = (button) This. Findviewbyid (R.id.btnsync); Btnsyncgdb.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {syncofflinedata ();//Synchronizing offline geodatabases            }        }); }    /*** geodatabase file storage path*/    StaticString Creategeodatabasefilepath () {returnEnvironment.getexternalstoragedirectory (). GetAbsolutePath () + File.separator + "/runtimeofflineedit" + File . Separator + "Demo.geodatabase"; }    /*** Read offline map information in Geodatabase *@paramfeaturelayerpath offline geodatabase file path*/    Private voidAddfeaturelayer (String featurelayerpath) {geodatabase localgdb=NULL; Try{localgdb=Newgeodatabase (Featurelayerpath); } Catch(FileNotFoundException e) {e.printstacktrace (); }        //add Featurelayer to Mapview        if(Localgdb! =NULL) {             for(geodatabasefeaturetable gdbFeatureTable:localGdb.getGeodatabaseTables ()) {if(Gdbfeaturetable.hasgeometry ()) {Featurelayer layer=NewFeaturelayer (gdbfeaturetable);                Mmapview.addlayer (layer); }            }        }    }    /*** Synchronize offline geodatabases*/    Private voidSyncofflinedata () {log.i (TAG,"Sync Geodatabase"); //Create a dialog to update user on progressmprogressdialog.show (); Gdbsynctask=NewGeodatabasesynctask (Onlinefeaturelayerurl,NULL); Gdbsynctask.fetchfeatureserviceinfo (NewCallbacklistener<featureserviceinfo>() {@Override Public voidonError (Throwable arg0) {log.e (TAG,"Get Featureserviceinfo Failed"); } @Override Public voidOnCallback (Featureserviceinfo fsinfo) {if(fsinfo.issyncenabled ()) {syncgeodatabase (fsinfo);    }            }        }); }    /*** Get offline Geodatabase synchronization information based on featureserviceinfo information *@paramfeatureserverinfo Service Parameter information*/    Private voidsyncgeodatabase (Featureserviceinfo featureserverinfo) {Try {            //Create an offline GeodatabaseGeodatabase GDB =Newgeodatabase (Localgdbfilepath); //get offline geodatabase synchronization parameters            FinalSyncgeodatabaseparameters Syncparams =gdb.getsyncparameters (); Callbacklistener<map<integer, geodatabasefeaturetableediterrors>>Syncresponsecallback=NewCallbacklistener<map<integer, geodatabasefeaturetableediterrors>>() {@Override Public voidOnCallback (Map<integer, geodatabasefeaturetableediterrors>Objs)                    {Mprogressdialog.dismiss (); if(Objs! =NULL) {                        if(Objs.size () > 0) {Showmaketext ("Synchronization completed, but error occurred"); } Else{Showmaketext ("Sync Complete: Synchronization succeeded"); }                    } Else{Showmaketext ("Sync Complete: Synchronization succeeded"); }} @Override Public voidOnError (Throwable e) {log.e (TAG,"", E);                    Mprogressdialog.dismiss (); Toast.maketext (Context,"Error:" +e.tostring (), Toast.length_short). Show ();            }            }; Geodatabasestatuscallback Statuscallback=NewGeodatabasestatuscallback () {@Override Public voidstatusupdated (geodatabasestatusinfo status) {FinalString progress =status.getstatus (). toString (); //Update the download status on the UI thread(Activity) context). Runonuithread (NewRunnable () {@Override Public voidrun () {Mprogressdialog.setmessage ("In data synchronization, please later ...");                }                    });            }            }; //Perform synchronizationgdbsynctask.syncgeodatabase (Syncparams, GDB, Statuscallback, Syncresponsecallback); } Catch(Exception e) {e.printstacktrace (); }    }    /*** Perform status hints in the UI thread *@parammsg*/    Private voidShowmaketext (FinalString msg) {        //Update the download status on the UI thread(Activity) context). Runonuithread (NewRunnable () {@Override Public voidrun () {Toast.maketext (context, MSG, toast.length_short). Show ();    }        }); }}

Source code managed Address: Http://git.oschina.net/gis-luq/RuntimeOfflineEdit

3. Data Synchronization Results

Related Content List

"ArcGIS Runtime SDK for Android Development note"-off-line integration technology: overview

"ArcGIS Runtime SDK for Android Development note"-off-line integration technology: Offline vector data download

"ArcGIS Runtime SDK for Android Development note"-off-line integration technology: Offline vector data editing

"ArcGIS Runtime SDK for Android Development note"-off-line integration technology: Offline vector data synchronization

"ArcGIS Runtime SDK for Android Development note"-Data creation: Publishing Featureservice services with synchronization capabilities

"ArcGIS Runtime SDK for Android Development note"-off-line integration technology: Offline vector data synchronization

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.