ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / Developing for Android
  • Overview
  • Creating an SQLite connection
  • Transferring data from a WINDEV application to an Android application
  • Copying an SQLite database from the PC to the mobile device
  • Copying the SQLite Android database onto the SD Card
  • Transferring SQLite data from an Android application to a WINDEV application
  • SQLite data found in the database directory of the Mobile device
  • SQLite data found on the SD Card of the Mobile device
  • Note: Creating an Android emulator with an SD Card
  • Example
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Warning
This feature is kept for backward compatibility. It is preferable to use an HFSQL database..
Overview
The databases available for Android applications are:
  • HFSQL (Classic and Client/Server),
  • SQLite.
    To use an SQLite database, an SQLite connection must be declared in the data model editor.

Creating an SQLite connection

An SQLite connection can be created:
  • At analysis creation: when you create an analysis for an Android application, the proposed database is either SQLite or HFSQL (Classic or Client/Server). If you select "SQLite", the wizard automatically creates a connection used to manage and access this type of data file. The wizard allows you to enter the advanced parameters of this connection:
    • Name of the file containing the database.
    • Directory of the database.
  • In the data model editor: under "Analysis", in the "Analysis" group, click on "Connections". Simply add a connection to an SQLite database and specify its characteristics.
When the connection is created, you will be able to use all the WLanguage functions for manipulating data files as well as the possibilities of link with the controls.
The SQLite databases ca be accessed from WINDEV or WEBDEV via the Native SQLite Access. Therefore, you have the ability to exchange data between the database of your WINDEV "Back Office" and the mobile database.
Transferring data from a WINDEV application to an Android application

Copying an SQLite database from the PC to the mobile device

When an SQLite data file is created by an Android application, the SQLite database is created in the "/data/data/com.<mycompany>.<projectname>/databases/<base>.db" directory.
This directory is inaccessible from the PC: the Android system does not allow access to this data.
To transfer an SQLite database found on the development computer to an Android device, the database can be added into the apk archive of the application. This operation can be performed when creating the Android archive, in the "Integrating files" screen.
This file can be installed on the Android phone as soon as the application is started by fExtractResource. For example, to install the database in the default directory of Android databases:
fExtractResource("MyPCDatabase.db", CompleteDir(fDataDir()) + "Database.db")

Copying the SQLite Android database onto the SD Card

When an SQLite data file is created by an Android application, the SQLite database is created in the "/data/data/com.<mycompany>.<projectname>/databases/<base>.db" directory.
To ignore this limit, we recommend that you use the SD Card of the mobile device to store the data.
To do so, you must modify the characteristics of the connection used, by specifying the directory of the SD Card. This operation must be performed programmatically. For example:
gcntSQLite is Connection = MyAndroidFile.Connection
gcntSQLite.Source = CompleteDir(SysDirStorageCard()) + "Database.db"
gcntSQLite.Provider = hNativeAccessSQLite
This file will be accessible from the PC when the mobile device is connected to the PC. Therefore, you will be able to perform copies of the database from the PC to the mobile device and vice versa.
Transferring SQLite data from an Android application to a WINDEV application

SQLite data found in the database directory of the Mobile device

If the SQLite data to transfer is found in the default data directory of the Mobile device, the transfer must be performed by the Android application by using HTTTP requests (AWP service), an FTP transfer or via sockets.

SQLite data found on the SD Card of the Mobile device

In this case, all you have to do is copy the SQLite data from the SD Card (visible like a Windows disk) to the PC and include the data in the WINDEV application.

Note: Creating an Android emulator with an SD Card

For your tests, you have the ability to create a SD Card in the Android emulator:
  1. Start a command console window in Windows ("Start .. CMD").
  2. Position yourself in the "tools" directory of the Android SDK used.
  3. Use the following command line (for a SD Card of 256 MB):
    mksdcard.exe 256M c:\temp\sdcard.img
  4. In WINDEV Mobile, when starting the emulator, modify the command line as follows:
    -no-boot-anim –partition-size 128 –sdcard c:\temp\sdcard.img
Example
The following example allows you to use an SQLite database on Android with access to the database from a PC during the connection of the device in USB. The database is stored on the SD Card of the device.
// CntSQLiteDatabase is the name of the connection defined in the analysis
 
