[WIP] continued to implement a base for WiFi-Direct
This commit is contained in:
parent
08956df9c8
commit
449bb6f5d3
1 changed files with 29 additions and 11 deletions
|
@ -4,6 +4,8 @@ import android.content.Context
|
||||||
import android.net.wifi.p2p.WifiP2pConfig
|
import android.net.wifi.p2p.WifiP2pConfig
|
||||||
import android.net.wifi.p2p.WifiP2pManager
|
import android.net.wifi.p2p.WifiP2pManager
|
||||||
import android.net.wifi.p2p.WifiP2pManager.ActionListener
|
import android.net.wifi.p2p.WifiP2pManager.ActionListener
|
||||||
|
import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION
|
||||||
|
import android.net.wifi.p2p.WifiP2pManager.WIFI_P2P_STATE_ENABLED
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -40,35 +42,47 @@ class MainActivity : ComponentActivity() {
|
||||||
this.registerReceiver(MyBroadcastReceiver(this), intentFilter)
|
this.registerReceiver(MyBroadcastReceiver(this), intentFilter)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
// get the WiFi direct manager
|
// get the WiFi direct manager
|
||||||
val manager: WifiP2pManager? = this.getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager?
|
val manager: WifiP2pManager? = this.getSystemService(Context.WIFI_P2P_SERVICE) as WifiP2pManager?
|
||||||
if (manager == null) {
|
if (manager == null) {
|
||||||
Log.e("wifi-p2p", "cannot get the manager")
|
Log.e("wifi-p2p", "cannot get the manager")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Log.d("wifi-p2p", "manager: $manager")
|
||||||
|
|
||||||
val channel = manager.initialize(this, this.mainLooper, null)
|
val channel = manager.initialize(this, this.mainLooper, null)
|
||||||
|
Log.d("wifi-p2p", "channel: $channel")
|
||||||
|
|
||||||
|
/*
|
||||||
// get the list of peers in the group
|
// get the list of peers in the group
|
||||||
manager.requestPeers(channel) { devices ->
|
manager.discoverPeers(channel, object : ActionListener {
|
||||||
devices.deviceList.forEach { device ->
|
|
||||||
Log.d("wifi-p2p", "peer found : [${device.deviceAddress}] ${device.deviceName}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
manager.createGroup(channel, object : ActionListener {
|
|
||||||
override fun onSuccess() {
|
override fun onSuccess() {
|
||||||
Log.d("wifi-p2p", "Group created")
|
Log.d("wifi-p2p", "Peers discovery started")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(reason: Int) {
|
override fun onFailure(reason: Int) {
|
||||||
Log.e("wifi-p2p", "Error when creating group : $reason")
|
Log.e("wifi-p2p", "Error when starting peers discovery : $reason")
|
||||||
|
// NOTE: might fail if the "Location" permission is not granted
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
|
|
||||||
return
|
/*
|
||||||
|
manager.requestPeers(channel) { devices ->
|
||||||
|
// NOTE: might be empty if the "Location" permission is not granted
|
||||||
|
|
||||||
|
Log.d("wifi-p2p", "Peers found : ${devices.deviceList.size}")
|
||||||
|
devices.deviceList.forEach { device ->
|
||||||
|
Log.d(
|
||||||
|
"wifi-p2p",
|
||||||
|
"peer found : [${device.deviceAddress}] ${device.deviceName}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
manager.requestGroupInfo(channel) { group ->
|
manager.requestGroupInfo(channel) { group ->
|
||||||
val config = WifiP2pConfig().apply {
|
val config = WifiP2pConfig().apply {
|
||||||
this.deviceAddress = group.owner.deviceAddress
|
this.deviceAddress = group.owner.deviceAddress
|
||||||
|
@ -122,8 +136,11 @@ class MainActivity : ComponentActivity() {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
Log.d("socket", "Test")
|
Log.d("socket", "Test")
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
Thread {
|
Thread {
|
||||||
try {
|
try {
|
||||||
Log.d("socket", "Starting server")
|
Log.d("socket", "Starting server")
|
||||||
|
@ -150,6 +167,7 @@ class MainActivity : ComponentActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue