An explanation of peer application on Android Research's intel® android* developer Guide

Source: Internet
Author: User

Brief introduction

When there is no Wi-Fi access point or Internet access, the Android* app may require a peering connection to establish a connection between two or more android* devices. For example, file sharing apps and multiplayer games.

This feature can be implemented using NFC, Bluetooth, or Wi-Fi peering technology. The preferred technology in a particular case needs to be determined based on the desired distance, connection speed, power dissipation, and unique technical characteristics.

This article evaluates the Wi-Fi peering technology. Wi-Fi peering enables Android 4.0 or later with the appropriate app to connect to each other over Wi-Fi without an access point. The Android Wi-Fi peer framework complies with Wi-Fi Direct standards. In general, Wi-Fi Direct supports faster and farther distances, but requires a higher power consumption than Bluetooth connectivity. The previous chapter studies the android* Bullet physics engine porting to Intel architecture

Implement

This article focuses on the basic steps for establishing a socket connection between two Android devices.

To use Wi-Fi peer, the app must have the minimum Software Development Kit version correctly set to 14 and request the following license in the Androidmanifest.xml file:

    • Access_wifi_state

    • Change_wifi_state

    • Access_network_state

    • Change_network_state

    • INTERNET

The application needs to call the Initialize () method of the Wifip2pmanager object to register the app with the Wi-Fi peer framework. This method must be called before performing a Wi-Fi peer operation.

The app needs to create and register a broadcast sink for the following Wi-Fi peer intent:

    • Wifi_p2p_connection_changed_action

    • Wifi_p2p_peers_changed_action

    • Wifi_p2p_state_changed_action

    • Wifi_p2p_this_device_changed_action

After performing the above steps, the app will be able to call the Wi-Fi peer-to Wifip2pmanager object and receive Wi-Fi peer intent. Most of the Wifip2pmanager methods are asynchronous, so developers need to provide listener for each method call to get state and results.

To discover available Wi-Fi peer devices, you need to call the Discoverpeers () method of the Wifip2pmanager object. The discovery process will continue to be performed, knowing that the device is turning on Wi-Fi peer connections or calling the Stoppeerdiscovery method.

When the app receives wifi_p2p_peers_changed_action intent, the Requestpeers () method using the Wifip2pmanager object will be able to get a list of the peer devices found.

To connect to a device in the obtained peer list, you need to prepare the Wifip2pconfig object containing the full DeviceAddress field and invoke the Connect () method of the Wifip2pmanager object.

After a successful connection, the device IP address is obtained by calling the Requestconnectinfo () method of the Wifip2pmanager object.

Then, use the IP address to create a Socket and ServerSocket object. Use the standard socket interface to perform communication.

The following is a diagram that invokes a method and receives intent to prepare a connection for a Wi-Fi peer device:

650) this.width=650; "width=" 773 "height=" 757 "title=" Android research on the Intel android* Developer Guide for peer-to-face application details (57)-1th | Successful Smart network-focus on game programming development! "Alt=" Android research on the Intel android* Developer Guide for peer-to-face application details (57)-1th | Successful Smart network-focus on game programming development! "src=" Http://www.cgzhw.com/wp-content/uploads/2014/08/150.png "/>

To establish a Wi-Fi peer connection between two Android devices, you need to perform these steps at least. Apps should implement handlers for all Wi-Fi peer intent and listener to fully respond to different events, such as lost connections or Wi-fi disabled. Please refer to the Android documentation for more information.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.