// Directories on the SD Card for accessing the SQLite database
sDataDirectory is string
sDataDirectory = "data_wm_androidsqlitedatabasesharepc"
 
// Name of the SQLite database
sNameSQLiteDatabase is string = "wm_sqlitedatabase.db"
 
// Unit corresponding to the SD Card of the Android device
// (from a Windows application)
// To be asked to the user
// and to be stored in a parameter file
sUnitSDCardFromPC is string = "e:"
 
// In any case, the database is in SQLite format
CntSQLiteDatabase.Provider = hNativeAccessSQLite
 
// Execution on the Android device?
IF InAndroidMode() = True THEN
// yes
// WINDEV Mobile simulator?
IF InSimulatorMode() = True THEN
// Database in the Exe directory of the project
CntSQLiteDatabase.Source = fExeDir() + ["\"] + sNameSQLiteDatabase
ELSE
// Execution on the Android device or on the emulator
// There should be a storage card,
// checks whether it is available
IF SysStatusStorageCard() = sysCardAvailable THEN
// Localizes the database on the SD Card,
// in relation to the mobile
CntSQLiteDatabase.Source = SysDirStorageCard() + ["/"] + ...
sDataDirectory + ["/"] + sNameSQLiteDatabase
ELSE
// No storage card
Error("No storage card available in write mode.")
EndProgram()
END
END
ELSE
// Execution on a PC?
IF InAndroidEmulatorMode() = True _OR_ IniOSEmulatorMode = True THEN
Error("No access to the database is provided on this platform")
EndProgram()
ELSE
// IF SysWindowsVersion() IN ("98","NT 3.5","NT 4", ...
// "NT 5","ME", "2003S","2008S","VISTA","7")  THEN
// localizes the database on the SD Card, in relation to the PC
CntSQLiteDatabase.Source = sUnitSDCardFromPC + ["\"] + ...
sDataDirectory + ["\"] + sNameSQLiteDatabase
END
END
 
// Open the connection
IF HOpenConnection(CntSQLiteDatabase) = False THEN
Error("Failure connecting to the SQLite Android database", ...
HErrorInfo())
EndProgram()
END
 
HCreationIfNotFound("*")
 
Info("Connection to the database established")
Related Examples:
Android Inventory Android (WINDEV Mobile): Android Inventory
[ + ] This application is used to perform inventories and to save the results in a database.
WM Attendance Cross-platform examples (WINDEV Mobile): WM Attendance
[ + ] This application is an attendance manager. It allows you to list the persons who attended a meeting.
The database is filled beforehand with the list of registered persons.
You have the ability to find a person by using his/her name.
The following topics are presented in this example:
1/ using a browsing looper based on a query
2/ using a database in HFSQL format.
WM Managing Orders Cross-platform examples (WINDEV Mobile): WM Managing Orders
[ + ] The WM Managing Orders example is a simplified management of orders and invoices.
This example is used to:
- create/modify/delete a product,
- create/modify/delete a customer,
- contact a customer by email,
- see the history of the actions performed for a customer
- place an order, print an order form,
- invoice an order, print an invoice.
WM Password Cross-platform examples (WINDEV Mobile): WM Password
[ + ] Web sites, bank accounts, ... passwords are everywhere in out life. With WM Password, no need to store all the passwords of your different accounts. The application stores all your passwords in a secure way. WM Password can also generate secure passwords for you.
WM Notes Cross-platform examples (WINDEV Mobile): WM Notes
[ + ] This example is using the drawing functions of WLanguage for Android and iOS.
It allows you to draw graphic "notes" and to save them.
WM Sports Cross-platform examples (WINDEV Mobile): WM Sports
[ + ] This example is a sport application used to save your performances.
The application calculates the distance, the time, the average speed and the number of calories spent according to the sport.
The run is displayed on a map control via markers and an itinerary.

The example also includes a server part used to synchronize the user data.
This webservice is available in the WEBDEV "WW_Sports" example.
WM Stocks Cross-platform examples (WINDEV Mobile): WM Stocks
[ + ] This application is used to perform stocktaking and to save the results in a database.
The example is used to create entries/exits in the stock, by directly scanning the bar code of products.
It is optimized to be run on tablets.
Minimum version required
  • Version 16
Comments
Click [Add] to post a comment

Last update: 10/17/2024

Send a report | Local help