Ethernet sharing method based on Android system

文档序号:142947 发布日期:2021-10-22 浏览:32次 中文

阅读说明:本技术 基于Android系统的以太网共享方法 (Ethernet sharing method based on Android system ) 是由 王安兴 程玉 胡锐生 于 2021-07-16 设计创作,主要内容包括:本发明公开了一种基于Android系统的以太网共享方法,包括以下步骤:S1,开启以太网共享开关,包括在设置界面中增加一个以太网共享的开关按钮提供了代码接口,或者将开关功能集成到APK源码中,设置开启以太网共享的接口函数,指定一个开启参数即可完成打开的功能;S2,判断以太网是否已就绪,如果以太网已经准备就绪就继续下一步,否则返回一个错误信息提示共享失败;S3,判断指定源网络并判断源网络是否已就绪,系统通过调用Android自带网络管理工具类中的“检查网络是否连接”的方法,来判断指定的网络是否已连接成功;S4,配置包括子网的网段和DNS的信息;S5,开启DHCP服务和网络转发,进入网络共享状态。(The invention discloses an Ethernet sharing method based on an Android system, which comprises the following steps: s1, turning on the Ethernet sharing switch, including adding an Ethernet sharing switch button in the setting interface to provide a code interface, or integrating the switch function into APK source code, setting the interface function for turning on the Ethernet sharing, and designating a turn-on parameter to complete the turn-on function; s2, judging whether the Ethernet is ready, if the Ethernet is ready, continuing the next step, otherwise returning an error message to prompt the sharing failure; s3, judging whether the specified source network is ready or not, and judging whether the specified network is successfully connected or not by calling a method for checking whether the network is connected or not in the Android self-contained network management tool class by the system; s4, configuring information including the network segment of the subnet and the DNS; s5, starting DHCP service and network forwarding, and entering into network sharing state.)

1. An Ethernet sharing method based on an Android system is characterized by comprising the following steps:

s1, turning on the Ethernet sharing switch, including adding an Ethernet sharing switch button in the setting interface to provide a code interface, or integrating the switch function into APK source code, setting the interface function for turning on the Ethernet sharing, and designating a turn-on parameter to complete the turn-on function;

s2, judging whether the Ethernet is ready, if the Ethernet is ready, continuing the next step, otherwise returning an error message to prompt the sharing failure;

s3, judging a designated source network and judging whether the source network is ready, judging whether the designated network is successfully connected or not by calling a method of checking whether the network is connected or not in an Android self-contained network management tool class by the system, if the network is connected and the source network is ready, taking the network as the source network shared by the Ethernet, and if the network is not connected and the source network is not ready, returning a corresponding error code;

s4, configuring information including the network segment of the subnet and the DNS;

s5, starting DHCP service and network forwarding, and entering into network sharing state.

2. The Android system-based Ethernet sharing method of claim 1, wherein S2 specifically comprises: firstly, finding out a network node of the Ethernet, monitoring the connection state change information of a bottom Ethernet port through the node, if the Linkup information of the port appears, successfully connecting an Ethernet link layer, indicating that the Ethernet is ready, and using the Ethernet as a shared network; if the information of the Link down appears, the Ethernet Link layer is disconnected, the Ethernet can not be used as a sharing network at the moment, the Ethernet sharing fails, and if the sharing is opened before, the Ethernet sharing function is closed at the moment.

3. The Android system-based Ethernet sharing method of claim 1, wherein S4 specifically comprises: in the specific code for starting the network sharing function, the original fixed IP address and DNS function are deleted, in the configuration of the Ethernet interface, the appointed IP address and DNS variable information are read from a memory each time, the appointed IP address pool is allocated after the shared service is started, the shared service is configured in the DHCP service, the IP address obtained by the network equipment is in the configured network segment, or the appointed DNS address is configured in the DNS service of the system, and the network management service interface is called to set the appointed DNS server.

