{"id":18687970,"url":"https://github.com/anitaa1990/wifi-connect","last_synced_at":"2025-06-26T17:32:18.986Z","repository":{"id":47544290,"uuid":"129410602","full_name":"anitaa1990/Wifi-Connect","owner":"anitaa1990","description":"A library project to connect two devices using Wifi-Direct","archived":false,"fork":false,"pushed_at":"2019-11-05T13:12:05.000Z","size":1502,"stargazers_count":108,"open_issues_count":6,"forks_count":54,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-12T05:33:27.734Z","etag":null,"topics":["android","android-library","android-sdk","broadcastreceiver","data","java","receiver","sender","share","wifi-connection","wifi-direct","wifip2pconnectioncallback-interface","wrapper"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anitaa1990.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-13T14:05:48.000Z","updated_at":"2024-12-28T06:11:45.000Z","dependencies_parsed_at":"2022-09-10T06:20:59.502Z","dependency_job_id":null,"html_url":"https://github.com/anitaa1990/Wifi-Connect","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/anitaa1990/Wifi-Connect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anitaa1990%2FWifi-Connect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anitaa1990%2FWifi-Connect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anitaa1990%2FWifi-Connect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anitaa1990%2FWifi-Connect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anitaa1990","download_url":"https://codeload.github.com/anitaa1990/Wifi-Connect/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anitaa1990%2FWifi-Connect/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262113250,"owners_count":23260986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","android-sdk","broadcastreceiver","data","java","receiver","sender","share","wifi-connection","wifi-direct","wifip2pconnectioncallback-interface","wrapper"],"created_at":"2024-11-07T10:35:04.848Z","updated_at":"2025-06-26T17:32:18.923Z","avatar_url":"https://github.com/anitaa1990.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![152px](https://user-images.githubusercontent.com/38810169/40613662-45cd4bea-62a1-11e8-9584-cb389821cbaf.png)\n\n# Wifi-Connect\n\n\u003ca href=\"https://android-arsenal.com/details/1/6930\"\u003e\u003cimg src=\"https://img.shields.io/badge/Android%20Arsenal-Wifi--Connect-blue.svg?style=flat\" alt=\"Android Arsenal\" data-canonical-src=\"https://img.shields.io/badge/Android%20Arsenal-Wifi--Connect-blue.svg?style=flat\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n\nA simple wrapper module to connect two devices and share data using Wifi-Direct.\n\nThis library provides an easy way to access the wifi direct api provided by Android without having to deal with all the boilerplate stuff going on inside.\n\n\n\u003ch2\u003eSample App\u003c/h2\u003e\n\u003cp\u003e\u003ca href=\"https://play.google.com/store/apps/details?id=com.wifi.server\" target=\"_blank\"\u003e\u003cimg width=\"150\" alt=\"Get it on Google Play\" src=\"https://camo.githubusercontent.com/ccb26dee92ba45c411e669aae47dcc0706471af7/68747470733a2f2f706c61792e676f6f676c652e636f6d2f696e746c2f656e5f67622f6261646765732f696d616765732f67656e657269632f656e5f62616467655f7765625f67656e657269632e706e67\" data-canonical-src=\"https://play.google.com/intl/en_gb/badges/images/generic/en_badge_web_generic.png\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n\u003cp\u003eDownload the sample app on the Google Play Store and check out all the features\u003c/p\u003e\n\u003cp\u003e\n\u003ca href=\"https://lh3.googleusercontent.com/np6mWFTBu0GFah9BhO53E2ew5RgychG79Jh9x2Yp1wX_Omb2Eal_3bIL-amWXeDQVX8=h310-rw\" target=\"_blank\"\u003e\u003cimg src=\"https://github.com/anitaa1990/Wifi-Connect/blob/master/media/Screenshot_20180416-080937.png\" width=\"180\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n\u003ca href=\"https://lh3.googleusercontent.com/9q35IMOhQsRAoxCfxHsxBd2S62Ke_yXG_ivgFZwxoCQqVYEFJ7nqu11j_k0QALASYDE=h310-rw\" target=\"_blank\"\u003e\u003cimg src=\"https://github.com/anitaa1990/Wifi-Connect/blob/master/media/Screenshot_20180416-080943.png\" width=\"180\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n\u003ca href=\"https://lh3.googleusercontent.com/9q35IMOhQsRAoxCfxHsxBd2S62Ke_yXG_ivgFZwxoCQqVYEFJ7nqu11j_k0QALASYDE=h310-rw\" target=\"_blank\"\u003e\u003cimg src=\"https://github.com/anitaa1990/Wifi-Connect/blob/master/media/Screenshot_20180416-080954.png\" width=\"180\" style=\"max-width:100%;\"\u003e\u003c/a\u003e        \n\u003c/p\u003e\n\n\u003cimg src=\"https://img.shields.io/badge/API-14%2B-orange.svg?style=flat\" alt=\"API\" data-canonical-src=\"https://img.shields.io/badge/API-14%2B-orange.svg?style=flat\" style=\"max-width:100%;\"\u003e\n\n\n\u003ch2\u003eHow to integrate the library in your app?\u003c/h2\u003e\n\u003cb\u003eGradle Dependecy - Java\u003c/b\u003e\u003c/br\u003e\n\n```gradle\ndependencies {\n    implementation 'com.wifiscanner:wifiscanner:0.1.2'\n}\n```\n\n\u003cb\u003eMaven Dependecy - Java\u003c/b\u003e\u003c/br\u003e\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.wifiscanner\u003c/groupId\u003e\n  \u003cartifactId\u003ewifiscanner\u003c/artifactId\u003e\n  \u003cversion\u003e0.1.2\u003c/version\u003e\n  \u003ctype\u003epom\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\n\n\u003ch2\u003eUsage\u003c/h2\u003e\n\u003cb\u003eStep 1:\u003c/b \u003eDefine the AndroidManifest.xml class:\n\n```\u003cuses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\" /\u003e\n\u003cuses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\" /\u003e\n\u003cuses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\" /\u003e\n\u003cuses-permission android:name=\"android.permission.INTERNET\" /\u003e\n\u003cuses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" /\u003e\n```\n\nDeclare the following service:\n```\n\u003cservice android:enabled=\"true\" android:name=\"com.wifiscanner.server.ServerDataService\" /\u003e\n```\n\n\u003cb\u003eNote: Currently the app does not support runtime permissions.\u003c/b\u003e\n\n\n\u003c/br\u003e\u003cb\u003eStep 2:\u003c/b\u003e Define the wrapper class in the ```onCreate()``` method of the activity \n\n```\nWifiP2PService wifiP2PService = new WifiP2PServiceImpl.Builder()\n                .setSender(this)\n                .setWifiP2PConnectionCallback(this)\n                .build();\n        wifiP2PService.onCreate();\n```\nWe need to initialize the wrapper class and declare the activity as either the \u003cb\u003eSender\u003c/b\u003e or the \u003cb\u003eReceiver\u003c/b\u003e.\nFor instance, in order to declare the activity as a Sender class, we use ```.setSender(this)```.\nIn order to declare the activity as a Receiver class, we use ```.setReceiver(this)``` \n\nThe Receiver - will act as the server. It will fetch the list of available nearby devices and select a device to connect with. \nThe Sender - will act as the client. Once a connection request is made from the server, the sender will accept the connection and pass data to the Receiver \n\n\n\n\u003c/br\u003e\u003cb\u003eStep 3:\u003c/b\u003e Add the following method in the ```onResume``` method of the activity\n```\nwifiP2PService.onResume();\n```\nThis method will register the broadcast receiver that will listen for the changes in Wifi network.\n\n\n\n\u003c/br\u003e\u003cb\u003eStep 4:\u003c/b\u003e Add the following method in the ```onStop``` method of the activity\n```\nwifiP2PService.onStop();\n```\nThis method will unregister the broadcast receiver since the activity is no longer at the top of the activity.\n\n\n\u003c/br\u003e\u003cb\u003eStep 5:\u003c/b\u003e Implement the WifiP2PConnectionCallback interface in your activity\n```\npublic class MainActivity extends AppCompatActivity implements WifiP2PConnectionCallback {\n```\nFunctions in the WifiP2PConnectionCallback interface\n\n| Function Name | Usage  |\n| ------------- | -----:|\n| ```initiateDiscovery()``` | This callback method is called when the scan is first initiated |\n| ```onDiscoverySuccess()``` | This callback method is called the discovery is successful |\n| ```onDiscoveryFailure()``` | This callback method is called the discovery is not successful |\n| ```onPeerAvailable()``` | This callback method is called with a list of all peer available devices |\n| ```onPeerStatusChanged()``` | This status of the peers that are discovered is changing |\n| ```onPeerConnectionSuccess()``` | called when a connection to a nearby device is successful |\n| ```onPeerConnectionFailure()``` | called when a connection to a nearby device is not successful |\n| ```onPeerDisconnectionSuccess()``` | called when a disconnection to a nearby device is successful |\n| ```onPeerDisconnectionFailure()``` | called when a disconnection to a nearby device is not successful |\n| ```onDataTransferring()``` | called when data transfer has been initiated |\n| ```onDataTransferredSuccess()``` | called when data transfer has completed \u0026 is successful |\n| ```onDataTransferredFailure()``` | called when data transfer has completed \u0026 is not successful |\n| ```onDataReceiving()``` | Called when the receiver has started to receive the data from sender |\n| ```onDataReceivedSuccess(String message)``` | Called when the receiver has received the data successfully |\n| ```onDataReceivedFailure()``` | Called when the data transferred is completed but data is not received |\n\n\n\u003c/br\u003eMethods available in the Receiver class:\nMethod to connect to an available device:  - you need to pass the device that is to be connected\n```wifiP2PService.connectDevice(wifiP2pDevice);```\n\n\n\u003c/br\u003eMethod to start data transfer - you need to pass the message that needs to be shared to the client\n```wifiP2PService.startDataTransfer(\"Helllooo\");```\n\n\n\u003c/br\u003eAnd that's it folks!\u003c/br\u003e\u003c/br\u003e\n\n\u003ch2\u003eCreated and maintained by:\u003c/h2\u003e\n\u003cp\u003eAnitaa Murthy  murthyanitaa@gmail.com\u003c/p\u003e\n\u003cp\u003e\u003ca href=\"https://twitter.com/anitaa_1990\"\u003e \u003cimg src=\"https://github.com/anitaa1990/DeviceInfo-Sample/blob/master/media/twitter-icon.png\" alt=\"Twitter\" style=\"max-width:100%;\"\u003e \u003c/a\u003e\u003ca href=\"https://plus.google.com/104409749442569901352\"\u003e \u003cimg src=\"https://github.com/anitaa1990/DeviceInfo-Sample/blob/master/media/google-icon.png\" alt=\"Google Plus\" style=\"max-width:100%;\"\u003e \u003c/a\u003e\u003ca href=\"https://www.linkedin.com/in/anitaa-murthy-41531699\"\u003e \u003cimg src=\"https://github.com/anitaa1990/DeviceInfo-Sample/blob/master/media/linkedin-icon.png\" alt=\"Linkedin\" style=\"max-width:100%;\"\u003e \u003c/a\u003e\u003c/p\u003e\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanitaa1990%2Fwifi-connect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanitaa1990%2Fwifi-connect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanitaa1990%2Fwifi-connect/lists"}