on 2011 Nov 13 4:22 PM
Hey!
I have a problem in mobilink environment. I have an SQL anywhere 12 for consolidated database, and I want to deploy mobilink synchronization to android devices.
I make the model and everything in sybase central, I generate the ultralite database for clients, and I made a test, the generated ultralite database file synchronizes well when I start the ultralite database on windows environment.
When I want to deploy the generated UL databases to android device, sync fails.
First of all, I dont know how to deploy the generated database file to the android clients. I found a way on android emulator that I push the .udb file to the data/data/hu.company.myproject/ folder and synchronisation goes well. This is not an elegant solution because I dont have write permission to that folder on the devices.
I've tried to add it to the ProjHome/assets/ or ProjHome/res/raw folders in my eclipse project, but DatabaseManager.Connect could not find the file.
My question is, I do it on the wrong way or the only way is to manually create the database and the schema on the devices in Java code?
Thanks for answers!
Request clarification before answering.
This is going mainly from memory; I hope it is not too far off.
One way to deploy a database file is to include the file as a resource in your Android project. Add the file to a resource folder in your project named resraw. On the first start up of the client, you need code like this to read the database file out of the resources and store it in the file system.
InputStream is = getResources().openRawResource(R.raw.my_db.udb); FileOutputStream os = openFileOutput("my_db.udb", MODE_PRIVATE); byte[] buff = new byte[4096]; int n; for(;;) { n = is.read(buff); if (n < 0) break; os.write(buff, 0, n); }
You need to specify the database file in your configuration, like this:
ConfigFileAndroid config = DatabaseManager.createConfigurationFileAndroid("my_db.udb", this);
Here I have just put the file name, which is the root of your application folder (data/data/com.example.package). If you wish to put the database file in a subfolder you will need to use the path in the call to createConfigurationFileAndroid().
Some people like to use the MobiLink file transfer capability to download the database file on first synchronization, but that is an advanced technique and I wouldn't investigate it until you have everything working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The file path for private files can be obtained as in the following code fragment:
Connection conn; try { ConfigFileAndroid config = DatabaseManager.createConfigurationFileAndroid( getFilesDir().getPath() + File.separator + "my_db.udb", getApplicationContext()); conn = DatabaseManager.connect(config); // ... conn.release(); } catch(ULjException ex) { // ... }
Note that my_db.udb is created in this example as a file that is private to your application, and it is removed when your application is uninstalled. If you want the database to be on external persistent storage, there are ways to do that, but you get the idea anyway.
User | Count |
---|---|
82 | |
29 | |
9 | |
8 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.