• Stars
    star
    105
  • Rank 328,112 (Top 7 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A library project to connect two devices using Wifi-Direct

152px

Wifi-Connect

Android Arsenal

A simple wrapper module to connect two devices and share data using Wifi-Direct.

This 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.

Sample App

Get it on Google Play

Download the sample app on the Google Play Store and check out all the features

API

How to integrate the library in your app?

Gradle Dependecy - Java
dependencies {
    implementation 'com.wifiscanner:wifiscanner:0.1.2'
}

Maven Dependecy - Java

<dependency>
  <groupId>com.wifiscanner</groupId>
  <artifactId>wifiscanner</artifactId>
  <version>0.1.2</version>
  <type>pom</type>
</dependency>

Usage

Step 1:Define the AndroidManifest.xml class:
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Declare the following service:

<service android:enabled="true" android:name="com.wifiscanner.server.ServerDataService" />

Note: Currently the app does not support runtime permissions.


Step 2: Define the wrapper class in the onCreate() method of the activity

WifiP2PService wifiP2PService = new WifiP2PServiceImpl.Builder()
                .setSender(this)
                .setWifiP2PConnectionCallback(this)
                .build();
        wifiP2PService.onCreate();

We need to initialize the wrapper class and declare the activity as either the Sender or the Receiver. For instance, in order to declare the activity as a Sender class, we use .setSender(this). In order to declare the activity as a Receiver class, we use .setReceiver(this)

The Receiver - will act as the server. It will fetch the list of available nearby devices and select a device to connect with. The 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


Step 3: Add the following method in the onResume method of the activity

wifiP2PService.onResume();

This method will register the broadcast receiver that will listen for the changes in Wifi network.


Step 4: Add the following method in the onStop method of the activity

wifiP2PService.onStop();

This method will unregister the broadcast receiver since the activity is no longer at the top of the activity.


Step 5: Implement the WifiP2PConnectionCallback interface in your activity

public class MainActivity extends AppCompatActivity implements WifiP2PConnectionCallback {

Functions in the WifiP2PConnectionCallback interface

Function Name Usage
initiateDiscovery() This callback method is called when the scan is first initiated
onDiscoverySuccess() This callback method is called the discovery is successful
onDiscoveryFailure() This callback method is called the discovery is not successful
onPeerAvailable() This callback method is called with a list of all peer available devices
onPeerStatusChanged() This status of the peers that are discovered is changing
onPeerConnectionSuccess() called when a connection to a nearby device is successful
onPeerConnectionFailure() called when a connection to a nearby device is not successful
onPeerDisconnectionSuccess() called when a disconnection to a nearby device is successful
onPeerDisconnectionFailure() called when a disconnection to a nearby device is not successful
onDataTransferring() called when data transfer has been initiated
onDataTransferredSuccess() called when data transfer has completed & is successful
onDataTransferredFailure() called when data transfer has completed & is not successful
onDataReceiving() Called when the receiver has started to receive the data from sender
onDataReceivedSuccess(String message) Called when the receiver has received the data successfully
onDataReceivedFailure() Called when the data transferred is completed but data is not received


Methods available in the Receiver class: Method to connect to an available device: - you need to pass the device that is to be connected wifiP2PService.connectDevice(wifiP2pDevice);


Method to start data transfer - you need to pass the message that needs to be shared to the client wifiP2PService.startDataTransfer("Helllooo");


And that's it folks!

Created and maintained by:

Anitaa Murthy [email protected]

Twitter Google Plus Linkedin

More Repositories

1

Android-Cheat-sheet

Cheat Sheet for Android Interviews
Java
2,162
star
2

Biometric-Auth-Sample

Add Biometric Authentication to any Android app
Java
246
star
3

DeviceInfo-Sample

[Android Library] Get easy access to device information super fast, real quick
Kotlin
204
star
4

TrailersApp

A simple demo project for The Movie DB based on MVVM clean architecture.
Java
197
star
5

PagingLibrary-Sample

An open source app that is refactored to demo Paging Library from Android Jetpack
Java
170
star
6

Today-I-Learned

A collection of small things I learn day to day across a variety of languages and technologies
155
star
7

RoomDb-Sample

A simple notes app to demo Room + LiveData implementation in Android
Java
122
star
8

ConstraintLayout-Sample

A demo app to showcase constraint layout implementation in Android
Java
105
star
9

OnboardingSample

Beginners - A demo of an onboarding screen in iOS using Swift
Swift
97
star
10

Dagger2-Sample

A sample app to demo how to implement dagger in Android using Dagger Android Support library
Java
77
star
11

Github-Trending-Repos

An Android App that lists the most trending repositories from Github.
Java
60
star
12

RxAndroid-Sample

A list of concise write ups on the implementation of RxJava in Android
Java
36
star
13

Optimize

Android library for displaying data based on JSON configuration fetched from server. With this library, you can kiss goodbye to string.xml, dimen.xml, arrays.xml. Keep all your string/integer/array config in one file. The library will automatically fetch the data from the url you provide.
Java
35
star
14

CustomFontView

Custom View classes for TextView, EditText & Buttons - to set custom fonts
Java
27
star
15

Inshorts

A demo app news app for a hackathon - includes MVP architecture example
Java
23
star
16

RxNetworkEvent-Example

This is a sample app to demonstrate error handling using Retrofit2 and RxJava2
Java
22
star
17

AESEncryption

A demo of how to implement AES encryption in Android & iOS
Swift
21
star
18

Trailers

An open source app that is refactored to demo MVVM architecture
Java
20
star
19

otpview

A simple custom view class to enter otp
Java
19
star
20

GameOfThronesTrivia

An open source app that is refactored to demo ViewModel and LiveData
Java
17
star
21

DataBindingExample

A demo of how to implement Data Binding in Android app
Java
11
star
22

Jni-Sample

A simple project that demonstrates the use of jni to communicate between native and Java code in Android
Java
10
star
23

Ussd-app

A POC app for USSD implementation in Android
Java
6
star
24

RequestTask

Android library wrapper for HttpUrlConnection
Java
5
star
25

Github-Repo-Sample

A demo app that follows clean architecture which includes:
Kotlin
3
star
26

VDOPlayer

A simple video player app
Java
2
star