anitaa1990 / wifi-connect Goto Github PK
View Code? Open in Web Editor NEWA library project to connect two devices using Wifi-Direct
License: Apache License 2.0
A library project to connect two devices using Wifi-Direct
License: Apache License 2.0
My code keeps going to onPeerConnectionFailure() calback.
Here it is -
` private WifiP2PServiceImpl wifiP2PService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wifiP2PService = new WifiP2PServiceImpl.Builder()
.setSender(this)
.setWifiP2PConnectionCallback(this)
.build();
wifiP2PService.onCreate();
}
@Override
public void onInitiateDiscovery() {
Log.d("*****", "initiate discovery");
}
@Override
public void onDiscoverySuccess() {
Log.d("*****", "discovery success");
}
@Override
public void onDiscoveryFailure() {
Log.d("*****", "discovery failure");
}
@Override
public void onPeerAvailable(WifiP2pDeviceList wifiP2pDeviceList) {
Log.d("*****", "peer available");
ArrayList<WifiP2pDevice> devices = new ArrayList<>(wifiP2pDeviceList.getDeviceList());
for(int i=0; i<devices.size(); i++){
if(devices.get(i).deviceName.equals("Smart TV"))
wifiP2PService.connectDevice(devices.get(i));
}
}
@Override
public void onPeerStatusChanged(WifiP2pDevice wifiP2pDevice) {
Log.d("*****", "peer status change");
}
@Override
public void onPeerConnectionSuccess() {
wifiP2PService.startDataTransfer("Helllooo");
Log.d("*****", "peer connection success");
}
@Override
public void onPeerConnectionFailure() {
Log.d("*****", "peer connection failure");
}
@Override
public void onPeerDisconnectionSuccess() {
Log.d("*****", "peer disconnection success");
}
@Override
public void onPeerDisconnectionFailure() {
Log.d("*****", "peer disconnection failure");
}
@Override
public void onDataTransferring() {
Log.d("*****", "data transferring");
}
@Override
public void onDataTransferredSuccess() {
Log.d("*****", "data transferring success");
}
@Override
public void onDataTransferredFailure() {
Log.d("*****", "data transferring failure");
}
@Override
public void onDataReceiving() {
Log.d("*****", "data receiving");
}
@Override
public void onDataReceivedSuccess(String s) {
Log.d("*****", "data receiving success");
}
@Override
public void onDataReceivedFailure() {
Log.d("*****", "data receiving failure");
}
@Override
protected void onResume() {
super.onResume();
wifiP2PService.onResume();
}
@Override
protected void onStop() {
super.onStop();
wifiP2PService.onStop();
}`
Here is my receiver app code -
` private WifiP2PServiceImpl wifiP2PService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wifiP2PService = new WifiP2PServiceImpl.Builder()
.setReceiver(this)
.setWifiP2PConnectionCallback(this)
.build();
wifiP2PService.onCreate();
}
@Override
public void onInitiateDiscovery() {
Log.d("*****", "initiate discovery");
}
@Override
public void onDiscoverySuccess() {
Log.d("*****", "discovery success");
}
@Override
public void onDiscoveryFailure() {
Log.d("*****", "discovery failure");
}
@Override
public void onPeerAvailable(WifiP2pDeviceList wifiP2pDeviceList) {
Log.d("*****", "peer available");
}
@Override
public void onPeerStatusChanged(WifiP2pDevice wifiP2pDevice) {
Log.d("*****", "peer status change");
}
@Override
public void onPeerConnectionSuccess() {
Log.d("*****", "peer connection success");
}
@Override
public void onPeerConnectionFailure() {
Log.d("*****", "peer connection failure");
}
@Override
public void onPeerDisconnectionSuccess() {
Log.d("*****", "peer disconnection success");
}
@Override
public void onPeerDisconnectionFailure() {
Log.d("*****", "peer disconnection failure");
}
@Override
public void onDataTransferring() {
Log.d("*****", "data transferring");
}
@Override
public void onDataTransferredSuccess() {
Log.d("*****", "data transferring success");
}
@Override
public void onDataTransferredFailure() {
Log.d("*****", "data transferring failure");
}
@Override
public void onDataReceiving() {
Log.d("*****", "data receiving");
}
@Override
public void onDataReceivedSuccess(String s) {
Toast.makeText(MainActivity.this, s, Toast.LENGTH_SHORT).show();
Log.d("*****", "data receiving success");
}
@Override
public void onDataReceivedFailure() {
Log.d("*****", "data receiving failure");
}
@Override
protected void onResume() {
super.onResume();
wifiP2PService.onResume();
}
@Override
protected void onStop() {
super.onStop();
wifiP2PService.onStop();
}
`
Can you help me with the reason behind it?
Hi,
I am using two Google Pixel 2 phones to connect Wifi-direct to each other using your Wifi-Connect. If I manually check in Settings -> Network & Internet -> Wifi -> Wifi Preferences -> Advanced -> WiFi-Direct, I can discover peers and connect them.
Using your repo in my project, I followed the instructions and have all the required permissions granted. However, I cannot discover nearby peers and always see WifiP2pDeviceList returned from onPeerAvailable with the size of 0. FYI, the interfaces - onInitiateDiscovery() and onDiscoverySuccess() - are also called back.
can we use for multiple device connection like xender ?
Hello there, I'd like to contribute to your awesome project by writing a Frequent Asked Questions for users self-service. Would love to hear from you, thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.