SQLite is a common way provided by the Android SDK for Android apps to persist data. Persistent data ensures user-generated content isn't lost when the app is closed, or data downloaded from the internet is saved so it doesn't need to be redownloaded later. The Clock app stores your recurring alarms, the Google Maps app saves a list of your recent searches, and the Contacts app lets you add, edit, and remove your contacts' information.ĭata persistence-storing or persisting data on the device-is a big part of Android development. Once you have opened the database, you are ready to do some spatial magic.Many of the apps you use store data directly on the device. If the database doesn't exist, it will be created empty (due to the SQLITE_OPEN_CREATE flag).įile spatialDbFile = new File(sdcardDir, "italy.sqlite") ĭb.open(spatialDbFile.getAbsolutePath(), _OPEN_READWRITE The following will open the database named italy.sqlite that is placed in your sdcard. Let's do some basic stuff with it in the next chapters. Your project is already Spatialite enabled. copy the java package of the base API into you new project's source folderĪnd that is it.copy the native libs into the root of the newly created Android project.The first step is to copy the main components of the Spatialite-Android project as mentioned before. Once the hello world project can be run, we can start to add the spatialite part. It will generate you a ready to use Android application that shows a nice View with Hello World on it. Use the Android eclipse new project wizard to create a basic hello world example for Android. Copy the created database on the mobile device's external storage card. Your first Spatialite enabled project Prepare a datasetįollow this tutorial to create a spatialite database that contains the comuni_2011.shp (find references to where to get it here) data. the basic API classes, contained in the jsqlite package.the native spatialite libraries: they are places in a folder named libsĪnd contains several folders for different platforms that hold the main library, called libspatialite.so.The downloaded archive contains 2 basic components necessary to enable your project to use Spatialite: Note that it would be possible to create an Android library to reference from the project, but to keep this tutorial short, we will just show how to integrate the library directly into our new project. The API is very small and simple and basically bases on a manual building of the queries to send to the database. Once that is done, there are few steps to perform to get things working. To get started we just need to get the Spatialite libraries and add them to our new Android application project. The sqlite database used for this tutorial can be downloaded in the download area of the same project page. It should work out of the box and show you where libs need to be put and how to run queries. The quickest way is to download the source project of this documentation, browse it and run it. The project is released under LGPLv3 license. The Spatialite-Android project has been released by the U.S. It is meant for developers that have at least a minimal knowledge about Android application development (having built and run the hello world app shoul be enough). In this document we will help new developers to get started with their first Spatialite enabled application. The Spatialite-Android project is simple to use and stable. That should not scare away any developer eager to play real geospatial on Android devices. Even if since the appearence of SpatiaLite in the geospatial world it looked like a perfect match to have it available by default for the system, developers had to wait for a while to use spatialite on Android.Īnd even now, that it is available, it is not integrated in the operating system and it is not accessible through the standard Android persistence APIs. The Android operating system for mobile devices uses as its default relational database SQLite. Many thanks to Andrea for his thorough documentation effort !!! This Wiki page has been kindly contributed by Andrea Antonello, a skilled Java devoloper with a sound specific experience on Android, and actively involved in several GFOSS projects (PSC member of uDig and maintainer of GeoPaparazzi).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |