Webpage and Android interaction method and device, equipment and storage medium
By establishing a mapping relationship and using structured data files in the interaction between Android and web pages, the problems of code redundancy and high maintenance costs are solved, and an efficient and stable interaction method is achieved, reducing maintenance difficulty and improving interface generation speed.
Patent Information
- Application Number
- CN202511763200.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-27
- Publication Date
- 2026-02-24
AI Technical Summary
Existing Android interaction methods with front-end pages require declaring a large number of Java methods in the web page code when expanding functionality, resulting in code redundancy and high maintenance costs.
By establishing a mapping relationship between the web page container and the native interface object in the native environment, data acquisition requests are received, structured data files are read and transmitted to the web page script, and page content is generated to complete the interaction, reducing the number of Java methods directly embedded in the web page code.
It improves interaction efficiency and stability, reduces maintenance costs, and the use of structured data files ensures clear data format, reduces errors and delays in the data acquisition process, and improves the speed and quality of interface content generation.
Smart Images

Figure CN121560972A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data interaction technology, and in particular to methods, apparatus, devices and storage media for interaction between web pages and Android devices. Background Technology
[0002] With the rapid development of internet technology, the demand for real-time communication is growing daily. Existing real-time communication methods rely on real-time communication clients, such as mobile phones, tablets, and computers, to enable real-time interaction of data such as voice, video, and text between two or more clients. However, when Android communicates with front-end pages, it typically injects objects into the front-end page based on Android controls, declaring multiple different Java methods in the injected objects to implement different functionalities. When it is necessary to expand functionality, a large number of Java methods need to be declared in the injected objects and their corresponding front-end pages, which leads to code redundancy and high maintenance costs in the later stages. Summary of the Invention
[0003] The purpose of this invention is to overcome the shortcomings of the prior art and provide a method, device, computer equipment, and storage medium for interaction between web pages and Android.
[0004] To solve the above-mentioned technical problems, the present invention adopts the following technical solution: This invention is achieved through the following technical solution: Firstly, this embodiment provides a method for interaction between a webpage and Android, including the following steps: After loading the web page container in the native environment, a mapping relationship is established between the web page container and the native interface object; Based on the native interface object, determine the calling interface and receive data retrieval requests from the web page script; In response to the data acquisition request, a structured data file is read from local storage and the structured data file is transmitted to the web page script; After generating page content based on the structured data file, the web page script renders the page content in the web page container to complete the interaction.
[0005] Furthermore, the step of establishing a mapping relationship between the webpage container and the native interface object after loading the webpage container in the native environment includes: Instantiate the view component in the web page container; Add the view component to the currently active window and bind its lifecycle; Add the name and signature of the native interface object to the initial script in the view component to form the target script; Based on the target script, the native interface object is added to the context of the web page container to establish a mapping relationship between the web page container and the native interface object.
[0006] Furthermore, the step of determining the calling interface based on the native interface object and receiving the data acquisition request from the web page script includes: The function to be called in the web page script is identified in the native interface object; The calling function is added to the web page script based on a preset channel; When the webpage script executes the call command, the call function is triggered through the preset channel to receive the data acquisition request.
[0007] Furthermore, the step of triggering the calling function via the preset channel to receive the data acquisition request when the webpage script executes the calling command includes: Register an interceptor in the preset channel to obtain the calling commands issued by the web page script; The interceptor converts the invocation command into a parameter object that matches the invocation function. The parameter object is added to the calling function to trigger the execution of the calling function and receive the data acquisition request.
[0008] Furthermore, the step of reading a structured data file from local storage and transferring the structured data file to the web page script in response to the data acquisition request includes: Parse the data acquisition request to obtain the request identifier; Based on the request identifier, determine the structured data file in the preset directory; Serialize the structured data file into a string; The string is input into the receiving function of the web page script based on the calling interface to complete the transfer of the structured data file from the local storage to the web page script.
[0009] Furthermore, the step of serializing the structured data file into a string includes: The serialization rules are determined based on the fields of the structured data file; The structured data file is converted into an intermediate object based on the serialization rules. The intermediate object is encoded into a string to generate the string corresponding to the structured data.
[0010] Furthermore, the step of generating page content based on the structured data file using the webpage script, and then rendering the page content in the webpage container to complete the interaction between the webpage and Android, includes: Semantic parsing is performed on the structured data file to obtain a node tree; Construct a document object model tree based on the node tree; Generate hypertext markup language fragments based on the document object model tree; The markup language fragment is inserted into the root node of the web page container to trigger the web page container to perform a repaint process, so that the page content is displayed on the mobile terminal screen to complete the interaction.
[0011] Secondly, this embodiment provides a webpage and Android interaction device, including: a loading module, an acquisition module, a debugging module and a transmission module; The loading module is used to load the web page container in the native environment and then establish a mapping relationship between the web page container and the native interface object. The acquisition module is used to determine the calling interface based on the native interface object and receive data acquisition requests from the web page script; The debugging module is used to respond to the data acquisition request by reading a structured data file from local storage and transmitting the structured data file to the web page script; The transmission module is used to render the page content in the web page container after the web page script generates page content based on the structured data file to complete the interaction.
[0012] Thirdly, this embodiment provides a computer device, which includes a memory and a processor. The processor stores a computer program, and when the processor executes the computer program, it implements the webpage and Android interaction method described above.
[0013] Fourthly, this embodiment provides a storage medium storing a computer program, the computer program including program instructions, which, when executed by a processor, can implement the webpage and Android interaction method described above.
[0014] The beneficial effects of this invention compared to existing technologies are as follows: It establishes a mapping relationship between the webpage container and the native interface object, reducing the number of Java methods directly embedded in the webpage code, avoiding code redundancy, enabling the webpage container to more flexibly call native functions, and improving the efficiency and stability of interaction. When new functions need to be added, only modifications need to be made to the native interface object, without extensive modifications to the webpage script code, reducing maintenance costs. Simultaneously, the use of structured data files gives the data a clear structure and format. Therefore, reading structured data files from local storage and transmitting them to the webpage script facilitates the parsing and processing of the webpage script, reducing errors and delays in the data acquisition process, and improving the speed and quality of interface content generation.
[0015] The above description is merely an overview of the technical solution of the present invention. In order to better understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other objects, features and advantages of the present invention more obvious and understandable, preferred embodiments are described in detail below. Attached Figure Description
[0016] Figure 1 is a flowchart illustrating the interaction method between a webpage and Android provided in an embodiment of the present invention; Figure 2 This is a flowchart illustrating the execution of step S1 in the webpage-Android interaction method provided in this embodiment of the invention. Figure 3 is a flowchart illustrating the execution of step S2 in the webpage-Android interaction method provided in an embodiment of the present invention. Figure 4 is a flowchart illustrating the execution of step S23 in the webpage-Android interaction method provided in an embodiment of the present invention. Figure 5 is a flowchart illustrating the execution of step S3 in the webpage-Android interaction method provided in an embodiment of the present invention. Figure 6 This is a flowchart illustrating the execution of step S31 in the webpage-Android interaction method provided in this embodiment of the invention. Figure 7 This is a flowchart illustrating the execution of step S4 in the webpage-Android interaction method provided in this embodiment of the invention. Figure 8 A schematic block diagram of a webpage and Android interaction device provided in an embodiment of the present invention; Figure 9 A schematic block diagram of a computer device provided for an embodiment of the present invention. Detailed Implementation
[0017] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0018] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0019] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0020] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0021] Please see Figure 1 The specific embodiment shown in the present invention discloses a method for interaction between a webpage and Android, including the following steps: Step S1: After loading the web page container in the native environment, establish a mapping relationship between the web page container and the native interface object; Understandably, in the native Android environment, a web page container, such as WebView, is loaded, and then a mapping relationship is established between the web page container and the native interface object based on preset mapping rules. The web page container can then call the native interface object without embedding a large amount of complex Java code in the web page code.
[0022] Step S2: Determine the calling interface based on the native interface object and receive a data acquisition request from the web page script; Understandably, the web page script only needs to send a data retrieval request to the native interface object. Based on the data retrieval request, the native interface object determines the corresponding database query interface to call, retrieves the data, and returns it to the web page script. When new functionality needs to be added, only the corresponding interface implementation needs to be added to the native interface object, without needing to modify a large amount of code in the web page script.
[0023] Step S3: In response to the data acquisition request, read the structured data file from local storage and transmit the structured data file to the web page script; Understandably, after receiving a data retrieval request from a web script, the native interface object determines the structured data file to be read based on the data identifier information in the request. Then, it retrieves the corresponding data file from local storage. Once the data file is obtained, the native interface object performs format conversion and encapsulation to ensure that the data file can be correctly parsed and used by the web script. Finally, the converted data file is transmitted to the web script, completing the data transmission process. In this embodiment, the structured data file is in JSON format. After receiving the data file, the web script can quickly parse the data and generate the corresponding page content.
[0024] Step S4: After the web page script generates page content based on the structured data file, it renders the page content in the web page container to complete the interaction.
[0025] Understandably, after receiving the structured data file from the native interface object, the web script generates corresponding page content based on the data file's content and preset page generation rules. These rules can be HTML templates, CSS styles, etc., converting the data in the data file into visual page content. The web script then calls a page generation tool or framework to populate the page template with the data from the data file, generating the target page content. Finally, the generated page content is rendered in a web page container to complete the interaction.
[0026] Through steps S1 to S4, a mapping relationship between the web page container and the native interface object is established, reducing the number of Java methods directly embedded in the web page code, avoiding code redundancy, and enabling the web page container to call native functions more flexibly, thus improving the efficiency and stability of interaction. When new functions need to be added, only modifications need to be made to the native interface object, without extensive modifications to the web page script code, reducing maintenance costs. At the same time, the use of structured data files gives the data a clear structure and format. Therefore, reading structured data files from local storage and transferring the data files to the web page script facilitates the parsing and processing of the web page script, reducing errors and delays in the data acquisition process, and improving the speed and quality of interface content generation.
[0027] In one embodiment, please refer to Figure 2 The step of establishing a mapping relationship between the web page container and the native interface object after loading the web page container in the native environment includes: Step S11: Instantiate the view component in the webpage container; Understandably, in the native Android environment, after calling the WebView constructor to create a WebView instance, the WebView's properties, such as size and layout parameters, are set to fit the application's interface. The initial state of the WebView is configured to ensure that the dynamic functions of the webpage can run normally. After the WebView is instantiated, it is added to the application's layout, ready to load the webpage content.
[0028] Step S12: Add the view component to the currently active window and bind its lifecycle; Understandably, in the current active window, the instantiated WebView component is added to the layout of the active window, and then the WebView's resources are managed in the active window's lifecycle callback methods to ensure that the WebView can respond to lifecycle events in a timely manner when the application is in different lifecycles, thus avoiding resource leaks.
[0029] Step S13: Add the name and signature of the native interface object to the initial script in the view component to form the target script; Understandably, in the initial script of WebView, the name and signature information of the native interface object are added. When the web page script needs to call the native function, it sends a request to the native interface object by calling the added function. After receiving the request, the native interface object identifies the corresponding native function based on the signature information and performs the corresponding operation so that the web page script can call the native function through the clearly identified native interface object to achieve interaction.
[0030] Step S14: Based on the target script, add the native interface object to the context of the web page container to establish a mapping relationship between the web page container and the native interface object.
[0031] Understandably, in the context of WebView, a reference object to the native interface object is added to establish a mapping relationship between the web page container and the native interface object. This allows the web page script to access the functionality of the native interface object through the context. When the web page script needs to call a native function, it sends a request to the native interface object through a function in the target script. After receiving the request, the native interface object executes the corresponding native function according to the mapping relationship and returns the result to the web page script.
[0032] Through steps S11 to S14, the initialization process of the web page container is optimized by instantiating the view components in the web page container, which improves the web page loading efficiency. At the same time, the native interface object is added to the context of the web page container based on the target script to establish a mapping relationship, which reduces the number of Java methods directly embedded in the web page script and reduces code redundancy.
[0033] In one embodiment, please refer to Figure 3 The step of determining the calling interface based on the native interface object and receiving a data acquisition request from the web page script includes: Step S21: Confirm the calling function of the web page script in the native interface object; Understandably, in the native interface object, based on the preset interface specifications and identifiers, the calling function of the web script is identified. The calling function is the bridge for communication between the web script and the native interface object. In the native interface object, each calling function has a unique identifier and corresponding implementation logic. Therefore, based on the identifier, the native interface object can identify the calling request of the web script and map the request to the corresponding calling function.
[0034] Step S22: Add the calling function to the web page script based on the preset channel; Understandably, the native interface object injects a reference to or proxy object of the calling function into the web page script based on a preset channel. In this embodiment, the calling function is a JavaScript function. When the web page script receives the injected calling function, it stores it locally for later use. When the web page script needs to call native functionality, it directly calls the locally stored calling function and sends the request to the native interface object based on the preset channel.
[0035] Step S23: When the web page script executes the call command, the call function is triggered through the preset channel to receive the data acquisition request.
[0036] Understandably, when a web page script needs to call a native function, it executes a call command. The call command sends an event or message through a preset channel, triggering the corresponding call function in the native interface object. After receiving the event or message, the native interface object executes the corresponding call function. After the call function completes its execution, it returns the result to the web page script through the preset channel. This allows the web page script to call native functions more flexibly, improving the efficiency and stability of the interaction.
[0037] By using steps S21 to S23, the calling functions of the web page script are identified in the native interface object, which reduces the number of Java methods directly embedded in the web page script and reduces code redundancy.
[0038] In one embodiment, please refer to Figure 4 The step of triggering the calling function via the preset channel to receive the data acquisition request when the webpage script executes the calling command includes: Step S231: Register an interceptor in the preset channel to obtain the calling commands issued by the web page script; Understandably, when a webpage script issues a call command, the preset channel passes the call command to the interceptor. The interceptor processes the call command, generates a parameter object that matches the called function, and after the interceptor finishes processing, passes the parameter object to the called function, triggering the execution of the called function.
[0039] Step S232: Based on the interceptor, the calling command is converted into a parameter object that matches the calling function; Understandably, after the interceptor captures the call command issued by the web page script, it parses the call command, extracts the parameter information from the call command, and encapsulates the extracted parameter information into a parameter object based on the parameter requirements of the calling function. The parameter object can contain multiple properties, each property corresponding to a call parameter, such as document content, file path, etc. The interceptor passes the encapsulated parameter object to the calling function, triggering the execution of the calling function. The calling function receives and processes the parameters through the parameter object and performs the corresponding operation.
[0040] Step S233: Add the parameter object to the calling function to trigger the execution of the calling function and receive the data acquisition request.
[0041] Understandably, the interceptor encapsulates the converted parameter object into a data structure that conforms to the requirements of the native interface object. The encapsulated parameter object is added to the calling function of the native interface object, causing the calling function to enter the execution state. After receiving the parameter object, the calling function executes the corresponding function according to the content of the parameter object. When the calling function finishes execution, it returns the result to the web page script, thus completing the processing of the data retrieval request.
[0042] Through steps S231 to S233, by registering an interceptor in the preset channel to obtain the calling commands issued by the web page script, the number of Java methods directly embedded in the web page script is reduced, and code redundancy is reduced. At the same time, the parameter object can encapsulate multiple calling parameters, so that the calling function can receive and process parameters in a unified way.
[0043] In one embodiment, please refer to Figure 5 The step of reading a structured data file from local storage and transferring the structured data file to the web page script in response to the data acquisition request includes: Step S31: Parse the data acquisition request to obtain the request identifier; Understandably, the web page script sends a data retrieval request to the native interface object. The request command contains a specific identifier. After receiving the request, the native interface object parses the request content according to preset parsing rules. During the parsing process, the request identifier is extracted as key information for subsequent data retrieval. After parsing is completed, the native interface object performs the next data retrieval operation based on the request identifier.
[0044] Step S32: Determine the structured data file in the preset directory based on the request identifier; Understandably, after the native interface object receives the parsed request identifier, it searches for the corresponding structured data file in a preset directory based on the request identifier. The preset directory can be an internal storage directory specifically used to store data files. Based on identifier matching technology, the request identifier is matched with the file name or path to determine the required data file.
[0045] Step S33: Serialize the structured data file into a string; Understandably, after the native interface object determines the required data file, it reads the contents of the data file and converts the contents of the data file into a string format based on serialization technology (such as JSON serialization). During the serialization process, it ensures the correctness and integrity of the string format, which facilitates subsequent transmission and parsing.
[0046] Step S34: Input the string into the receiving function of the web page script based on the calling interface to complete the transfer of the structured data file from the local storage to the web page script.
[0047] Understandably, after the native interface object completes the serialization of the data file, it obtains data in string format. Based on the preset calling interface, it transmits the string data to the receiving function of the web page script. After receiving the string data, the receiving function of the web page script parses and processes it to generate page content.
[0048] Steps S31 to S34 parse the data acquisition request to obtain the request identifier, which improves the efficiency of data acquisition. Furthermore, the structured data file is serialized into a string, which improves the efficiency and flexibility of data transmission. The string format data is easy to transmit and parse, reduces the number of Java methods directly embedded in the web page script, and reduces code redundancy.
[0049] In one embodiment, please refer to Figure 6 The step of serializing the structured data file into a string includes: Step S331: Determine the serialization rules based on the fields of the structured data file; Understandably, after reading the structured data file, the preset field analysis module is invoked, and the field parsing tool analyzes the field structure of the data file, extracts the field names and data types, and generates serialization rules based on the field information. The serialization rules include the field encoding method and serialization order.
[0050] Step S332: Based on the serialization rules, the structured data file is converted into an intermediate object; Understandably, upon receiving the serialization rules, the data conversion module is invoked, and data mapping tools or field conversion logic are used to convert the content of the structured data file into an intermediate object according to the serialization rules. The intermediate object is then preprocessed and formatted to ensure the accuracy and consistency of the data.
[0051] Step S333: Encode the intermediate object into a string to generate the string corresponding to the structured data.
[0052] Understandably, after receiving the intermediate object, the string encoding module is called to use a preset encoding tool or algorithm to convert the content of the intermediate object into a string format. During the encoding process, the data is verified and optimized to ensure the integrity and consistency of the data.
[0053] Steps S331 to S333 determine serialization rules based on the fields of the structured data file, thereby improving the efficiency of the serialization process.
[0054] In one embodiment, please refer to Figure 7 The steps of generating page content based on the structured data file using the webpage script, and then rendering the page content in the webpage container to complete the interaction between the webpage and Android, include: Step S41: Perform semantic parsing on the structured data file to obtain a node tree; Understandably, after receiving a structured data file, the semantic parsing module is invoked to perform semantic analysis on the content of the data file based on a preset parsing tool or algorithm. After completing the semantic analysis, a node tree is constructed based on the semantic analysis results, where each node represents a semantic unit in the data file.
[0055] Step S42: Construct a document object model tree based on the node tree; Understandably, after receiving the node tree, the document object model tree building module is called to convert the node tree into a document object model tree based on a preset tree structure conversion algorithm. During the conversion process, each node is converted into a corresponding element according to preset rules and standards.
[0056] Step S43: Generate hypertext markup language fragments based on the document object model tree; Understandably, after receiving the Document Object Model (DOM) tree, the pre-defined HTML generation module is invoked. Based on the HTML generator, the content of the DOM tree is converted into hypertext markup language fragments, which are HTML code.
[0057] Step S44: Insert the markup language fragment into the root node of the web page container to trigger the web page container to perform a redraw process, so that the page content is displayed on the mobile terminal screen to complete the interaction.
[0058] Understandably, upon receiving a markup language fragment, the system uses JavaScript's DOM manipulation methods based on a preset operation module to insert the fragment into the root node of the webpage container. Once inserted, the webpage container's repaint process is triggered, rendering the page content onto the screen and completing the interaction between the webpage and Android.
[0059] Through steps S41 to S44, the structured data file is semantically parsed to obtain a node tree, which improves the efficiency and accuracy of data processing. At the same time, markup language fragments are inserted into the root node of the web page container to trigger the repaint process, which improves the efficiency and accuracy of page rendering.
[0060] Please see Figure 8 The present invention also discloses a web page and Android interaction device, comprising: a loading module 10, an acquisition module 20, a debugging module 30 and a transmission module 40; The loading module 10 is used to load the web page container in the native environment and then establish a mapping relationship between the web page container and the native interface object. The acquisition module 20 is used to determine the calling interface based on the native interface object and receive data acquisition requests from the web page script. The debugging module 30 is configured to, in response to the data acquisition request, read a structured data file from local storage and transmit the structured data file to the web page script; The transmission module 40 is used to render the page content in the web page container after the web page script generates page content based on the structured data file to complete the interaction.
[0061] It should be noted that those skilled in the art will clearly understand that the specific implementation process of the above-mentioned interactive device for web pages and Android and its various units can be found in the corresponding descriptions in the foregoing method embodiments. For the sake of convenience and brevity, these details will not be repeated here. The above can be implemented as a computer program, which can be used in, for example... Figure 9 It runs on the computer device shown.
[0062] Please see Figure 9 , Figure 9 This is a schematic block diagram of a computer device 500 provided in an embodiment of this application; the computer device 500 can be a terminal or a server, wherein the terminal can be an electronic device with communication functions such as a smartphone, tablet computer, laptop computer, desktop computer, personal digital assistant, and wearable device. The server can be a standalone server or a server cluster composed of multiple servers.
[0063] Please see Figure 9 The computer device 500 includes a processor 502, a memory, and a network interface 505 connected via a system bus 501. The memory may include a non-volatile storage medium 503 and internal memory 504.
[0064] The non-volatile storage medium 503 can store an operating system 5031 and a computer program 5032. The computer program 5032 includes program instructions that, when executed, enable the processor 502 to implement a webpage interaction method with Android, comprising the following steps: after loading a webpage container in the native environment, establishing a mapping relationship between the webpage container and a native interface object; determining a calling interface based on the native interface object, and receiving a data acquisition request from a webpage script; in response to the data acquisition request, reading a structured data file from local storage and transmitting the structured data file to the webpage script; and after the webpage script generates page content based on the structured data file, rendering the page content onto the webpage container to complete the interaction.
[0065] The processor 502 provides computing and control capabilities to support the operation of the entire computer device 500.
[0066] The internal memory 504 provides an environment for the execution of the computer program 5032 in the non-volatile storage medium 503. When the computer program 5032 is executed by the processor 502, the processor 502 can execute a web page and Android interaction method.
[0067] This network interface 505 is used for network communication with other devices. Those skilled in the art will understand that... Figure 6 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device 500 to which the present application is applied. The specific computer device 500 may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0068] The processor 502 is used to run a computer program 5032 stored in the memory to perform the following steps: Step S1: After loading the web page container in the native environment, establish a mapping relationship between the web page container and the native interface object; Step S2: Determine the calling interface based on the native interface object and receive a data acquisition request from the web page script; Step S3: In response to the data acquisition request, read the structured data file from local storage and transmit the structured data file to the web page script; Step S4: After the web page script generates page content based on the structured data file, it renders the page content in the web page container to complete the interaction.
[0069] It should be understood that in the embodiments of this application, the processor 502 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0070] It will be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program includes program instructions and can be stored in a storage medium, which is a computer-readable storage medium. The program instructions are executed by at least one processor in the computer system to implement the process steps of the embodiments of the above methods.
[0071] Therefore, the present invention also provides a storage medium. This storage medium can be a computer-readable storage medium. The storage medium stores a computer program, wherein the computer program includes program instructions that, when executed by a processor, can implement the above-described webpage and Android interaction method. The storage medium stores a computer program, which includes program instructions that, when executed by a processor, can implement the above-described method. The program instructions include the following steps: Step S1: After loading the web page container in the native environment, establish a mapping relationship between the web page container and the native interface object; Step S2: Determine the calling interface based on the native interface object and receive a data acquisition request from the web page script; Step S3: In response to the data acquisition request, read the structured data file from local storage and transmit the structured data file to the web page script; Step S4: After the web page script generates page content based on the structured data file, it renders the page content in the web page container to complete the interaction.
[0072] The storage medium can be any computer-readable storage medium capable of storing program code, such as a USB flash drive, portable hard drive, read-only memory (ROM), magnetic disk, or optical disk.
[0073] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0074] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is merely a logical functional division, and there may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed.
[0075] The steps in the method of this invention can be adjusted, merged, or reduced in order according to actual needs. The units in the device of this invention can be merged, divided, or reduced according to actual needs. Furthermore, the functional units in the various embodiments of this invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0076] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0077] The above embodiments are preferred implementations of the present invention. In addition, the present invention can be implemented in other ways. Any obvious substitutions without departing from the concept of the present technical solution are within the protection scope of the present invention.
Claims
1. A method for interaction between a webpage and Android, characterized in that, Includes the following steps: After loading the web page container in the native environment, a mapping relationship is established between the web page container and the native interface object; Based on the native interface object, determine the calling interface and receive data acquisition requests from the web page script; In response to the data acquisition request, a structured data file is read from local storage and the structured data file is transmitted to the web page script; After generating page content based on the structured data file, the web page script renders the page content in the web page container to complete the interaction.
2. The method for interaction between a webpage and Android according to claim 1, characterized in that, The step of establishing a mapping relationship between the web page container and the native interface object after loading the web page container in the native environment includes: Instantiate the view components in the web page container; Add the view component to the currently active window and bind its lifecycle; Add the name and signature of the native interface object to the initial script in the view component to form the target script; Based on the target script, the native interface object is added to the context of the web page container to establish a mapping relationship between the web page container and the native interface object.
3. The method for interaction between a webpage and Android according to claim 1, characterized in that, The step of determining the calling interface based on the native interface object and receiving a data acquisition request from the web page script includes: The function to be called in the web page script is identified in the native interface object; The calling function is added to the web page script based on a preset channel; When the webpage script executes the call command, the call function is triggered through the preset channel to receive the data acquisition request.
4. The method for interaction between a webpage and Android according to claim 3, characterized in that, The step of triggering the calling function via the preset channel to receive the data acquisition request when the web page script executes the calling command includes: Register an interceptor in the preset channel to obtain the calling commands issued by the web page script; The interceptor converts the invocation command into a parameter object that matches the invocation function. The parameter object is added to the calling function to trigger the execution of the calling function and receive the data acquisition request.
5. The method for interaction between a webpage and Android according to claim 1, characterized in that, The step of reading a structured data file from local storage and transferring the structured data file to the web page script in response to the data acquisition request includes: Parse the data acquisition request to obtain the request identifier; Based on the request identifier, determine the structured data file in the preset directory; Serialize the structured data file into a string; The string is input into the receiving function of the web page script based on the calling interface to complete the transfer of the structured data file from the local storage to the web page script.
6. The method for interaction between a webpage and Android according to claim 5, characterized in that, The step of serializing the structured data file into a string includes: The serialization rules are determined based on the fields of the structured data file; The structured data file is converted into an intermediate object based on the serialization rules. The intermediate object is encoded into a string to generate the string corresponding to the structured data.
7. The method for interaction between a webpage and Android according to claim 1, characterized in that, The steps of generating page content based on the structured data file and rendering the page content in the webpage container to complete the interaction between the webpage and Android include: Semantic parsing is performed on the structured data file to obtain a node tree; Construct a document object model tree based on the node tree; Generate hypertext markup language fragments based on the document object model tree; The markup language fragment is inserted into the root node of the web page container to trigger the web page container to perform a repaint process, so that the page content is displayed on the mobile terminal screen to complete the interaction.
8. A webpage-Android interactive device, characterized in that, include: Loading module, retrieval module, debugging module, and transmission module; The loading module is used to load the web page container in the native environment and then establish a mapping relationship between the web page container and the native interface object. The acquisition module is used to determine the calling interface based on the native interface object and receive data acquisition requests from the web page script; The debugging module is used to respond to the data acquisition request by reading a structured data file from local storage and transmitting the structured data file to the web page script; The transmission module is used to render the page content in the web page container after the web page script generates page content based on the structured data file to complete the interaction.
9. A computer device, characterized in that, The computer device includes a memory and a processor, the processor storing a computer program, and when the processor executes the computer program, it implements the webpage and Android interaction method as described in any one of claims 1-7.
10. A storage medium, characterized in that, The storage medium stores a computer program, which includes program instructions that, when executed by a processor, can implement the webpage and Android interaction method as described in any one of claims 1-7.