version 0.1.3
This commit is contained in:
@@ -2,14 +2,14 @@ group 'com.xenikii.nearby_service'
|
||||
version '1.0-SNAPSHOT'
|
||||
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.7.10'
|
||||
ext.kotlin_version = '2.1.20'
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.3.1'
|
||||
classpath 'com.android.tools.build:gradle:8.1.0'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,8 @@ apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdk 33
|
||||
compileSdk 35
|
||||
namespace 'com.xenikii.nearby_service'
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.xenikii.nearby_service">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- required to use Wi-fi Direct on Android 13+ -->
|
||||
<uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />
|
||||
<!-- required to use Wi-fi Direct -->
|
||||
|
||||
+10
-3
@@ -14,6 +14,7 @@ import android.os.Build
|
||||
/**
|
||||
* Receiver of [WifiP2pManager] changes.
|
||||
*/
|
||||
@Suppress("DEPRECATION")
|
||||
class NearbyServiceBroadcastReceiver(
|
||||
private val wifiManager: WifiP2pManager,
|
||||
private val wifiChannel: Channel,
|
||||
@@ -34,7 +35,7 @@ class NearbyServiceBroadcastReceiver(
|
||||
}
|
||||
|
||||
WifiP2pManager.WIFI_P2P_PEERS_CHANGED_ACTION -> {
|
||||
writeDevices()
|
||||
writeDevices { intent.getParcelableExtra(WifiP2pManager.EXTRA_P2P_DEVICE_LIST) }
|
||||
}
|
||||
|
||||
WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION -> {
|
||||
@@ -76,13 +77,19 @@ class NearbyServiceBroadcastReceiver(
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeDevices() {
|
||||
private fun writeDevices(deviceListSupplier: (() -> WifiP2pDeviceList?)? = null) {
|
||||
try {
|
||||
wifiManager.requestPeers(
|
||||
wifiChannel
|
||||
) { newPeers: WifiP2pDeviceList ->
|
||||
) { data: WifiP2pDeviceList ->
|
||||
val list: MutableList<String> = mutableListOf()
|
||||
|
||||
val newPeers =
|
||||
if (data.deviceList.isEmpty() && deviceListSupplier != null) {
|
||||
deviceListSupplier() ?: data
|
||||
} else {
|
||||
data
|
||||
}
|
||||
if (newPeers.deviceList.isEmpty() && connectedDevice != null) {
|
||||
connectedDevice = null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user