Message transmission method and device, equipment and storage medium
By introducing native services to receive and broadcast messages in the application, the problem of low message transmission efficiency of application is solved, the stability of internal message delivery and server connection is achieved, and the overall message delivery efficiency and path richness are improved.
Patent Information
- Application Number
- CN202310579389.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-22
- Publication Date
- 2024-11-22
AI Technical Summary
In the prior art, applications are inefficient in message transmission, and the message delivery path is long, so they cannot realize effective message delivery between the application, especially when the main page WebView runs for a long time in the background, resulting in interruption between the application and the server. even.
By introducing native services into the application, receiving and broadcasting messages, allowing target objects (such as pages or native components) to directly receive and process messages, simplifying the message delivery path and maintaining connections between native services and servers.
It improves messaging efficiency, avoids disconnection caused by long-term background operation of the main page WebView, realizes cross-page and cross-component messaging within the application, saves resources, and enriches the messaging path.
Smart Images

Figure CN119011647A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of communication technology, and in particular, to a message transmission method, apparatus, device and storage medium. Background Art
[0002] As user demand increases, applications (Application Program, APP) for various purposes have emerged. In some technologies, during the operation of the application, the WebView of the main page (also known as the homepage) is responsible for receiving and sending messages between the application and the outside world. For example, when other pages in the application need to process messages transmitted by the server, the WebView of the main page needs to receive the message transmitted by the server, and then pass it to other pages through the internal path. This makes the message transmission path longer and the message transmission efficiency lower. In addition, when the main page is placed in the background for a long time, it will be suspended. At this time, it is impossible to receive and send messages between the application and the outside world. At the same time, messages cannot be transmitted between pages loaded by different WebViews of the application, and messages cannot be transmitted between pages loaded by the WebView of the application and the native components of the application. Therefore, it is impossible to meet the user's needs for transmitting messages within the application.
[0003] Based on this, how to make the application transmit messages more reasonably and efficiently during the operation of the application has become a technical problem that needs to be solved urgently. Summary of the invention
[0004] The embodiments of the present application provide a message transmission method, apparatus, device and storage medium to solve the technical problem in the related art that application message transmission lacks rationality and has low efficiency.
[0005] In a first aspect, an embodiment of the present application provides a message transmission method, the method comprising:
[0006] The native service in the first application receives a first message, where the first message is a message sent by a first page in the first application, a message sent by a first native component in the first application, or a message sent by a server of the first application, and the first message is used for processing by a target object in the first application, where the target object is a second page or a second native component;
[0007] The native service broadcasts the first message in the first application;
[0008] The target object in the first application receives the first message broadcast by the native service and processes the first message.
[0009] In a second aspect, an embodiment of the present application further provides a message transmission device, the device comprising:
[0010] A first receiving unit is configured to enable a native service in a first application to receive a first message, wherein the first message is a message sent by a first page in the first application, a message sent by a first native component in the first application, or a message sent by a server of the first application, and the first message is used for processing by a target object in the first application, and the target object is a second page or a second native component;
[0011] a broadcast unit, configured to enable the native service to broadcast the first message in the first application;
[0012] The second receiving unit is configured to enable a target object in the first application to receive the first message broadcast by the native service and process the first message.
[0013] In a third aspect, an embodiment of the present application further provides a message transmission device, the device comprising:
[0014] one or more processors;
[0015] a communication module, configured to communicate according to instructions of the processor;
[0016] A memory for storing one or more programs;
[0017] When the one or more programs are executed by the one or more processors, the one or more processors implement the message transmission method as described in the first aspect.
[0018] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the message transmission method as described in the first aspect.
[0019] In one embodiment of the present application, a message sent by the first page of the first application is received through the native service of the first application, a message sent by the first native component of the first application is received, or a message sent by the server of the first application is received. After that, the native service broadcasts the received message. When the message needs to be processed by the second page of the first application, the second page receives the message broadcast by the native service and processes the message. When the message needs to be processed by the second native component of the first application, the second native component receives the message broadcast by the native service and processes the message. The technical means solves the technical problem of the lack of rationality and low efficiency of application message transmission in the related technology. Compared with the homepage WebView receiving messages, the native service uniformly receives the messages sent by the external server, and the page or native component that processes the message can directly receive the message broadcast by the native service, which can simplify the message transmission path and improve the message transmission efficiency. In addition, it is no longer dependent on the homepage WebView to receive messages, and it can also avoid the disconnection of the first application and the server when the homepage WebView runs in the background for a long time. That is, during the operation of the first application, the native service and the server can maintain a connection, thereby ensuring the timely reception of messages, and only the connection between the native service and the server needs to be maintained, which also saves more resources. In addition, message transmission across web pages, across native components, and between web pages and native components within the first application is implemented, enriching the message transmission path of the first application. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] Figure 1 A schematic diagram of a message transmission path of a native application in the related art;
[0021] Figure 2 A schematic diagram of the structure of an electronic device provided by one embodiment of the present application;
[0022] Figure 3 A first example diagram of a message delivery path provided for an embodiment of the present application;
[0023] Figure 4 A flowchart of a message transmission method provided by an embodiment of the present application;
[0024] Figure 5 A flowchart of another message transmission method provided by an embodiment of the present application;
[0025] Figure 6 A flowchart of another message transmission method provided by an embodiment of the present application;
[0026] Figure 7 A second example diagram of a message delivery path provided for one embodiment of the present application;
[0027] Figure 8An internal message transmission flow chart provided for an embodiment of the present application;
[0028] Fig. 9 A cloud message transmission flow chart provided for one embodiment of the present application;
[0029] Fig.10 A schematic diagram of the structure of a message transmission device provided for one embodiment of the present application. DETAILED DESCRIPTION
[0030] The present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are used to explain the present application, rather than to limit the present application. It should also be noted that, for ease of description, only the parts related to the present application, rather than all structures, are shown in the accompanying drawings.
[0031] Applications can also be called application software, software programs, etc. Based on different development methods, applications can be divided into native applications, HTML5 applications, and hybrid applications.
[0032] Among them, native applications can be understood as applications developed through native development technology in accordance with the programming language and development language, development library, and development tools of the operating system.
[0033] The interface for user interaction during the operation of a native application can be a web page or a native interface generated by other native components. A web page can be understood as a web page, which is loaded through WebView. WebView is a control for loading web pages in native syntax.
[0034] Figure 1 This is a schematic diagram of the message transmission path of the native application in the related technology. Figure 1 When the server passes a message to other WebViews of the native application, it first passes the message to the homepage WebView of the native application, and the homepage WebView then forwards the message to the native service, and the native service notifies the corresponding WebView ( Figure 1 When the server passes messages to other components of the native application, it also needs to pass the message to the homepage WebView first. The homepage WebView forwards the message to the native service, and the native service notifies the corresponding component ( Figure 1 Similarly, when other WebViews and other components pass messages to the server, they also need to go through the native service and the homepage WebView.
[0035] Among them, the homepage of the native application can also be understood as the main interface, which is the first interface for users to interact with when entering (i.e. starting or opening) the application. Users can also enter other interfaces while operating the homepage. At this time, the homepage is covered by other interfaces, and users can interact with other interfaces. During the interaction process, users can return to the homepage or enter other interfaces.
[0036] There is a WebView on the homepage of the native application. The web page loaded by the WebView is responsible for communicating with the backend server. For ease of understanding, the web page loaded by the WebView is recorded as the homepage WebView. It can be understood that the homepage WebView can also be understood as the homepage of the native application. All messages transmitted between the native application and the server need to be received and forwarded by the homepage WebView.
[0037] The server can provide background services for native applications. The server can be one or more physical entities. The device type, number of devices, and service types provided by the server are not currently limited. The messages transmitted between the native application and the server can include data, instructions, etc. transmitted between the native application and the server.
[0038] Native services can be understood as a service based on native development in native applications. The functions implemented by native services can be set based on actual needs. In related technologies, native services are used to implement message transmission between the homepage WebView and other WebViews, as well as message transmission between the homepage WebView and other components.
[0039] Other WebViews can be understood as WebViews used to generate web pages other than the home page. Other components can be understood as native components that rely on messages. For example, if a native interface needs to communicate with the server, then the component that generates the native interface can be considered as other components.
[0040] It is understandable that when a native application opens (can also be understood as generating) another web page (not the home page), it is necessary to use the WebView corresponding to the web page to load the web page. Currently, in order to distinguish it from the home page WebView, it is recorded as a new WebView. Based on the foregoing content, it can be seen that when the new WebView transmits messages to the server, it must at least pass through the native service and the home page WebView. Similarly, when other components that rely on messages transmit messages to the server, they must also at least pass through the native service and the home page WebView.
[0041] This makes the transmission path between the native application and the server longer. In particular, when two native applications transmit messages through the server, the required transmission path is longer, which affects the efficiency of message transmission.
[0042] In addition, the native application needs to keep the homepage WebView alive (that is, keep the homepage WebView running) to ensure that the homepage WebView communicates normally with the server. However, when the homepage is covered by other interfaces, the homepage WebView is placed in the background. At this time, in order to save system (that is, the operating system running the native application) performance, when the WebView is placed in the background, the duration of the timed loop operation is generally set. During this duration, the WebView continues to run in the background. After the duration is exceeded, the WebView no longer runs. For example, the duration is 5 minutes, then when the homepage WebView is placed in the background, it will only be kept alive in the first 5 minutes. After more than 5 minutes, the homepage WebView will no longer communicate with the server, that is, stop receiving and sending messages, which seriously affects the transmission of messages between the native application and the server.
[0043] In the related technology, the internal message transmission path of the native application is also relatively simple, and messages can only be transmitted between native components (implemented through the communication method agreed upon within the native page), which cannot meet more application scenarios. For example, a web page loaded by a WebView of a native application cannot transmit messages to a web page loaded by another WebView of the native application, or the native components of the native application cannot transmit messages to the web pages loaded by the WebView of the native application.
[0044] Based on this, a message transmission method is provided in an embodiment of the present application. By setting a native service for receiving and forwarding messages in the native application, the native application can transmit messages more reasonably and efficiently. Specifically, the native service can transmit messages between the server, the web pages of the native application, and the components. It no longer relies on the homepage WebView, simplifies the message transmission path, and can enrich the message transmission path within the native application. In addition, it no longer relies on the homepage WebView, and it also avoids the impact of the homepage WebView being placed in the background for a long time on the message transmission between the native application and the server.
[0045] In one embodiment of the present application, the message transmission method can be executed by a message transmission device, which can be composed of two or more physical entities or one physical entity. Currently, the message transmission device is an electronic device that can install an application. Among them, the electronic device can be an intelligent electronic device such as a mobile phone, an interactive tablet, a laptop, a smart TV, a tablet computer, a learning machine, etc.
[0046] Figure 2 A schematic diagram of the structure of an electronic device provided by an embodiment of the present application. Figure 2 The electronic device 10 includes a processor 101, a display screen 102, a memory 103, and a communication module 104. The processor 101, the display screen 102, the memory 103, and the communication module 104 are connected via a communication bus 105. In practical applications, the processor 101, the display screen 102, the memory 103, and the communication module 104 may also be connected via other types of connection lines.
[0047] The processor 101 may include processing units such as an application processor (AP), a graphics processing unit (GPU), and a central processing unit (CPU).
[0048] The display screen 102 may be a liquid crystal display (Liquid Crystal Display), an LED display (LEDdisplay), an organic light-emitting diode (OLED) display screen, or a flexible light-emitting diode (FLED) display screen, etc. In addition, the display screen 102 may be a straight screen or a curved screen, which is not limited in the embodiments of the present application.
[0049] The number of display screens 102 configured in the electronic device 10 can be one or more. When there are multiple display screens 102, the layout of the multiple display screens is not currently limited. For example, the multiple display screens are arranged horizontally from left to right. For another example, the multiple display screens are respectively located on the front and back of the electronic device.
[0050] The display screen 102 includes a display panel, or the display screen 102 includes a display panel and a touch panel. Among them, the display panel is used to complete the visual output. The touch panel can be a component that supports infrared touch, electromagnetic touch, capacitive touch or resistive touch. The touch panel can pass the touch data corresponding to the detected touch operation to the processor 101, and the display panel can provide visual output related to the touch operation. Taking a mobile phone as an example, the display panel can be understood as a display screen used for displaying pictures in a mobile phone, and the touch panel can be understood as a touch component for collecting data generated by the user's touch operation.
[0051] The memory 103 may be used to store a computer executable program of the electronic device, the computer executable program including instructions, etc. The memory 103 may include a program storage area and a data storage area. The program storage area may store an operating system and an application required for at least one function. The data storage area may store data created according to the use of the electronic device, etc.
[0052] The memory 103 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage devices.
[0053] The communication module 104 may be a wired communication module and / or a wireless communication module. The communication module 104 is used to implement communication between the electronic device and the outside world, for example, to implement communication between the electronic device and a server, or between the electronic device and other electronic devices. It is understood that the communication module 104 may also include at least one interface for implementing communication, so that the communication module 104 can use it during communication.
[0054] Optionally, the electronic device 10 may further include components such as a camera, an audio device, etc. The embodiment of the present application does not specifically limit the hardware components of the electronic device.
[0055] The electronic device is installed with at least one type of operating system, which may be an Android system, a Windows system, a Linux system, an IOS system, etc. Currently, the electronic device is described by taking the Android system as an example.
[0056] For the layered architecture of the Android system, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, namely, the application layer, the application framework layer, the system library, and the kernel layer from top to bottom.
[0057] The application layer may include a series of application packages, and the application packages may include various currently installed applications, such as whiteboard writing software, annotation writing software, Bluetooth, music, collaborative assistant and other applications installed on the electronic device.
[0058] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions. For example, the application framework layer may include a window manager, a resource manager, a view system, etc.
[0059] The window manager is used to manage window programs. The window manager can obtain the display size, determine whether there is a status bar, lock the screen, etc. The resource manager provides various resources for applications, such as localized strings, icons, pictures, layout files, video files, etc. The view system includes visual controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build applications. The display interface can be composed of one or more views. For example, it includes a view for displaying text and a view for displaying pictures.
[0060] The application layer and the application framework layer can run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine can be used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0061] The system library can include multiple functional modules. For example: surface manager, media library, touch server, etc. The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications. The media library supports playback and recording of multiple common audio and video formats, as well as static image files, etc. The media library can support multiple audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0062] The kernel layer (also known as the Linux kernel layer) is the layer between hardware and software. The kernel layer includes touch driver, display driver, camera driver, audio driver, sensor driver, Bluetooth driver, WIFI driver, etc.
[0063] Based on the layered architecture of the aforementioned operating system, the application installed in the electronic device may be an application that comes with the operating system, or an application downloaded from a server or a third-party device. The user can implement corresponding functions by running the application installed in the electronic device.
[0064] In the embodiment of the present application, the application programs installed in the electronic device at least include an application program using the message transmission method provided in the embodiment of the present application. Currently, the application program using the message transmission method is a native application program.
[0065] Native applications provide native services, which can be considered as editable functions when developing applications. Currently, native services are used to implement message transmission between native applications and servers, as well as message transmission within native applications.
[0066] During the operation of a native application, at least one web page can be generated, and messages can be transmitted between web pages through native services. A native application also includes at least one native component. A native component is developed based on native and is used to implement a corresponding interface or function. When a native component is running, a corresponding interface can be generated or a corresponding function can be implemented. Messages can also be transmitted between native components and between native components and web pages through native services.
[0067] On this basis, Figure 3 The first example diagram of a message transmission path provided by an embodiment of the present application. Figure 3 , the server connects to the native service in the native application to achieve two-way communication. The native service communicates bidirectionally with each web page (referred to as page) generated by the native application and the running native components. Figure 3 A web page and a native component are shown in the example
[0068] Figure 3 Messages can be passed between two objects that implement two-way communication in the native application to achieve message transmission between native applications and between native applications and the outside world.
[0069] Currently, the server can provide services for applications installed in different types of electronic devices for implementing the same business. The operating systems installed on different types of electronic devices can be the same or different. For example, the server can provide services for an application that implements a certain business in a mobile phone, an application that implements the business in an interactive tablet, and an application that implements the business in a PC. At this time, messages can be transmitted between different electronic devices through the server, that is, the server can receive a message sent by an electronic device and pass it to another electronic device. In one embodiment, a background service runs in the server, and the background service is used for two-way communication with each application, that is, the communication between the server and the native application mentioned in the embodiments of the present application can be considered as communication between the background service and the native service.
[0070] exist Figure 3 On the basis of Figure 4 A flowchart of a message transmission method provided by an embodiment of the present application, refer to Figure 4 , the message transmission method comprises the following steps:
[0071] Step 210: The native service in the first application receives a first message. The first message is a message sent by the first page in the first application, a message sent by the first native component in the first application, or a message sent by the server of the first application. The first message is used for processing by a target object in the first application, and the target object is a second page or a second native component.
[0072] The first application is a native application currently running on the electronic device. That is, the content currently displayed on the display screen of the electronic device at least includes the interface of the first application. The interface can be a web page or a native interface. The user interacts based on the interface of the first application to control the first application.
[0073] Currently, the message transmitted by the first application can be an internal message or a cloud message. Among them, the internal message refers to the message generated by the first application and transmitted within the first application. The cloud message refers to the message received from the server, or the message generated by the first application and transmitted to the server.
[0074] When the first application is running, the native service in the first application receives a message that needs to be transmitted in the first application, that is, receives a message that needs to be responded to by the first application. The message can be an internal message or a cloud message. In the embodiment, the message currently received by the native service is recorded as the first message.
[0075] Exemplarily, the first message may be a message sent by the server of the first application, in which case the first message is a cloud message. For the first application, the first message received from the server may be a message generated by other applications and sent through the server. In some cases, the first message may also be generated by the server. In an embodiment of the present application, when the server sends a message to the first application, the message is received by the native service of the first application. That is, when the first application receives a message sent by the outside world, the message is specifically received by the native service of the first application.
[0076] In one embodiment, the native service and the background service of the server establish a two-way connection through WebSocket. Among them, WebSocket is a protocol for full-duplex communication on a single TCP connection. Establishing a two-way connection based on WebSocket is a technical means that has been implemented and is not described separately at present. After the connection is established, the native service receives the first message sent by the background service based on WebSocket.
[0077] Exemplarily, the first message may also be a message generated internally by the first application. In this case, the first message is an internal message.
[0078] When the first message is generated inside the first application, it may be a web page in the first application that generates the first message. In an embodiment, the web page that generates the first message is recorded as the first page. When the first page generates the first message, it may be autonomously generating the first message, or it may be generating the first message based on the user's instructions. Optionally, the first page may be a page running in the foreground of the first application, or it may be a page running in the background of the first application. Among them, foreground running means that the first page is displayed on the display screen of the electronic device and can be interacted with by the user. Background running means that the first page is covered by other interfaces and cannot be interacted with by the user. After the first page generates the first message, the first message is sent to the native service, that is, the first message is received by the native service.
[0079] When the first message is generated inside the first application, it may be a native component in the first application that generates the first message. In the embodiment, the native component that generates the first message is recorded as the first native component. The implementation method of the first native component generating the first message is similar to the implementation method of the first page generating the first message, and is not described separately at present. After the first native component generates the first message, it sends the first message to the native service, that is, the first message is received by the native service.
[0080] Optionally, when the native service receives the first message, it can determine whether the first message is a cloud message or an internal message. The determination method is not currently limited. For example, cloud messages and internal messages have different message formats. The native service can determine whether the first message is a cloud message or an internal message based on the message format. For another example, the protocol (or interface) used by the native service to receive cloud messages is different from the protocol (or interface) used to receive internal messages. The native service can determine whether the first message is a cloud message or an internal message based on the protocol (or interface) currently used when receiving the message.
[0081] Optionally, when the native service receives a message (such as the first message), it can first determine whether the message should be sent to the server or responded to by the first application. If it is determined that the first application responds, the subsequent steps are executed. If it is determined that the message needs to be sent to the server, the subsequent steps are not executed, and the message is sent to the server.
[0082] Optionally, when the native service receives a message sent by the server, the subsequent steps are executed. When a message sent by the first page or the first native component is received, it is determined whether the message should be sent to the server or responded by the first application. If it is determined that the first application responds, the subsequent steps are executed. If it is determined that it needs to be sent to the server, the subsequent steps are not executed, and the message is sent to the server.
[0083] The way in which the native service determines whether a message needs to be sent to the server or responded to by the first application is not currently limited. For example, if the message contains a communication address (such as an IP address) that is not the first application, it is determined that the message needs to be sent to the server. For another example, if the message contains an identifier related to the first application (such as a device identifier or device ID, etc.), it is determined that the message should be responded to by the first application. If there is no identifier of the first application, it is determined that the message needs to be sent to the server.
[0084] When the first message needs to be responded to by the first application, the object in the first application that responds to the first message is recorded as the target object. Currently, the target object can be a web page in the first application or a native component in the first application. In an embodiment, the web page that responds to the first message is recorded as the second page, and the native component that responds to the first message is recorded as the second native component.
[0085] It should be noted that the native components mentioned in the embodiments can all be considered as native components that rely on messages, that is, native components that need to generate messages and transmit or process messages.
[0086] Step 220: The native service broadcasts a first message in the first application.
[0087] For example, when the native service broadcasts the first message in the first application, each web page in the first application and the native component that relies on the message can theoretically receive the first message. At this time, each web page and the native component that relies on the message can receive the first message broadcast by the native service when it is determined that the first message needs to be responded to by itself.
[0088] When the native service broadcasts the first message in the first application, it may directly broadcast the first message, or process the first message and broadcast the processed first message.
[0089] Currently, the description is made by taking the example that the native service parses the first message and broadcasts the parsed message entity. At this time, step 220 may include steps 221 and 222:
[0090] Step 221: The native service parses the first message according to the message type of the first message to obtain the message entity of the first message.
[0091] Exemplarily, the message type is used to indicate the type of actual response content corresponding to the message. The granularity of the message type division can be set according to demand. For example, the message types related to communication connection may include: request connection type, connection success type, request disconnect type, disconnect type, etc.
[0092] Optionally, each message type can be represented by a corresponding identifier, wherein the identifier can be represented by numbers, letters and / or symbols. Taking numbers as an example, if there are currently 7 message types, then the 7 message types can be represented by numbers 1-7 respectively.
[0093] Optionally, the server and each application program served by the server may pre-store each message type and a corresponding identifier, so as to determine the message type to which the message belongs based on the identifier corresponding to the message type.
[0094] In one embodiment, the first message includes at least an identifier corresponding to the message type. Currently, each content included in the message has a corresponding field. For example, if the message includes a target communication address and an identifier of the message type, then the target communication address and the identifier of the message type both have fixed fields in the message. After receiving the first message, the native service parses the first message to obtain an identifier of the record from the field indicating the message type, and then determines the message type of the first message based on the identifier.
[0095] Afterwards, the native service obtains the message entity according to the message type of the first message. Among them, the message entity indicates the content actually expressed by the first message, that is, the actual response content. For example, if the message type of the first message is a request connection type, then the corresponding message entity is the specific content of the connection request, that is, the target object receiving the message can clearly know what kind of connection request it is based on the message entity. Exemplarily, the native service obtains the message entity and can be considered to generate a message representing the message entity, which can be recognized and responded to by the first application. For example, if the message type is a request connection type, then the native service can generate a message based on the message type, and the message contains a specific connection request, that is, the message can be used as the message entity.
[0096] The implementation method of obtaining the message entity by the native service is currently not limited. For example, the native service pre-stores the generation rules of the message entities corresponding to each message type, and then generates the message entity corresponding to the message type of the first message based on the corresponding generation rules. Optionally, when generating the message entity, the native service can also add the content related to the actual response content in the first message to the message entity. For example, if the first message is an instant messaging message, then the specific communication content of the instant messaging message can be written into the message entity.
[0097] Step 222: The native service broadcasts a message entity of the first message in the first application.
[0098] After the native service obtains the message entity, it can broadcast the message entity in the first application. The message entity can be obtained and responded to by the web page or native component in the first application.
[0099] It can be understood that the subsequent processing flow of the first application on the first message can be regarded as the processing flow of the message entity of the first message.
[0100] Step 230: The target object in the first application receives the first message broadcast by the native service and processes the first message.
[0101] Exemplarily, when the native service broadcasts the first message, each web page currently generated by the first application and each running native component can determine whether the first message currently broadcast by the native service is a message that they can process. If so, they receive the first message and process the first message.
[0102] Generally speaking, in the first application, different web pages and different native components may process different types of messages. At this time, each web page and each native component can only receive messages of the type that can be processed by itself, and other types of messages will not be received.
[0103] Optionally, the protocol content can be pre-defined between each web page, each native component and native service, and the protocol content is used to provide a method for mutual calling to realize message transmission during calling. That is, the pre-defined protocol can be considered as the protocol used by the first application when transmitting messages. The specific content of the protocol is not currently limited.
[0104] An optional method is to use a different protocol when delivering internal messages than when delivering cloud messages, so as to achieve separate processing of internal messages and cloud messages. It can be understood that different protocols can be understood as different specific implementation methods when delivering, but the delivery path will not change. For example, when a web page delivers a message to a native service, although cloud messages and internal messages use different protocols, in the end, the native service will receive the message and perform subsequent processing.
[0105] When the target object is the second page, after the first application generates the second page, the second page can communicate with the native service, that is, observe whether there is a message type that the second page is concerned about in each message broadcast by the native service.
[0106] In one embodiment, each web page (ie, page) of the first application has a corresponding WebView, and the corresponding web page is loaded through the WebView. Optionally, the WebView corresponding to each web page is a native WebView, so that the native application generates a web page based on the native WebView.
[0107] Optionally, when a web page communicates with a native service, the WebView corresponding to the web page communicates with the native service. That is, the messages transmitted between the web page and the native service need to pass through the WebView.
[0108] In one embodiment, each web page (i.e., page) of the first application communicates with the corresponding WebView via JSBridge, wherein JSBridge is provided by the operating system (currently Android system) of the electronic device, and JSBridgee is an actual means that has been implemented and will not be described in detail.
[0109] For example, a web page and a corresponding WebView can be called through JSBridge. The predefined protocol content between each web page and the native service also includes the protocol provided by WebView. At this time, based on the predefined protocol content, the web page and WebView can call each other, and the WebView and the native service can call each other.
[0110] In one embodiment, the WebView of each web page (i.e., page) communicates with the native service via EventBus. Among them, EventBus is an open source library that can be used for module communication in the Android system. Currently, it is used to implement communication between the native service and WebView in the first application installed in the Android system. Based on EventBus, WebView can monitor the native service to determine whether the native service broadcasts messages that can be processed by the web page, and receive processable messages and pass them to the web page for processing. At this time, step 230 may include steps 231-233:
[0111] Step 231: The WebView of the second page receives the first message broadcast by the native service.
[0112] Exemplarily, when the first application generates the WebView of the second page, the WebView registers the service. The service can be understood as a specific service that the web page can respond to (or provide), and the message types corresponding to each service are different. After the service is registered, the WebView can clearly identify the service type that the loaded web page can handle, and then determine the message type that can be processed. This message type is the message type that the WebView cares about. After that, the WebView can observe whether the native service broadcasts the message type that it cares about.
[0113] In one embodiment, the WebView may monitor the native service and determine whether it has monitored a message type that it is concerned about. In this case, step 231 may be specifically as follows: the WebView of the second page monitors the native service, and when it is detected that the message type of the first message currently broadcast by the native service meets the preset message type, the WebView receives the first message.
[0114] Exemplarily, after the WebView service of the second page is registered, it can monitor the native service. At this time, the WebView of the second page can monitor every message broadcast by the native service. Currently, take the broadcast of the first message by the native service as an example. When the native service broadcasts the first message, the WebView of the second page can determine that the first message is a service that can be processed by the second page, and then, through Eventbus, based on the predefined protocol content, call the native service to receive the first message broadcast by the native service. After that, the WebView of the second page continues to monitor the native service.
[0115] It can be understood that if the first message is not a service that can be processed by the second page, the WebView of the second page does not receive the first message.
[0116] Among them, the WebView of the second page determines whether the first message is a business that can be processed by the second page, which can also be understood as determining whether the message type of the first message is a preset message type. The preset message type refers to the message type that can be processed by the second page. The implementation method for the WebView of the second page to determine whether the message type of the first message is a preset message type is not currently limited. For example, different message types correspond to different message entities. The WebView of the second page can determine whether the message type of the first message is a preset message type by parsing the message entity. For another example, when the native service broadcasts the first message, it can simultaneously broadcast the message type of the first message. The WebView of the second page determines whether the message type broadcast by the native service is a preset message type.
[0117] Optionally, the WebView of the second page can determine whether the first message is a cloud message or an internal message, wherein the determination method is currently not limited. For example, the broadcast rules used by the native service when broadcasting cloud messages are different from the broadcast rules used when broadcasting internal messages. At this time, the WebView of the second page determines whether the first message is a cloud message or an internal message based on the broadcast rules. When the first message is a cloud message, the WebView of the second page calls the protocol content corresponding to the reception of cloud messages provided by the native service through EventBus. When the first message is an internal message, the WebView of the second page calls the protocol content corresponding to the reception of internal messages provided by the native service through EventBus. It can be understood that no matter which protocol content is used, the end result is that the WebView of the second page receives the first message.
[0118] Optionally, the web page can only process cloud messages or only process internal messages. For example, when the second page can only process cloud messages, the WebView of the second page calls the protocol content corresponding to receiving cloud messages provided by the native service through EventBus to ensure that only the corresponding cloud messages are received. When the second page can only process internal messages, the WebView of the second page calls the protocol content corresponding to receiving internal messages provided by the native service through EventBus to ensure that only the corresponding internal messages are received.
[0119] Step 232: The WebView of the second page passes the first message to the second page.
[0120] Exemplarily, after the WebView of the second page receives the first message, it transmits the first message to the second page through JsBridge.
[0121] Optionally, when the first message is a cloud message (i.e., the first message is a message sent by the server of the first application), step 232 may be specifically as follows: the WebView of the second page passes the first message to the second page according to the cloud message receiving protocol. Specifically, the WebView of the second page calls the second page through JsBridge, and based on the cloud message receiving protocol, the second page receives the first message. Among them, the cloud message receiving protocol can be considered as the protocol used by the second page when receiving the cloud message, which can be provided by the second page or by the WebView of the second page.
[0122] When the first message is an internal message (that is, the first message is a message sent by the first page in the first application or a message sent by the first native component in the first application), step 232 may be specifically as follows: the WebView of the second page passes the first message to the second page according to the internal message receiving protocol. Specifically, the WebView of the second page calls the second page through JsBridge, and based on the internal message receiving protocol, the second page receives the first message. Among them, the internal message receiving protocol can be considered as the protocol used by the second page when receiving the internal message, which can be provided by the second page or by the WebView of the second page.
[0123] Step 233: The second page processes the first message.
[0124] After receiving the first message, the second page responds to the first message. Optionally, after responding to the first message, if the response result of the first message needs to be fed back, the second page can generate a message containing the response result, and then send the message to the WebView of the second page, and the WebView of the second page sends the message to the native service, and the native service then delivers the message.
[0125] Optionally, when the second page responds to the first message, if the result of the response needs to be displayed to the user, the second page is displayed in the foreground so that the user can view the response result displayed on the electronic device.
[0126] It is understandable that when a web page is closed, such as when the second page is closed, the WebView of the second page no longer communicates with the native service.
[0127] It should be noted that the first message received by the above-mentioned native service broadcast is a way to achieve message delivery. In actual applications, other methods can also be used to deliver the first message. For example, the native service can directly determine the target object that can respond to the first message and send the first message directly to the target object.
[0128] When the target object is the second native component, after the first application runs the second native component, the second native component can communicate with the native service, that is, observe whether there is a message type that the second native component is concerned about in each message broadcast by the native service.
[0129] In one embodiment, each native component of the first application communicates with the native service via EventBus. Based on Eventbus, the native component can monitor the native service to determine whether the native service broadcasts messages that it can process, and receive messages that can be processed for processing. At this time, step 230 may include steps 234-235:
[0130] Step 234: The second native component receives the first message broadcast by the native service.
[0131] For example, the second native component can also register a service. After the service is registered, the second native component can clarify the service type it handles, and then determine the message type that can be processed. The message type is the message type that the second native component cares about. After that, the second native component can observe whether the native service broadcasts the message type that it cares about.
[0132] In one embodiment, the second native component may monitor the native service, and receive the first message when it detects that the message type of the first message currently broadcast by the native service is a message type that the second native component can process.
[0133] Exemplarily, after the second native component business is registered, it can monitor the native service. At this time, the second native component can monitor every message broadcast by the native service. Currently, take the native service broadcasting the first message as an example. When the native service broadcasts the first message, the second native component can determine that the first message is a business that it can handle. Then, through EventBus, based on the predefined protocol content, call the native service to receive the first message broadcast by the native service. After that, the second native component continues to monitor the native service.
[0134] It can be understood that if the first message is not a business that can be processed by the second native component, the second native component will not receive the first message.
[0135] Among them, the second native component determines whether the message type of the first message is an implementation method that it can process. The implementation method of determining whether the message type of the first message is a preset message type can refer to the WebView of the second page, which is not elaborated at present.
[0136] Optionally, the second native component can determine whether the first message is a cloud message or an internal message. The implementation method can refer to the implementation method of the WebView of the second page to determine whether the first message is a cloud message or an internal message, which will not be described in detail at present. When the first message is a cloud message, the second native component calls the protocol content corresponding to the cloud message provided by the native service through EventBus. When the first message is an internal message, the second native component calls the protocol content corresponding to the internal message provided by the native service through EventBus. It can be understood that no matter which protocol content is used, the final result is that the second native component receives the first message.
[0137] Optionally, the native component can only process cloud messages or only process internal messages. For example, when the second native component can only process cloud messages, the second native component calls the protocol content corresponding to receiving cloud messages provided by the native service through EventBus to ensure that only corresponding cloud messages are received. When the second native component can only process internal messages, the second native component calls the protocol content corresponding to receiving internal messages provided by the native service through EventBus to ensure that only corresponding internal messages are received.
[0138] Step 235: The second native component processes the first message.
[0139] After receiving the first message, the second native component responds to the first message. The implementation process of responding to the first message can refer to the implementation process of the second page responding to the first message, which will not be described in detail at present.
[0140] It is understandable that when a native component stops running, the native component no longer communicates with the native service.
[0141] In the above, the native service of the first application receives the message sent by the first page of the first application, receives the message sent by the first native component of the first application, or receives the message sent by the server of the first application. After that, the native service broadcasts the received message. When the message needs to be processed by the second page of the first application, the second page receives the message broadcast by the native service and processes the message. When the message needs to be processed by the second native component of the first application, the second native component receives the message broadcast by the native service and processes the message. The technical means solves the technical problem of the lack of rationality and low efficiency of application message transmission in the related technology. Compared with the homepage WebView receiving messages, the native service uniformly receives the messages sent by the external server, and the page or native component that processes the message can directly receive the message broadcast by the native service, which can simplify the message transmission path and improve the message transmission efficiency. In addition, it is no longer dependent on the homepage WebView to receive messages, and it can also avoid the disconnection of the first application and the server when the homepage WebView runs in the background for a long time. That is, during the operation of the first application, the native service and the server can maintain a connection, thereby ensuring the timely reception of messages, and only the connection between the native service and the server needs to be maintained, which also saves more resources. In addition, the message transmission between web pages, native components, and web pages and native components within the first application is realized, enriching the message transmission path of the first application. In addition, the message transmission between each web page and the corresponding WebView is realized through JSBridge, and the message transmission between each WebView and each native component and native service is realized through EventBus.
[0142] Figure 5 A flowchart of another message transmission method provided by an embodiment of the present application, Figure 5 Based on the above embodiments, the first message is generated by the first page as an example to describe how the first message is transmitted within the first application. Figure 5 , the message transmission method has the following steps:
[0143] Step 310: The first page generates a first message.
[0144] The manner in which the first page generates the first message is not currently limited. For example, the first message is generated based on the user's operation on the first page. The format of the first message is not currently limited. In an embodiment, the first message at least includes a field for writing a message type.
[0145] Step 320: The first page calls an internal message sending protocol provided by the WebView of the first page, so that the WebView of the first page receives the first message.
[0146] Exemplarily, the first page calls the message sending protocol provided by the WebView of the first page through JsBridge, and based on the message sending protocol, the WebView of the first page can receive the first message. Optionally, the message sending protocol provided by the WebView includes an internal message sending protocol and a cloud message sending protocol. The internal message sending protocol is a protocol used when sending internal messages. The cloud message sending protocol is a protocol used when sending cloud messages. At this time, after the first page generates the first message, when it is determined that the first message is an internal message, the internal message sending protocol provided by the WebView of the first page is called so that the WebView of the first page receives the first message that is an internal message.
[0147] It can be understood that when the first message is a cloud message, the first page calls the cloud message sending protocol provided by the WebView of the first page, so that the WebView of the first page receives the first message which is a cloud message.
[0148] Step 330: The WebView of the first page calls the internal message sending interface of the native service so that the native service receives the first message.
[0149] After the WebView of the first page receives the first message, it calls the Application Programming Interface (API) provided by the native service through EventBus. It can be understood that when WebView passes a message to a native service, it can call the corresponding API provided by the native service based on the predefined protocol content, and then pass the message to the native service through the API. Currently, the APIs provided by the native service include an internal message sending interface and a cloud message sending interface. Among them, the internal message sending interface is an API for sending internal messages to native services. The cloud message sending interface is an API for sending cloud messages to native services.
[0150] Optionally, when the WebView of the first page receives the first message through the internal message sending protocol, it determines that the first message is an internal message. At this time, the WebView of the first page calls the internal message sending interface provided by the native service so that the native service receives the first message. At this time, when the native service receives the first message based on the internal message sending interface, it can be determined that the first message is an internal message. It can be understood that when the first message is a cloud message, the WebView of the first page calls the cloud message sending interface provided by the native service so that the native service receives the first message.
[0151] It is understandable that the first message can also be generated by the first native component and sent to the native service. Among them, the process of the first native component generating the first message can refer to the process of the first page generating the first message. Afterwards, the first native component sends the first message to the native service. Similar to the first page, the first native component calls the API provided by the native service through EventBus to pass the first message to the native service. At this time, the first native component can also determine whether the first message is an internal message or a cloud message. When the first message is an internal message, the first native component calls the internal message sending interface provided by the native service so that the native service receives the first message. It is understandable that when the first message is a cloud message, the first native component calls the cloud message sending interface provided by the native service so that the native service receives the first message. Optionally, the API provided when transmitting messages between the native service and the native component may be the same as or different from the API provided when transmitting messages between the native service and the WebView, and the embodiment does not limit this.
[0152] Step 340: The native service in the first application receives a first message, where the first message is used for processing by a target object in the first application, where the target object is a second page or a second native component.
[0153] Step 350: The native service broadcasts a first message in the first application.
[0154] Optionally, the native service parses the first message according to the message type of the first message to obtain the message entity of the first message, and broadcasts the message entity of the first message in the first application.
[0155] Step 360: The target object in the first application receives the first message broadcast by the native service and processes the first message.
[0156] As described above, when the first page generates the first message that is an internal message, the internal message sending protocol provided by the WebView of the first page is called, so that the WebView of the first page receives the first message that is an internal message. Afterwards, the WebView of the first page calls the internal message sending interface provided by the native service, so that the native service receives the first message that is an internal message. This allows the first application to have a corresponding protocol and API when transmitting the internal message, thereby realizing separate processing of the internal message and the cloud message, thereby improving the message delivery efficiency.
[0157] In one embodiment of the present application, the first application may also transmit a message to the server, or transmit a message to other applications (applications that can handle the same business) through the server. Figure 6 A flowchart of another message transmission method provided by an embodiment of the present application, Figure 6Based on the above embodiments, the process of the first application transmitting a cloud message to the outside is described exemplarily. Figure 6 , the message transmission method comprises:
[0158] Step 410: The third page in the first application generates a second message, and the second message is used for processing by the second application.
[0159] In one embodiment, a web page in a first application generates a cloud message for external transmission as an example for description. Currently, the web page that generates the message is recorded as a third page. The cloud message generated by the third page for external transmission is recorded as a second message. The third page and the first page or the second page can be the same web page or different web pages.
[0160] Currently, the second message is used for other applications provided by the server to respond. In the embodiment, the application responding to the second message is recorded as the second application.
[0161] The process of the third page generating the second message can refer to the process of the first page generating the first message. Optionally, the cloud message and the internal message transmitted in the first application can have different formats. In this case, the third page generates the second message according to the format of the cloud message. The first page generates the first message according to the format of the internal message.
[0162] Step 420: The third page calls the cloud message sending protocol provided by the WebView of the third page, so that the WebView of the third page receives the second message.
[0163] Exemplarily, the third page calls the message sending protocol provided by the WebView of the third page through JsBridge, and based on the message sending protocol, the WebView of the third page can receive the second message.
[0164] Optionally, when the third page generates the second message, it can be made clear that the second message is a cloud message. At this time, the third page calls the cloud message sending protocol provided by the WebView of the third page, so that the WebView of the third page receives the third message belonging to the cloud message.
[0165] Step 430: The WebView of the third page calls the cloud message sending interface of the native service so that the native service receives the second message.
[0166] After the WebView of the third page receives the second message, it calls the API provided by the native service through EventBus. Optionally, when the WebView of the third page receives the second message through the cloud message sending protocol, it determines that the second message is a cloud message. At this time, the WebView of the third page calls the cloud message sending interface provided by the native service so that the native service receives the second message. At this time, when the native service receives the second message based on the cloud message sending interface, it can determine that the second message is a cloud message.
[0167] Step 440: The native service sends the second message to the server, so that the server sends the second message to the second application for processing.
[0168] Exemplarily, the native service sends the second message to the background service of the server via WebSocket. The server and the second application are also connected via WebSocket. After receiving the second message, the server sends the second message to the second application via WebSocket. Afterwards, the second application receives the second message and responds to the second message.
[0169] Among them, the implementation method of the server determining the second application that should receive the second message is currently not limited. For example, the second message includes a communication address in the second application, and the server sends the second message to the second application corresponding to the communication address based on the communication address in the second message.
[0170] It is understandable that the second message can also be used for the server to respond. In this case, after receiving the second message, the server directly responds. If the response result needs to be fed back to the first application, a cloud message containing the response result can be generated and sent to the native service of the first application. After that, the native service processes it according to the processing method of receiving the cloud message.
[0171] It is understandable that the native component in the first application can also send cloud messages. Currently, the native component that generates the cloud message is recorded as the third native component. It is understandable that the third native component can be the same native component as the first native component or the second native component, or it can be a different native component. Currently, the cloud message generated by the third native component is recorded as the third message. After the third native component generates the third message, it calls the cloud message sending interface provided by the native service through EventBus so that the native service receives the third message. Afterwards, the native service sends the third message to the server through WebSocket, and then the server responds to the third message or sends a cloud message to other applications. For example, when the third message is used for a third application to respond, the server sends the third message to the third application.
[0172] As mentioned above, when the third page generates the second message belonging to the cloud message, the cloud message sending protocol provided by the WebView of the third page is called, so that the WebView of the third page receives the second message belonging to the cloud message. Afterwards, the WebView of the third page calls the cloud message sending interface provided by the native service, so that the native service receives the second message belonging to the cloud message. This can achieve that when the first application transmits the cloud message to the server, it has the corresponding protocol and API, thereby realizing the separate processing of internal messages and cloud messages, thereby improving the message delivery efficiency.
[0173] The following is an exemplary description of the message transmission method provided in the embodiment of the present application. In this example, Figure 7 This is a second example diagram of a message transmission path provided by an embodiment of the present application. It should be noted that: Figure 7 Two web pages and one native component in the first application are shown by way of example, but the number of web pages and native components is not limited.
[0174] Figure 7 In the example, the WebViews corresponding to the two web pages are the WebView of the home page and the WebView of other pages (not the home page). Native components are native components that rely on messages. Each web page communicates with the corresponding WebView through JsBridge, and each WebView and native component communicates with the native service through EventBus. The native service communicates with the server's background service through websocket.
[0175] The protocol content for transmitting messages between native services, web pages and WebView is pre-defined, among which internal messages and cloud messages correspond to different protocol contents.
[0176] When a web page (such as the first page) transmits an internal message to another web page (such as the second page), the transmission process is as follows: Figure 8 As shown, reference Figure 8 , when the transmission starts, the first page calls the internal message sending protocol provided by WebView through JsBridge. The WebView of the first page receives the internal message, and calls the internal message sending interface provided by the native service through EventBus. After the native service receives the internal message, it parses the message entity of the internal message according to the message type of the internal message, and broadcasts the message entity of the internal message. The WebView of the second page receives the message entity of the internal message by listening to the native service. Afterwards, the WebView of the second page sends the message entity of the internal message to the second page through JsBridge according to the internal message receiving protocol, and the second page responds to the message entity of the internal message.
[0177] When the first application receives a cloud message sent by the server, the delivery process is as follows: Fig. 9 As shown, reference Fig. 9 , other applications send cloud messages to the server's background service through WebSocket. The background service passes the cloud message to the native service of the first application through WebSocket. After the native service receives the cloud message, it parses the message entity of the cloud message according to the message type of the cloud message and broadcasts the message entity of the cloud message. Currently, taking the second page response message entity as an example, the WebView of the second page receives the message entity of the cloud message by monitoring the native service. Afterwards, the WebView of the second page sends the message entity of the cloud message to the second page through JsBridge, and the second page responds to the message entity of the cloud message.
[0178] At this time, since the WebView and native components of different web pages can communicate with native services, and communicate with other internal web page WebViews, other native components and background services through native services. Therefore, when the first application responds to different businesses at the same time, the transmission of messages corresponding to different businesses can also be realized. For example, when the WebView on the home page needs to communicate with the background service to refresh data, and other WebViews need to communicate with the background service to realize instant messaging or customer service, the WebView on the home page and other WebViews can communicate with the background service based on native services. Even if the WebView on the home page runs in the background, it does not respond to the transmission of messages. Compared with the home page WebView receiving and forwarding the transmitted messages, the transmission path based on native services is shorter and more efficient.
[0179] It can be understood that in addition to communicating with the server through native services, each WebView can also communicate directly with the server. At this time, each WebView can be connected to the server bidirectionally through WebSocket, thereby realizing direct message transmission between the WebView and the server.
[0180] Fig.10 A schematic diagram of a message transmission device provided by an embodiment of the present application. Fig.10 The content sharing device includes: a first receiving unit 501, a broadcasting unit 502, and a second receiving unit 503.
[0181] The first receiving unit 501 is used to enable the native service in the first application to receive the first message, the first message is a message sent by the first page in the first application, a message sent by the first native component in the first application, or a message sent by the server of the first application, and the first message is used for processing by the target object in the first application, and the target object is the second page or the second native component. The broadcasting unit 502 is used to enable the native service to broadcast the first message in the first application. The second receiving unit 503 is used to enable the target object in the first application to receive the first message broadcast by the native service and process the first message.
[0182] In one embodiment of the present application, the broadcast unit 502 includes: a parsing subunit, used to enable the native service to parse the message entity of the first message according to the message type of the first message; and an entity broadcasting subunit, used to enable the native service to broadcast the message entity of the first message in the first application.
[0183] In one embodiment of the present application, when the target object is the second page, the second receiving unit 503 includes: a message receiving subunit, used to enable the WebView of the second page to receive the first message broadcast by the native service; a message transmission subunit, used to enable the WebView of the second page to transmit the first message to the second page; and a message processing subunit, used to enable the second page to process the first message.
[0184] In one embodiment of the present application, the message receiving subunit is specifically used to enable the WebView of the second page to monitor the native service, and receive the first message when it is detected that the message type of the first message currently broadcast by the native service meets the preset message type.
[0185] In one embodiment of the present application, when the first message is a message sent by the first page in the first application or a message sent by the first native component in the first application, the message delivery subunit is specifically used to enable the WebView of the second page to deliver the first message to the second page according to the internal message receiving protocol. When the first message is a message sent by the server of the first application, the message delivery subunit is specifically used to enable the WebView of the second page to deliver the first message to the second page according to the cloud message receiving protocol.
[0186] In one embodiment of the present application, when the first message is a message sent by the first page in the first application, the device also includes: a first generating unit, used to enable the first page to generate the first message; a first calling unit, used to enable the first page to call the internal message sending protocol provided by the WebView of the first page, so that the WebView of the first page receives the first message; a second calling unit, used to enable the WebView of the first page to call the internal message sending interface of the native service, so that the native service receives the first message.
[0187] In one embodiment of the present application, each page of the first application communicates with the corresponding WebView via JSBridge; the WebView of each page communicates with the native service via EventBus.
[0188] In one embodiment of the present application, each native component of the first application communicates with the native service via EventBus.
[0189] In one embodiment of the present application, the device also includes: a second generating unit, configured to enable the third page in the first application to generate a second message, the second message being used for processing by the second application. A third calling unit, configured to enable the third page to call the cloud message sending protocol provided by the WebView of the third page, so that the WebView of the third page receives the second message. A fourth calling unit, configured to enable the WebView of the third page to call the cloud message sending interface of the native service, so that the native service receives the second message. A sending unit, configured to enable the native service to send the second message to the server, so that the server sends the second message to the second application for processing.
[0190] The message transmission device provided in the embodiments of the present application can be used to execute the message transmission method provided in any of the above embodiments, and has corresponding functions and beneficial effects.
[0191] It is worth noting that in the embodiment of the above-mentioned message transmission device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention.
[0192] An embodiment of the present application also provides a message transmission device, which can refer to Figure 2 The structure of the electronic device shown. The message transmission device includes a message transmission device, which can be used to execute any message transmission method and has corresponding functions and beneficial effects.
[0193] An embodiment of the present invention also provides a storage medium containing computer executable instructions, which, when executed by a computer processor, are used to perform relevant operations in the message transmission method provided in any embodiment of the present application, and have corresponding functions and beneficial effects.
[0194] Those skilled in the art should understand that the embodiments of the present application may be provided as methods, systems, or computer program products.
[0195] Therefore, the present application may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the functions in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing the process in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0196] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory. The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0197] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0198] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0199] Note that the above are only preferred embodiments of the present application and the technical principles used. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present application. Therefore, although the present application is described in more detail through the above embodiments, the present application is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the appended claims.
Claims
1. A message transmission method, characterized in that: include: The native service in the first application receives a first message, where the first message is a message sent by a first page in the first application, a message sent by a first native component in the first application, or a message sent by a server of the first application, and the first message is used for processing by a target object in the first application, where the target object is a second page or a second native component; The native service broadcasts the first message in the first application; The target object in the first application receives the first message broadcast by the native service and processes the first message.
2. The message transmission method according to claim 1, characterized in that: The native service broadcasts the first message in the first application, including: The native service parses the first message according to the message type of the first message to obtain a message entity of the first message; The native service broadcasts a message entity of the first message in the first application.
3. The message transmission method according to claim 1, characterized in that: When the target object is the second page, the target object in the first application receives the first message broadcast by the native service and processes the first message, including: The WebView of the second page receives the first message broadcast by the native service; The WebView of the second page transmits the first message to the second page; The second page processes the first message.
4. The message transmission method according to claim 3, characterized in that: The WebView of the second page receives the first message broadcast by the native service, including: The WebView of the second page monitors the native service, and receives the first message when it is detected that the message type of the first message currently broadcast by the native service meets the preset message type.
5. The message transmission method according to claim 3, characterized in that: When the first message is a message sent by a first page in the first application or a message sent by a first native component in the first application, the WebView of the second page transmits the first message to the second page, including: The WebView of the second page transmits the first message to the second page according to an internal message receiving protocol; When the first message is a message sent by the server of the first application, the WebView of the second page transmits the first message to the second page, including: The WebView of the second page transmits the first message to the second page according to the cloud message receiving protocol.
6. The message transmission method according to claim 1, characterized in that: When the first message is a message sent by the first page in the first application, the method further includes: The first page generates a first message; The first page calls an internal message sending protocol provided by the WebView of the first page, so that the WebView of the first page receives the first message; The WebView of the first page calls the internal message sending interface of the native service so that the native service receives the first message.
7. The message transmission method according to any one of claims 3 to 6, characterized in that: Each page of the first application communicates with the corresponding WebView via JSBridge; The WebView of each page communicates with the native service through EventBus.
8. The message transmission method according to claim 1, characterized in that: Each native component of the first application communicates with the native service via EventBus.
9. The message transmission method according to claim 1, characterized in that: Also includes: The third page in the first application generates a second message, where the second message is used for processing by the second application; The third page calls the cloud message sending protocol provided by the WebView of the third page, so that the WebView of the third page receives the second message; The WebView of the third page calls the cloud message sending interface of the native service, so that the native service receives the second message; The native service sends the second message to the server, so that the server sends the second message to the second application for processing.
10. A message transmission device, characterized in that: include: A first receiving unit is configured to enable a native service in a first application to receive a first message, wherein the first message is a message sent by a first page in the first application, a message sent by a first native component in the first application, or a message sent by a server of the first application, and the first message is used for processing by a target object in the first application, and the target object is a second page or a second native component; a broadcast unit, configured to enable the native service to broadcast the first message in the first application; The second receiving unit is configured to enable a target object in the first application to receive the first message broadcast by the native service and process the first message.
11. A message transmission device, characterized in that: include: one or more processors; a communication module, configured to communicate according to instructions of the processor; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the message transmission method as described in any one of claims 1 to 9.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the message transmission method as described in any one of claims 1 to 9 is implemented.