4. The Ethernet sharing method based on the Android system as claimed in any one of claims 1 to 3, further comprising monitoring connection states and information of all subnet devices, if a user needs to monitor the connection states of the subnet devices, the user needs to register a network listener first, call a network monitoring module to register a listener, periodically send a network packet to all subnet devices, judge the connection state by checking network packet conditions replied by all subnet devices, if the reply can be received, the subnet device is in the connection state, otherwise, the subnet device is disconnected; if the result of the check is different from the last time, a state change notification is sent to the monitor and is accompanied with specific state change information, and if monitoring needs to be stopped, a network monitoring module is called.

5. The Android system-based Ethernet sharing method of any one of claims 1 to 3, further comprising providing an API interface for a client to switch on and off the Ethernet sharing and adjust the configuration of the Ethernet sharing in a program.

Technical Field

The invention belongs to the technical field of Android system application, and particularly relates to an Ethernet sharing method based on an Android system.

Background

Many android industrial control devices on the market contain ethernet ports, and after a large number of users purchase the industrial control devices, other devices need to use the ethernet ports to realize the requirement of external network access, such as a network camera. In order to facilitate users and reduce unnecessary wired networking and additional expenses, a 4G routing device that can be used in an open environment is urgently needed.

In the Android native system, a function called a portable WLAN hotspot is provided, and the function can configure the Android mobile phone into an AP hotspot and is similar to a function of a simplified version 4G router. After the network is started, the 4G at the moment is called as a source network, and the WIFI is called as a shared network. However, it has the following disadvantages: (1) an Ethernet port cannot be configured to realize Ethernet sharing for a sharing network; (2) no source network can be specified (only the system's own default source network can be used); (3) the network segment and DNS of the subnet cannot be configured; (4) the connection state and information of all the sub-network devices connected to the shared network cannot be monitored and checked; (5) no API interface is provided to control the turning on and off of the network sharing function.

Disclosure of Invention

In view of the above technical problems, the present invention is directed to providing an ethernet sharing method based on an Android system.

In order to solve the technical problems, the invention adopts the following technical scheme:

an Ethernet sharing method based on an Android system comprises the following steps:

s1, turning on the Ethernet sharing switch, including adding an Ethernet sharing switch button in the setting interface to provide a code interface, or integrating the switch function into APK source code, setting the interface function for turning on the Ethernet sharing, and designating a turn-on parameter to complete the turn-on function;

s2, judging whether the Ethernet is ready, if the Ethernet is ready, continuing the next step, otherwise returning an error message to prompt the sharing failure;

s3, judging a designated source network and judging whether the source network is ready, judging whether the designated network is successfully connected or not by calling a method of checking whether the network is connected or not in an Android self-contained network management tool class by the system, if the network is connected and the source network is ready, taking the network as the source network shared by the Ethernet, and if the network is not connected and the source network is not ready, returning a corresponding error code;

s4, configuring information including the network segment of the subnet and the DNS;

s5, starting DHCP service and network forwarding, and entering into network sharing state.

Preferably, S2 specifically includes: firstly, finding out a network node of the Ethernet, monitoring the connection state change information of a bottom Ethernet port through the node, if the Linkup information of the port appears, successfully connecting an Ethernet link layer, indicating that the Ethernet is ready, and using the Ethernet as a shared network; if the information of the Link down appears, the Ethernet Link layer is disconnected, the Ethernet can not be used as a sharing network at the moment, the Ethernet sharing fails, and if the sharing is opened before, the Ethernet sharing function is closed at the moment.

Preferably, S4 specifically includes: in the specific code for starting the network sharing function, the original fixed IP address and the function of a DNS are deleted, in the method for configuring the Ethernet interface configureEthface, the appointed IP address and DNS variable information are read from a memory each time, an appointed IP address pool is allocated after the shared service is started, the IP address pool is configured in the DHCP service, the IP address obtained by the network equipment is in the configured network segment, or the appointed DNS address is configured in the DNS service of a system, and an interface of a network management module is called to set an appointed DNS server.

Preferably, the method further comprises monitoring the connection state and information of all the subnet devices, if the user needs to monitor the connection state of the subnet devices, the user needs to register a network listener first, call the network monitoring module to register a listener, periodically send a network packet to all the subnet devices, judge the connection state by checking the network packet condition replied by all the subnet devices, if the reply can be received, the subnet devices are in the connection state, otherwise, the subnet devices are disconnected; if the result of the check is different from the last time, a state change notification is sent to the monitor and is accompanied with specific state change information, and if monitoring needs to be stopped, a network monitoring module is called.

Preferably, the method further comprises providing an API interface for the client to switch the ethernet share and adjust the configuration of the ethernet share in the program.

The invention has the following beneficial effects:

(1) ethernet may be configured to enable ethernet sharing;

(2) the network source may be designated as the source network for the ethernet share;

(3) the network segment IP address and DNS information of the shared sub-network can be freely configured;

(4) the connection state and information of all the sub-network devices connected to the shared network can be monitored and checked;

(5) an API interface is provided to allow the client to switch on and off the ethernet share and adjust the configuration of the ethernet share in the program.

Drawings

Fig. 1 is a flowchart illustrating steps of an ethernet sharing method based on an Android system according to an embodiment of the present invention.

Detailed Description

The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

Referring to fig. 1, shown is a flowchart illustrating steps of an ethernet sharing method based on an Android system according to an embodiment of the present invention, including the following steps:

s1, turning on the Ethernet sharing switch, including adding an Ethernet sharing switch button in the setting interface to provide a code interface, or integrating the switch function into APK source code, setting the interface function for turning on the Ethernet sharing, and designating a turn-on parameter to complete the turn-on function;

s2, judging whether the Ethernet is ready, if the Ethernet is ready, continuing the next step, otherwise returning an error message to prompt the sharing failure;

s3, judging a designated source network and judging whether the source network is ready, judging whether the designated network is successfully connected or not by calling a method of checking whether the network is connected or not in an Android self-contained network management tool class by the system, if the network is connected and the source network is ready, taking the network as the source network shared by the Ethernet, and if the network is not connected and the source network is not ready, returning a corresponding error code;

s4, configuring information including the network segment of the subnet and the DNS;

s5, starting DHCP service and network forwarding, and entering into network sharing state.

In a specific application example, S2 specifically includes: firstly, finding out a network node of the Ethernet, monitoring the connection state change information of a bottom Ethernet port through the node, if the Link up information of the port appears, successfully connecting an Ethernet Link layer, indicating that the Ethernet is ready, and using the Ethernet as a shared network; if the information of the Link down appears, the Ethernet Link layer is disconnected, the Ethernet can not be used as a sharing network at the moment, the Ethernet sharing fails, and if the sharing is opened before, the Ethernet sharing function is closed at the moment.

In a specific application example, S4 specifically includes: in the method for configuring the Ethernet interface, appointed IP address and DNS variable information are read from a memory each time, an appointed IP address pool is allocated after the shared service is started, the IP address pool is configured in the DHCP service, the IP address obtained by the network equipment is in a configured network segment, or the appointed DNS address is configured in the DNS service of a system, and an interface of the network management service is called to set an appointed DNS server.

In the specific application example, the method further comprises monitoring the connection state and information of all the subnet equipment, if the user needs to monitor the connection state of the subnet equipment, the user needs to register a network monitor first, call a network monitoring module to register a monitor, periodically send a network packet to all the subnet equipment, judge the connection state by checking the network packet condition replied by all the subnet equipment, if the reply can be received, the subnet equipment is in the connection state, otherwise, the subnet equipment is disconnected; if the result of the check is different from the last time, a state change notification is sent to the monitor and is accompanied with specific state change information, and if monitoring needs to be stopped, a network monitoring module is called.

In a specific application example, the method further comprises the step of providing an API (application programming interface) to enable a client to switch on and off the Ethernet sharing in a program and adjust the configuration condition of the Ethernet sharing.

It is to be understood that the exemplary embodiments described herein are illustrative and not restrictive. Although one or more embodiments of the present invention have been described with reference to the accompanying drawings, it will be understood by those of ordinary skill in the art that various changes in form and details may be made therein without departing from the spirit and scope of the present invention as defined by the following claims.

6页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:处理SSB传输和周期性传输之间的冲突的装置和方法

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!