WifiDLite is my experimental, alpha-version, open-source Android library which tries to make it easier to do basic WiFi Direct tasks.

The idea is to encapsulate away some of the nuts and bolts of programming Wifi Direct on Android and offer a simpler API for Wifi Direct tasks.

For example, WifiDLite spares you the work of getting an instance of WifiP2pManager, initializing it to get a Channel object, and implementing a specialized BroadcastListener.

Instead you simply get and initialize the WifiDLite singleton in your app’s onCreate, and then dispose of it in onDestroy.

The most experimental part of the library is the worker thread which periodically “rediscovers” peers on the WiFi Direct network. The default interval (set in the DefaultConfiguration object) is 10 seconds. The idea is to discover repeatedly so that, as other Android devices become available to the WiFi P2P network, your client code becomes aware of them shortly afterwards.

Of course, in theory, this is totally unnecessary because the Android platform automatically updates the internal BroadcastReceiver implementation with a WIFI_P2P_PEERS_CHANGED_ACTION when these event occurs. But … I thought I’d try explicitly forcing discovery to see what happens. (This feature may be removed in the future.) Aside from this experimental background thread, everything, including the client programmer’s calls to WifiDLite methods, should happen on the UI thread.

The source is offered as an Android Studio project on GitHub, which includes both the WifiDLite library (aar) project, and source code for the demo app. The demo app is also available on Google Play.

The pre-built Android Archive (aar) file is now available on jCenter (thanks to Blundell), which makes it easy to use the library in Android Studio. For example, add this line to the dependencies block in your app’s build.gradle to download and include version 0.1.1 of the library in your Android Studio project:

compile(group: 'com.albertcbraun.wifidlite', name: 'wifidlite-lib', version: '0.1.1', ext: 'aar')

More code samples are found in the demo app and in the ReadMe on GitHub.