Virtual Machinery logoBTree logo
  BTree with Android
Home BTree Guide BTree Performance Sample Applications BTree Roadmap Other Products

Using the BTree with Android

Android Demo for Android 2.3 and above (all the way up to 4.2) - click here to download.

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.

Copyright Virtual Machinery 2013 - All Rights Reserved and is provided according to the terms of the license. Android is a trademark of Google Inc. Use of this trademark is subject to Google Permissions .