Changes

Jump to navigation Jump to search
1,207 bytes added ,  12:16, 10 April 2014
no edit summary
<br>
In the empty android package a new Java class needs to be created, this class is used to create the necessary BaseX files and communicate with BaseX. This class needs the data directory of the application for storing the corresponding BaseX files. This files should be stored in the apps /data/data/.. folder which is only accessible from the application.
This information is only available inside the applications context and not inside a library project, therefore it is neccessary necessary to pass this information to this class at the constructor call.
The following source code shows a minimal example for a BaseX class.
'''Example:'''
<pre class="brush:java">
public class BaseXDatabase {
BaseXDatabase baseXDatabase = new BaseXDatabase(getApplicationInfo().dataDir);
</pre>
At the moment it is not possible to use the BaseX library, therefore more adjustments have to be done in the BaseX code.<br>
First it is necessary to add an additional constructor to the Context class to create the BaseX files in the right directory and adjust the default constructor of it.
The following code shows the changes inside the Context.java file:
<pre class="brush:java">
public Context(String data_dir) {
this(true, (Prop.HOME = data_dir + "/"), (Prop.USERHOME = data_dir + "/"));
File dir = new File(Prop.HOME + "BaseXData");
if(!dir.exists()) {
if(!dir.mkdir()) {
android.util.Log.i("BASEX", "CREATING BASEX DIRECTORIES");
}
}
}
 
private Context(final boolean file, String home, String userhome) {
this(new MainProp(file));
}
</pre>
As shown in the adjustment above, it is necessary to set the two variables 'Prop.HOME' and Prop.USERHOME' during the constructor call. In the BaseX code those variables are final, which need also be changed in order to set them during the call.<br>
The reason for this change is that the in BaseX used System.getProperty(user.dir) returns an empty string in Android[http://developer.android.com/reference/java/lang/System.html#getProperty(java.lang.String)].
administrator, editor
10

edits

Navigation menu