BTree with Android |
Home | B+Tree Product | B+Tree Guide | B+Tree Performance | Demos | Licensing and Pricing | B+Tree FAQ |
Using the BTree with Android
Android Demo - click here to download. ***** Note that we know also support Nokia Asha and iOS (iPhone and iPad) platforms - click here to download demos.
This guide is designed for existing users of Virtual Machinery's BTree who wish to write code for Googles Android(TM) platform. Unlike the Java ME platform the Android platform can use the standard BTree. The important difference is the file paths used to create and access your BTree. The following code fragments should illustrate the basic principles. Note that any code that accesses the Context (as this does) must inherit from android.app.Activity - . . // Create a BTree try { //************ Choose only one of the following two options ************************************** // 1. Get the path to the applications private data - the amount of data that you can write will be restricted String path = getDir("data",Context.MODE_PRIVATE)+"/"; // 2. Get the path to the applications external storage (e.g an SD card) - the amount of data that you can write here is only restricted by // the capacity of the external storage. Note that you should check if the SD card has been mounted String path=getExternalFilesDir(null).getAbsolutePath()+"/"+fileset; BTree aTree = new BTree(path+"MYBTREE.DAT",path+"MYBTREE.IND",0,0); } catch (BTreeException e) { // TODO Auto-generated catch block e.printStackTrace(); } . . // Put a record try { aTree.put("MYRECORD","MYDATA"); } catch (BTreeException e) { // TODO Auto-generated catch block e.printStackTrace(); } . . // Get a record String response = null; try { response = aTree.get("MYRECORD"); } catch (BTreeException e) { // TODO Auto-generated catch block e.printStackTrace(); } As those of you familiar with Virtual Machinerys BTree interface will be aware the only difference between the code required to support Android and that used in a normal Java 'Desktop' scenario is the path to the file system. Obviously this path may change depending on the location to be accessed on the Android device - for example an SD Card. |
|