I Create a Simple APP in Kotlin, when 1 device Click a button, Button goes to Create a Group of WiFi Direct, Its means WiFi Direct Hotspot and we can see it in WiFi list of any Device like below Code (BUT DEVICE CONNECTED TO OUR WIFI DIRECT GROUP NOT HAVE INTERNET CONNECTION):
manager = applicationContext.getSystemService(WIFI_P2P_SERVICE) as WifiP2pManager
channel = manager.initialize(this, mainLooper, null)
receiver = WiFiDirectReceiver(manager, channel, this)
intentFilter = IntentFilter().apply {
addAction(WIFI_P2P_STATE_CHANGED_ACTION)
addAction(WIFI_P2P_PEERS_CHANGED_ACTION)
addAction(WIFI_P2P_CONNECTION_CHANGED_ACTION)
addAction(WIFI_P2P_THIS_DEVICE_CHANGED_ACTION)
}
if (!isWifiP2pEnabled) {
Log.e("P2P ACTIVITY", "error: cannot start wf hotspot. WifiP2p is not enabled\n")
return
}
val ssid = "DIRECT-gg"
val password = "123456789"
var band = WifiP2pConfig.GROUP_OWNER_BAND_AUTO
val config = WifiP2pConfig.Builder()
.setNetworkName(ssid)
.setPassphrase(password)
.enablePersistentMode(false)
.setGroupOperatingBand(band)
.build()
manager.createGroup(channel, config, object : ActionListener {
override fun onSuccess() {
isHotspotEnabled = true
}
override fun onFailure(i: Int) {
Log.e("P2P ACTIVITY", "wf hotspot failed to start. reason: $i\n")
}
})
But I have a Problem, when other Device Connected to this (WiFi Direct Hotspot), they cant Search in Internet, I mean their Not Have Internet Connection, I dont know WHY, tell me what should I Do or Use or Code?
I set All Permission its needs and Broadcast but still cant get Internet Connection to Who Devices Join our WiFi Direct Hotspot Group
I expect that when I Click the Button and the WiFi Direct Group is Created, Everyone who Connects to it will also have Access to the Internet