Years ago, I studied how Android can implement the Wireless Data Transfer Function and wrote a demo. I have nothing to do with it recently. I want to sort it out and share it with you. Early research found that Android has the following technologies to achieve wireless data transfer: 1. Bluetooth has been used for a long time and is easy to use. However, the slow speed is hard to solve; 2. NFC, officially supported since API 9, however, various manufacturers have a wait-and-see attitude towards this technology. For example, Samsung does not have the NFC hardware, and NFC is applicable to a small amount of data transmission in the near field. The data volume has not been tested yet, however, NFC's so-called near-field distance requirements are quite harsh, basically need to be pasted to pass; 3, WIFI-P2P, transmission speed, and P2P makes the two devices each other C/S, transmission can be performed in two directions. It is officially supported since API 14. Considering that there is a huge amount of equipment maintenance under API 14, this technology can only be abandoned for the time being.
Weigh on, refer to the current various types of wireless fast transmission software, and finally determine to use the Wifi AP method, self-testing compatibility with API 8 devices, fast transmission speed, but only one-way transmission. The Client connects to the Wifi AP enabled on the Server through Wifi. After the connection is successful, the Client initiates an Http request to the Server through HttpEngine. The Server provides the response service to the Client through a simple HttpServer, the following uses a non-standard flowchart to outline the solution process:
Before uploading a project, briefly explain several important classes in the source code:
Client
WifiApClientManager: encapsulates the WifiManager interface for enabling, connecting, and other operations.
HttpEngineLite: the "engine" class that initiates Http requests
WifiApClientRequest: Request abstract class, subclass WifiApClientGetRecvListRequest, and WifiApClientGetFileRequest indicate obtaining the list of files to be uploaded from the Server and getting the specified file requests from the Server respectively. Use HttpEngineLite
NanoHTTPClient: Provides operation interfaces for obtaining the list of files to be uploaded on the Server, obtaining specified files on the Server, and managing WifiApClientRequest using the thread pool.
Server
WifiApServerManager: encapsulate the WifiManager interface to enable AP and configure AP.
WifiApServerUtil: defines the IP address of the general gateway for Android AP.
NanoHTTPD: this class is the referenced open source code (A simple, tiny, nicely embeddable HTTP server in Java)
NanoHTTPServer: a subclass of NanoHTTPD. It implements its interface and returns the corresponding HttpResponse.
Read the fucking source code:
Http://files.cnblogs.com/zealotrouge/WifiAPDemo.7z