Android offline application permission application and SQLite management data method and electronic equipment
By building the project dependency environment and encapsulating database operation tools, the problems of repeated triggering and complex operations in permission requests and SQLite management in Android offline applications were solved. This resulted in improved success rates for intelligent permission requests and database file synchronization, increased development efficiency, and ensured application stability and data availability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUASHU (ZHEJIANG) TECH CO LTD
- Filing Date
- 2026-04-15
- Publication Date
- 2026-06-23
Smart Images

Figure CN122020695B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method for permission request and SQLite data management in an Android offline application, as well as an electronic device. Background Technology
[0002] With the widespread adoption of mobile offline applications in scenarios such as government verification, on-site inspections, and medical follow-ups, stable storage and efficient management of local data have become core requirements for these applications. Offline applications need to store business data such as forms, records, and configuration information in a local SQLite database in an environment without network access. At the same time, they need to obtain device storage permissions to complete the reading, copying, and initialization operations of database files to ensure the normal operation of the application.
[0003] Uniapp, as a mainstream cross-platform development framework, can quickly build offline applications adapted to Android and iOS systems, significantly reducing cross-platform development costs. However, in practical applications, existing technologies have significant shortcomings in the linkage between "permission request - SQLite database management": Uniapp's native permission request interface lacks intelligent judgment logic, which is prone to duplicate triggering issues; SQLite database operations require developers to encapsulate complex logic such as path adaptation and pagination queries; and the database file synchronization process is easily affected by factors such as device system differences and path permission restrictions, leading to synchronization failures.
[0004] Currently, in offline application permission and SQLite management solutions, permission requests are often disconnected from the database initialization process, easily leading to failure scenarios such as "database operations being performed without granted permissions." Furthermore, SQLite pagination queries require manually writing two redundant SQL statements: "list query" and "total record count." When switching between development and production environments, the database source path configuration needs to be manually modified. These issues all result in poor application stability, low development efficiency, and an inability to meet the core requirements of offline applications for data availability and operational efficiency. Summary of the Invention
[0005] To achieve intelligent permission request, stable database synchronization, and efficient operation, this application provides a method for permission request and SQLite data management in an Android offline application, as well as an electronic device.
[0006] Firstly, this application provides a method for permission request and SQLite data management in an Android offline application, employing the following technical solution:
[0007] A method for permission request and SQLite data management in an Android offline application includes the following steps:
[0008] Build the project dependencies and configure the scaffolding tools;
[0009] Create a framework project locally based on the scaffolding tool and import the basic development library;
[0010] Add the storage permission configuration corresponding to the current platform to the application configuration file in the framework project. The storage permission configuration includes at least read permission configuration and write permission configuration.
[0011] Add a route configuration for the permission request page to the page configuration file in the framework project, and set the permission request page as the first application loading page based on the route configuration;
[0012] The framework project encapsulates database operation tools and defines basic database configuration information;
[0013] Integrate database operation logic into the permission request page;
[0014] The encapsulated database operation tool is invoked to perform paginated queries and single data queries in order to read local data and render the page;
[0015] The framework project is compiled into an application installation package corresponding to the current platform using the compilation and execution tools, and the application installation package is run and verified.
[0016] In some embodiments, building the project dependency environment and configuring the scaffolding tools includes the following steps:
[0017] Install the runtime environment and install the scaffolding tools based on the package management commands configured in the runtime environment;
[0018] Install the compilation and runtime tools to enable the development plugins corresponding to the current platform;
[0019] Configure the simulator corresponding to the current platform or connect to the physical device corresponding to the current platform.
[0020] In some embodiments, creating a framework project locally based on the scaffolding tool and importing the underlying development library includes the following steps:
[0021] Obtain the project build instructions and select a preset template to execute;
[0022] Navigate to the root directory of the framework project and execute the package management command to download and install the basic dependency packages and style preprocessing libraries corresponding to the framework project.
[0023] In some embodiments, adding storage permission configurations corresponding to the current platform to the application configuration file of the framework project includes the following steps:
[0024] Locate the application configuration file in the root directory and open the source code view;
[0025] Based on the source code view, locate the platform configuration node and add a configuration array to the platform configuration node;
[0026] Write the configuration codes corresponding to the read permission configuration and the write permission configuration into the configuration array;
[0027] When the device version corresponds to a higher system version, add an external storage access compatibility parameter to the platform configuration node.
[0028] In some embodiments, a route configuration for the permission request page is added to the page configuration file in the framework project, and the permission request page is set as the first application loading page based on the route configuration, including the following steps:
[0029] Locate the page configuration file in the root directory, and add the permission request route corresponding to the permission request page to the first position of the page array in the page configuration file. The permission request route includes the first page path and the first page title.
[0030] An application homepage route is added after the permission request route in the page array. The application homepage route includes a second page path and a second page title.
[0031] In some embodiments, the database operation tools are encapsulated and basic database configuration information is defined within the framework project, including the following steps:
[0032] Create a new tool file in the source code directory of the framework project, and add the database basic configuration information to the tool file. The database basic configuration information includes the database name, the database source file path, and the database target file path.
[0033] The database operation tool is encapsulated by several database operation methods, and based on the database operation tool, database opening, single data query, paginated query, cross-environment path adaptation, and database file copying are implemented.
[0034] In some embodiments, database operation logic is integrated into the permission request page, including the following steps:
[0035] Add a status variable to the permission request page; the status variable is used to indicate whether the permission request is being executed.
[0036] Add triggering logic to the permission request page. Under the triggering logic, if the status variable is false, set it to true and call the permission request method to request storage permission by passing in the permission identifier.
[0037] Obtain the return result corresponding to the permission request on the permission request page, and generate a corresponding prompt message based on the return result;
[0038] On the permission request page, determine whether an old file exists in the target file path of the database; if so, delete it.
[0039] If not, copy the source file to the target directory in the database source file path and monitor the copying results;
[0040] If the copy is successful, the user will be redirected to the application's homepage; if the copy fails, the error message will be logged and displayed.
[0041] In some embodiments, the encapsulated database operation tool is invoked to perform paginated queries and single-data queries to achieve local data reading and page rendering, including the following steps:
[0042] Call the pagination query function in the database operation tool to return the current page data and the total number of data entries;
[0043] Call the basic query function in the database operation tool to return a single piece of specific configuration data.
[0044] In some embodiments, the framework project is compiled into an application installation package corresponding to the current platform using a compilation and execution tool, and the application installation package is run and verified, including the following steps:
[0045] Select the framework project using the compilation and execution tool, run it, compile the framework project into the corresponding application installation package, and deploy it to the test environment;
[0046] After the application starts, verify whether the permission request page pops up on the first launch and whether the return result received based on the permission request page matches the prompt information;
[0047] A query operation is triggered on the application homepage to verify whether the data can be read and correctly rendered on the application homepage.
[0048] Switch the test environment to the development environment and the production environment respectively to verify whether the database source file path switches automatically.
[0049] Secondly, this application provides an electronic device that adopts the following technical solution:
[0050] An electronic device includes: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors perform the method described above.
[0051] The technical solutions provided by the embodiments of this application have the following technical effects:
[0052] To resolve issues such as repeated permission requests and unclear guidance after users deny permissions, the permission request logic has been optimized to improve user experience.
[0053] To resolve synchronization issues caused by device differences, path permissions, etc. during database file synchronization, and ensure that offline data is loaded normally;
[0054] This solution addresses the issues of repetitive SQL code writing and low development efficiency and data instability caused by the lack of database connection state management in SQLite database list pagination queries, simplifies query logic, and improves operational reliability.
[0055] This solution addresses the issue of manually modifying database path configurations in both development and production environments, enabling automatic cross-environment matching to reduce development and maintenance costs. Attached Figure Description
[0056] Figure 1 This is a schematic diagram illustrating the steps of a method for requesting permissions and managing data using SQLite in an Android offline application, as provided in this embodiment. Detailed Implementation
[0057] To better understand the purpose, technical solutions, and advantages of this application, it has been described and illustrated below with reference to the accompanying drawings and embodiments. However, those skilled in the art should understand that this application can be implemented without these details. In some cases, to avoid obscuring various aspects of this application due to unnecessary description, well-known methods, processes, systems, components, and / or circuits already described at a higher level will not be elaborated upon. It will be apparent to those skilled in the art that various modifications can be made to the embodiments disclosed in this application, and the general principles defined in this application can be applied to other embodiments and application scenarios without departing from the principles and scope of this application. Therefore, this application is not limited to the illustrated embodiments, but conforms to the broadest scope consistent with the scope of protection claimed in this application.
[0058] It should be noted that the descriptions of these embodiments are for the purpose of aiding understanding the present invention, but do not constitute a limitation thereof. Furthermore, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0059] In the description of this application, "several" means one or more, "more than" means two or more, "greater than," "less than," and "exceeding" are understood to exclude the stated number, while "above," "below," and "within" are understood to include the stated number. The use of "first" and "second" in the description is merely for distinguishing technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the order of the indicated technical features.
[0060] In the description of this application, the terms "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any one or more embodiments or examples.
[0061] like Figure 1 As shown in the figure, this application discloses a method for permission request and SQLite data management in an Android offline application, including the following steps:
[0062] S100 builds the project dependency environment and configures the scaffolding tools.
[0063] This step is used to build a complete environment for the development, compilation, running and testing of the Uniapp project locally. Uniapp is a cross-platform development framework that uses Vue.js syntax and the target code supports programming to platforms such as iOS, Android, and HarmonyOS.
[0064] This step provides foundational support for subsequent development processes, ensuring the project can proceed smoothly. It includes installing the corresponding runtime environment and scaffolding tools on the local device to build the necessary dependencies; downloading and installing compilation and runtime tools; and configuring an Android emulator or connecting a physical Android device for subsequent project testing and verification.
[0065] Specifically, it includes the following steps:
[0066] S110, installs the runtime environment and installs the scaffolding tools based on the package management commands configured in the runtime environment.
[0067] Select and install the JavaScript runtime environment Node.js. In this application, version v14 or above is used. Ensure that it supports the corresponding version of the scaffolding tool vue.cli and meets the installation and running requirements of the project's dependencies.
[0068] To install the vue.cli scaffolding tool globally, execute `npm install -g@vue / cli` in the terminal using the package manager command that comes with the Node.js JavaScript runtime environment. The vue.cli scaffolding tool is used to quickly create framework projects.
[0069] vue.cli is an official Vue.js toolchain based on Webpack, used to quickly build Vue projects, supporting interactive scaffolding, zero-configuration prototyping, and plugin extensions.
[0070] S120, install the compilation and runtime tools to enable the development plugins corresponding to the current platform.
[0071] Download and install HBuilder or HBuilderX. HBuilder or HBuilderX is a dedicated compilation and execution tool for uniapp projects. Enable the Android development environment plugin in the compilation and execution tool to ensure that the tool can compile the Uniapp project into an installation package that can be run on the installation platform, that is, an APK format installation package.
[0072] S130: Configure the simulator corresponding to the current platform or connect to the physical device corresponding to the current platform.
[0073] Configure an Android emulator or connect a physical Android device. If using a physical device, you need to enable "Developer Mode" and "USB Debugging" on the device to ensure that the HBuilder compilation and runtime tool can correctly recognize the device and complete the application deployment and runtime testing.
[0074] S200 is based on scaffolding tools to create framework projects locally and import basic development libraries.
[0075] The core purpose of this step is to complete project initialization and basic dependency configuration. Using scaffolding tools, a Uniapp framework project is created locally, and the basic development libraries required for offline application development are downloaded and imported to support subsequent component development, style writing, and database operations.
[0076] Specifically, it includes the following steps:
[0077] S210: Obtain project build instructions and select a preset template to execute.
[0078] Open the terminal and execute the command `vue create -p dcloudio / uni-preset-vue uniapp-offline-db`. This command is used to build a Uniapp project, where `uniapp-offline-db` is a custom project name.
[0079] During project creation, you need to select a preset template. The template can be the default template or a blank template. Select the one that best suits your needs. Select the preset template and execute it to complete the project initialization.
[0080] S220, enter the root directory of the framework project and execute the package management command to download and install the basic dependency packages and style preprocessing library corresponding to the framework project.
[0081] Execute the command `cd uniapp-offline-db` to enter the root directory of the framework project, and then execute the command `npm install`. This command is a package management command used to download and install the basic dependency packages of the Uniapp project.
[0082] To meet the preprocessing requirements of component styles, execute `npm install sass sass-loader --save-dev` in the project root directory to install Sass and the Sass library to support subsequent style writing.
[0083] Sass is a continuously evolving CSS preprocessor language that uses SassScript to implement features such as variable definition, nested rules, and mixins. Sass also has a rich library of enabling components, including variable storage, absolute centering, setting delayed execution time, rounded corners, setting transitions, and setting keyframes.
[0084] Meanwhile, in this embodiment, there is no need to download the SQLite (Structured Query Language database) dependencies separately, because the Uniapp framework has a built-in cross-platform runtime database module plus.sqlite. This module runs on the 5+ Runtime environment and can be directly used for SQLite database connection, query and other operations.
[0085] S300, add the storage permission configuration corresponding to the current platform to the application configuration file in the framework project. The storage permission configuration includes at least read permission configuration and write permission configuration.
[0086] The core purpose of this step is to declare the storage permissions required by the Android platform in the framework project, ensuring that the application can normally request read and write permissions to external storage at runtime, thus laying the foundation for database file operations.
[0087] Specifically, it includes the following steps:
[0088] S310, locate the application configuration file in the root directory and open the source code view.
[0089] Locate and open the manifest.json configuration file in the root directory. This configuration file is the application configuration file. When opened, it is in source code view mode. Source code refers to the original version file used to generate the final executable program. Source code contains all the instructions, such as syntax and variables used in a specific programming language. It constitutes the core part of the application and provides the basic logical framework for the program. Source code view refers to tools or functions that can see the underlying source code, debuggers, or decompilers. Through source code view, vulnerabilities and defects in the program can be discovered.
[0090] S320 locates the platform configuration node based on the source code view and adds a configuration array to the platform configuration node.
[0091] Based on the source code view, locate and execute "distribute": {"android": {}} to find the Android configuration node under the distribution configuration object, and add a permission configuration array "permissions" under the Android node. The permission configuration array is used to add the configuration code corresponding to the storage permissions.
[0092] S330 writes the configuration code corresponding to the read permission configuration and write permission configuration into the configuration array.
[0093] Specifically, the configuration code written is as follows:
[0094] json
[0095] "permissions": [
[0096] " <uses-permission android:name="\"android.permission.READ_EXTERNAL_STORAGE\" / "> ",
[0097] " <uses-permission android:name="\"android.permission.WRITE_EXTERNAL_STORAGE\" / ">"].
[0098] These represent the codes corresponding to read external storage permissions and write external storage permissions, respectively, thus clearly informing the system application of the required storage permissions.
[0099] S340, when the device version corresponds to a higher system version, add external storage access compatibility parameters in the platform configuration node.
[0100] For devices with Android version 10 and above, you also need to configure traditional external storage access in the android node (Android platform configuration node) of the platform configuration node: "android:requestLegacyExternalStorage": "true". This permission code represents the compatibility parameter corresponding to traditional external storage access, so as to ensure that the application can access the traditional external storage path normally and avoid database files being unable to be read due to system permission restrictions.
[0101] S400 adds a route configuration for the permission request page in the page configuration file of the framework project, and sets the permission request page as the first application loading page based on the route configuration.
[0102] The core purpose of this step is to set the permission request page as the first page when the application starts, ensuring that permission requests and database initialization are completed first when the application starts, thus preventing core functions from failing to run due to missing permissions.
[0103] By adding a route configuration for a permission request page (named the permission page) in the pages.json file of the Uniapp project, and setting this page as the first page loaded after the application starts, it ensures that permission request and database initialization operations are completed first when the application starts.
[0104] In step S400, the corresponding configuration code is:
[0105] json
[0106] "pages": [
[0107] {
[0108] "path": "pages / permission / permission",
[0109] "style": {
[0110] "navigationBarTitleText": "Permission Request"
[0111] }
[0112] },
[0113] {
[0114] "path": "pages / index / index",
[0115] "style": {
[0116] "navigationBarTitleText": "Application Home Page"
[0117] }
[0118] }]
[0119] Specifically, it includes the following steps:
[0120] S410 locates the page configuration file in the root directory and adds the permission request route corresponding to the permission request page to the first position of the page array in the page configuration file. The permission request route includes the first page path and the first page title.
[0121] First, locate the page configuration array `pages` in the `pages.json` file under the uniapp project. This array is used to manage the routing information of all pages in the application.
[0122] Add the route configuration for the permission request page (permission page) to the pages configuration array. The configuration content includes the page path ("pages / permission / permission") and the page title ("navigationBarTitleText": "Permission Request").
[0123] At the same time, ensure that the permission request page is listed first in the page configuration array. This is because the Uniapp framework's routing mechanism dictates that the application will load the page path corresponding to the first element in this array by default upon startup, thus ensuring the permission request process begins immediately upon application launch. The homepage and other business pages should then be listed in order.
[0124] S420 adds an application homepage route after the permission request route in the page array. The application homepage route includes the second page path and the second page title.
[0125] Add a route configuration for the application homepage (index page) after the permission request page route. The path is pages / index / index, and the page title is "Application Homepage". This will be used to redirect to the application homepage after the permission request is approved.
[0126] S500 encapsulates database operation tools and defines basic database configuration information within the framework project.
[0127] The purpose of this step is to encapsulate operations such as connection, query, pagination, and file copying of the Structured Query Language database SQLite into a unified utility class, which simplifies the development process and improves operational reliability and cross-environment adaptability.
[0128] This step involves creating a database operation tool file named dbapi.js in the JavaScript script directory src / js within the framework project's source code directory. The file encapsulates the core operation methods of the SQLite database, including database connection management, data query, pagination processing, file copying, etc. It also defines a cross-environment adapted database path, providing a unified SQLite operation entry point for the entire application.
[0129] Specifically, it includes the following steps:
[0130] S510, create a new tool file in the source code directory of the framework project, and add basic database configuration information to the tool file. The basic database configuration information includes the database name, the path of the database source file, and the path of the database target file.
[0131] Define the core database configuration in the newly created database operation tool file dbapi.js, including the database name (e.g., sqlName: "gjss"), the database source file path (e.g., dbSrcPath:'file: / / / data / userdata / gjss.db'), and the database target file path (e.g., dbDestPath:'_doc / gjss.db').
[0132] The database source file path is the original storage path corresponding to the database file. In the development environment, it is convenient for developers to manually replace and update the database file during the debugging phase (such as directly putting the test gjss.db file into the root directory of the SD card). The effect of different database data can be quickly verified without modifying the code, which improves the frequency of development and debugging. In the production environment, it serves as the original storage location of the database file and usually stores the basic data required for application initialization (such as basic configuration, initial form templates, etc.). It provides a data source for the database file copying operation and ensures that the application can obtain the initial complete database file.
[0133] The database target file path represents the database file storage path accessible to the application. The doc directory is the Uniapp application's private accessible directory. The Android system has lower read and write permission restrictions on this directory, which can avoid the problem of database files becoming inaccessible due to changes in external storage permissions, ensuring that the application can stably read the database. The unified read and write path simplifies the subsequent SQLite database operation logic. Developers do not need to distinguish the source path differences in different environments and can directly perform database queries, updates, and other operations through this path. By copying the database file from the source path to this path, it is ensured that the application can obtain the complete initial database when it starts, avoiding database initialization failures due to source path permission restrictions or missing files.
[0134] The S520 encapsulates a database operation tool consisting of several database operation methods, and implements database opening, single data query, paginated query, cross-environment path adaptation, and database file copying based on the database operation tool.
[0135] The `openDB()` method encapsulates the database opening functionality. Its core logic is as follows: it checks if the database is already open by calling the cross-platform runtime database connection check method `plus.sqlite.isOpenDatabase()`. If not, it executes `plus.sqlite.openDatabase()` to open the database; otherwise, it returns a success status directly, eliminating the need for repeated connections. Therefore, the database opening operation is only performed when database operation tools determine that the database is not open, avoiding resource waste caused by repeated connections.
[0136] The basic data query method `selectSQL(sql)` is encapsulated to query single data on the page. This method receives an SQL statement as a parameter and calls the database query method `plus.sqlite.selectSql()` to execute the query operation. It also encapsulates asynchronous processing logic for asynchronous processing objects (Promises) to achieve asynchronous return of query results.
[0137] During the query process, the Uniapp framework is used to load and display the loading results using the uni.showLoading() method, and query errors are handled using the uni.showToast() method, improving user experience and troubleshooting efficiency.
[0138] The `selectPageList(sql)` method encapsulates a pagination query. Its core logic is as follows: it uses regular expressions to match fields in the original pagination SQL statement, automatically converting them into a SQL statement that counts the total number of rows (e.g., `select count() as count from ...`), and automatically removes the `LIMIT` condition and `OFFSET` parameter from the original statement. Finally, it uses asynchronous processing objects (Promises) to execute the "current page data SQL query" and the "total row count SQL query" simultaneously, reducing database interactions and improving pagination query efficiency.
[0139] Cross-environment path adaptation is characterized by automatically switching paths by judging the system environment variable process.env.NODE_ENV used to distinguish between development and production environments: In the development environment, the database source path is automatically switched to the root directory of the SD card ( / sdcard / gjss.db), which is convenient for manually replacing the database file during debugging; In the production environment, the system's private directory path (such as _doc) is used to ensure data security without requiring developers to manually modify the path configuration.
[0140] The `copyDB()` method encapsulates the database file copying functionality. Its core logic is as follows: it uses the Uniapp framework's `uni.getFileInfo()` method to determine if the database file already exists on the target path. If not, it calls the file path resolution method `plus.io.resolveLocalFileSystemURL()` to resolve the source and target paths respectively. Then, it uses the `copyTo()` method to copy the database file to the target path, ensuring that the database file can be accessed normally by the application and resolving database initialization failures caused by path permissions or missing files.
[0141] S600 integrates database operation logic into the permission application page.
[0142] The core purpose of this step is to integrate the logic of permission application, result processing, and database file synchronization (deleting old files and copying new files) into the permission application page, so as to ensure that the database initialization is reliably completed after permissions are granted.
[0143] Specifically, it includes the following steps:
[0144] S610, add a status variable to the permission request page. The status variable is used to indicate whether the permission request is being executed.
[0145] This step is used to define a state variable to prevent duplicate operations. Specifically, a new state variable isProcessing is added to the data() method of the data source on the permission request page. This flag is used to mark whether the permission request process is being executed, so as to avoid the page displaying the onShow lifecycle repeatedly triggering permission requests.
[0146] S620: Add trigger logic to the permission request page. Under the trigger logic, if the status variable is false, set it to true and call the permission request method to request storage permission by passing in the permission identifier.
[0147] The operation logic corresponding to this page is to trigger a permission request upon page launch. The logic is added to the onShow function throughout the entire lifecycle of the page: first, check if the state variable isProcessing is false (i.e., no permission request process is being executed). If it is, set it to true to lock the process, and call the permission request method plus.android.requestPermissions() under the Android platform to request storage permissions, passing in two permission identifiers: "read external storage" and "write external storage", and triggering a permission request pop-up.
[0148] S630 retrieves the return result corresponding to the permission request on the permission request page and generates the corresponding prompt information based on the return result.
[0149] This step is used to uniformly process permission request results. The `handlePermissionResult(e)` method is implemented to categorize and process the results based on the corresponding permission requests. Specifically...
[0150] If the result returned under the permission request is e.deniedAlways.length > 0, it means that the permission is permanently denied. In this case, the message method showPermissionToast() is called to inform the user that "You have denied the permission. Please enable it in the settings" and guide the user to resolve the permission issue. If the result returned is e.deniedPresent.length > 0, it means that the permission is temporarily denied. In this case, the user is prompted that "You have denied the permission. If you restart the app, you will be able to request it again" to preserve the opportunity to request it later. If the result returned is e.granted.length > 0, it means that the permission is granted. In this case, a loading prompt such as "Synchronizing data, please wait" is displayed, and the subsequent old file deletion method deleteFile() is called to start the database file synchronization process.
[0151] Through the database operation logic described above, the return results of Android platform permission requests are received and processed in a unified manner. Different logic is executed according to different permission statuses (allow / temporarily deny / permanently deny) to ensure that the permission status is linked with subsequent database operation processes.
[0152] Here, parameter 'e' is the result object returned by the Android permission request interface, which contains three core attributes: granted (an array of granted permissions), deniedPresent (an array of temporarily denied permissions), and deniedAlways (an array of permanently denied permissions).
[0153] In existing technologies, permission requests lack intelligent judgment logic, which easily leads to repeated permission requests, frequently disturbing users and causing a decline in user experience. At the same time, when users deny permissions, there is a lack of clear guidance process (such as guiding users to manually enable permissions), causing core application functions (such as database read and write) to fail to operate normally due to the lack of permissions.
[0154] By introducing the isProcessing state lock mechanism through the method described in this application, the problem of repeated permission requests being triggered when switching Uniapp pages is completely solved, avoiding multiple permission pop-ups from disturbing users. At the same time, differentiated guidance prompts are provided for the two scenarios of "permanent denial" and "temporary denial", so that users can clearly know the path to solve permission problems. The success rate of resolving permission problems is increased by more than 80%, ensuring the availability of core functions such as database operations.
[0155] S640: On the permission request page, check if the old file exists in the target file path of the database. If so, delete it.
[0156] S650, if not, copy the source file to the target directory in the database source file path and monitor the copying results.
[0157] If the copy is successful on the S660, the user will be redirected to the application's homepage; if the copy fails, the error message will be logged and displayed.
[0158] When permissions are granted, the `deleteFile()` method for deleting old files is implemented. The core logic is as follows: the target file path in the database is resolved using the file path resolution method `plus.io.resolveLocalFileSystemURL()`. If an old file exists in the path, the `entry.remove()` method is called to delete the old file. At this point, regardless of whether the deletion is successful or not, the `resolveLocalFile()` method for resolving the target path is triggered to perform subsequent copy operations for fault tolerance. Fault tolerance is to avoid blocking the process due to the failure to delete the old file. When it is found that the old file does not exist in the path after resolution, the `resolveLocalFile()` method for resolving the target path is directly called to perform the copy operation.
[0159] By using the above method, the old database files under the target path are preprocessed to prevent database read / write anomalies caused by conflicts between old and new files, thus clearing obstacles for copying new files.
[0160] The copy operation is executed based on the file copy trigger method `resolveLocalFile()`. The core logic is as follows: first, the source path of the database, `DBApi.dbSrcPath`, is resolved; if resolution is successful, the target directory is then resolved. Once the target directory is successfully resolved, the file copy method `entry1.copyTo(entry2, "gjss.db")` is called to copy the source file to the target directory. This method is characterized by resolving the database source file path to obtain the source file target `entry1`, resolving the application's private directory to obtain the target directory object `entry2`, copying the source file to the target directory, and renaming it to the database filename.
[0161] Furthermore, the replication results are monitored, and different methods are invoked to provide prompts when the replication result is successful or unsuccessful.
[0162] When the copying result is successful, hide the loading prompt and redirect to the application homepage via the page redirection method uni.redirectTo() in the Uniapp framework. If the copying result fails, call the copy error handling method handleCopyError() to log the error and notify the user.
[0163] In existing technologies, during the local synchronization of database files (such as SQLite files), the differences in file systems, path permission restrictions, and whether the file already exists on different devices are not fully considered. This may lead to synchronization failures (such as path resolution errors or copying interruptions), causing offline applications to be unable to load initial data normally, affecting application startup and data availability.
[0164] In this embodiment, a three-level fault-tolerant process of "old file processing - path resolution - copy execution" is designed: when deleting old files, the subsequent copy operation continues to be executed regardless of success or failure; when path resolution fails, the exception is captured in time and a clear prompt is displayed to the user, ensuring that the database synchronization success rate is increased from 60% in the prior art to more than 95% on devices with different Android system versions (such as Android 9 / 10 / 11) and different file system permissions, effectively avoiding the problem of "no data available" for the application due to synchronization failure.
[0165] Furthermore, this embodiment also includes unified handling of copying errors. It captures errors during path resolution and file copying by calling the error handling method `handleCopyError(message, error)`, records error information in the console log, and displays error messages to the user using the aforementioned message prompting method, ensuring the application does not crash in abnormal scenarios. Here, `message` is a custom error description (e.g., "Source path resolution failed"), and `error` is the native error object returned by the interface.
[0166] Furthermore, database file copying can use Uniapp's cross-platform file copying method uni.copyFile() to replace the path resolution + file copying combination scheme in this application. The cross-platform file copying method uni.copyFile() has a simpler syntax and fewer calling steps. However, the plus.io related methods in this application can handle path resolution exceptions (such as "file does not exist" or "insufficient permissions") at a lower level, which is more fault-tolerant and more suitable for copying core resources such as database files.
[0167] S700 calls the encapsulated database operation tools to perform paginated queries and single data queries to achieve local data reading and page rendering.
[0168] The core purpose of this step is to call the encapsulated database utility class in the business page to realize local data query and page rendering, and complete the linkage between business logic and data operation.
[0169] Specifically, it includes the following steps:
[0170] S710 calls the pagination query function in the database operation tool to retrieve the current page data and the total number of data entries.
[0171] First, you need to import the database operation utility class DBApi in the script section of the application homepage index.vue and other business pages using the import statement import DBApi from "@ / js / dbapi.js" to obtain database operation capabilities.
[0172] By following the steps above, business pages can obtain a unified database operation interface, eliminating the need to repeatedly write underlying logic such as database connections and queries, thus improving code reusability.
[0173] Calling the pagination query method DBApi.selectPageList("select * fromuser limit 10 offset 0") of the database utility class (passing in a pagination SQL statement with LIMIT and OFFSET, such as querying page 1 with 10 user records per page) will return a result object containing "current page data (rows)" and "total number of data (total)". This object can be directly used to render business tables and pagination controls without having to manually write the total number of records query statement.
[0174] S720 calls the basic query function in the database operation tool to return a single piece of specific configuration data.
[0175] Call the basic query method DBApi.selectSQL("select * from configwhere id = 1") of the database utility class to retrieve specific configuration data for page initialization and business logic judgment, simplifying the single data query process.
[0176] In existing technologies, developers need to manually write repetitive code to handle SQLite pagination query logic (such as writing separate SQL statements to query the list of data and the total number of records, and handling the LIMIT and OFFSET syntax). This makes the development experience cumbersome and error-prone. At the same time, the lack of unified management of database connection status may lead to query failures or wasted resources, affecting the efficiency of data operation.
[0177] This application can automatically convert pagination query SQL statements into "total number of records query SQL statements" through the selectPageList() method, eliminating the need for developers to manually write redundant SQL code and reducing a large amount of repetitive coding work. At the same time, the openDB() method will automatically determine the database connection status to avoid resource leaks caused by repeatedly opening the database.
[0178] Furthermore, in some other embodiments, an optional database connection release operation is also included.
[0179] In the page's hidden lifecycle method onHide() or unload lifecycle method onUnload(), call the database utility class's close method DBApi.closeDB() to close the database connection, release system resources, and avoid resource leaks.
[0180] The S800 uses a compilation and execution tool to compile the framework project into an application installation package corresponding to the current platform, runs the application installation package, and verifies it.
[0181] The core purpose of this step is to verify the integrity and stability of the entire technical process through actual operation testing, and to ensure that the core functions are implemented normally.
[0182] Specifically, it includes the following steps:
[0183] On the S810, the framework project is selected and run using the compilation and execution tool, which compiles the framework project into the corresponding application installation package and deploys it to the test environment.
[0184] First, select the project using the HBuilder compiler and run tool, then click "Run" - "Run to Phone or Emulator," select the connected Android device or the launched Android emulator, compile the project into an Android application, and deploy it to the test environment.
[0185] S820: After the application starts, verify whether a permission request page pops up on the first launch and whether the return result received from the permission request page matches the prompt message.
[0186] After the application starts, verify whether the pop-up page that appears on the first launch is the pop-up window corresponding to the permission request page, and test the three scenarios of "permanently deny", "temporarily deny" and "allow" permissions by the user to confirm whether the corresponding guidance prompts or jump logic can be executed normally.
[0187] S830 triggers a query operation on the application homepage to verify whether the data can be read and correctly rendered on the application homepage.
[0188] Trigger a business data query operation on the application homepage or other business pages to confirm that data can be read from the SQLite database and rendered correctly on the page, with no query failures or data anomalies.
[0189] S840 switches the test environment to the development environment and the production environment respectively to verify whether the database source file path is automatically switched.
[0190] Run the project in both the development and production environments to confirm that the database source path can be switched automatically (using the SD card root directory in the development environment and the system private directory in the production environment) without requiring manual configuration changes, and that the database files can be read and manipulated normally.
[0191] This application also discloses an electronic device including one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors perform the method described above.
[0192] The implementation principle is as follows:
[0193] To resolve issues such as repeated permission requests and unclear guidance after users deny permissions, the permission request logic has been optimized to improve user experience.
[0194] To resolve synchronization issues caused by device differences, path permissions, etc. during database file synchronization, and ensure that offline data is loaded normally;
[0195] This solution addresses the issues of repetitive SQL code writing and low development efficiency and data instability caused by the lack of database connection state management in SQLite database list pagination queries, simplifies query logic, and improves operational reliability.
[0196] This solution addresses the issue of manually modifying database path configurations in both development and production environments, enabling automatic cross-environment matching to reduce development and maintenance costs.
[0197] It should be understood that although the steps in the flowcharts in the accompanying drawings are shown sequentially as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Unless otherwise expressly stated herein, there is no strict order in which these steps are performed, and they may be performed in other orders.
[0198] The above are all preferred embodiments of this application, and are not intended to limit the scope of protection of this application. Therefore, all equivalent changes made in accordance with the structure, shape and principle of this application should be covered within the scope of protection of this application. < / uses-permission>
Claims
1. A method for permission request and SQLite data management in an Android offline application, characterized in that, Includes the following steps: Build the project dependencies and configure the scaffolding tools; Create a framework project locally based on the scaffolding tool and import the basic development library; Add the storage permission configuration corresponding to the current platform to the application configuration file in the framework project. The storage permission configuration includes at least read permission configuration and write permission configuration. Add a route configuration for the permission request page to the page configuration file in the framework project, and set the permission request page as the first application loading page based on the route configuration; The framework project encapsulates database operation tools and defines basic database configuration information; Integrate database operation logic into the permission request page; The encapsulated database operation tool is invoked to perform paginated queries and single data queries in order to read local data and render the page; The framework project is compiled into an application installation package corresponding to the current platform using the compilation and execution tools, and the application installation package is run and verified.
2. The method for permission request and SQLite data management in an Android offline application according to claim 1, characterized in that, Building the project's dependencies and configuring the scaffolding tools includes the following steps: Install the runtime environment and install the scaffolding tools based on the package management commands configured in the runtime environment; Install the compilation and runtime tools to enable the development plugins corresponding to the current platform; Configure the simulator corresponding to the current platform or connect to the physical device corresponding to the current platform.
3. The method for permission request and SQLite data management in an Android offline application according to claim 2, characterized in that, Creating a framework project locally based on the scaffolding tool and importing the basic development library includes the following steps: Obtain the project build instructions and select a preset template to execute; Navigate to the root directory of the framework project and execute the package management command to download and install the basic dependency packages and style preprocessing libraries corresponding to the framework project.
4. The method for permission request and SQLite data management in an Android offline application according to claim 3, characterized in that, Add the storage permission configuration corresponding to the current platform to the application configuration file of the framework project, including the following steps: Locate the application configuration file in the root directory and open the source code view; Based on the source code view, locate the platform configuration node and add a configuration array to the platform configuration node; Write the configuration codes corresponding to the read permission configuration and the write permission configuration into the configuration array; When the device version corresponds to a higher system version, add an external storage access compatibility parameter to the platform configuration node.
5. The method for permission request and SQLite data management in an Android offline application according to claim 4, characterized in that, Add a route configuration for the permission request page to the page configuration file of the framework project, and set the permission request page as the first application loading page based on the route configuration, including the following steps: Locate the page configuration file in the root directory, and add the permission request route corresponding to the permission request page to the first position of the page array in the page configuration file. The permission request route includes the first page path and the first page title. An application homepage route is added after the permission request route in the page array. The application homepage route includes a second page path and a second page title.
6. The method for permission request and SQLite data management in an Android offline application according to claim 1, characterized in that, The framework project encapsulates database operation tools and defines basic database configuration information, including the following steps: Create a new tool file in the source code directory of the framework project, and add the database basic configuration information to the tool file. The database basic configuration information includes the database name, the database source file path, and the database target file path. The database operation tool is encapsulated by several database operation methods, and based on the database operation tool, database opening, single data query, paginated query, cross-environment path adaptation, and database file copying are implemented.
7. The method for permission request and SQLite data management in an Android offline application according to claim 6, characterized in that, Integrating database operation logic into the permission request page includes the following steps: Add a status variable to the permission request page; the status variable is used to indicate whether the permission request is being executed. Add trigger logic to the permission request page. Under the trigger logic, if the status variable is false, set it to true and call the permission request method to request storage permission by passing in the permission identifier. Obtain the return result corresponding to the permission request on the permission request page, and generate a corresponding prompt message based on the return result; On the permission request page, determine whether an old file exists in the target file path of the database; if so, delete it. If not, copy the source file to the target directory in the database source file path and monitor the copying results; If the copy is successful, the user will be redirected to the application's homepage; if the copy fails, the error message will be logged and displayed.
8. The method for permission request and SQLite data management in an Android offline application according to claim 7, characterized in that, The encapsulated database operation tool is invoked to perform paginated queries and single-data queries to achieve local data reading and page rendering, including the following steps: Call the pagination query function in the database operation tool to return the current page data and the total number of data entries; Call the basic query function in the database operation tool to return a single piece of specific configuration data.
9. The method for permission request and SQLite data management in an Android offline application according to claim 8, characterized in that, The framework project is compiled into an application installation package corresponding to the current platform using a compilation and execution tool. The application installation package is then run and verified, including the following steps: Select the framework project using the compilation and execution tool, run it, compile the framework project into the corresponding application installation package, and deploy it to the test environment; After the application starts, verify whether the permission request page pops up on the first launch and whether the return result received based on the permission request page matches the prompt information; A query operation is triggered on the application homepage to verify whether the data can be read and correctly rendered on the application homepage. Switch the test environment to the development environment and the production environment respectively to verify whether the database source file path switches automatically.
10. An electronic device, comprising: One or more processors; A storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to perform the method according to any one of claims 1 to 9.