wifidirectplugin 1.3.3 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,15 +8,21 @@ import android.net.ConnectivityManager;
|
|
|
8
8
|
import android.net.Network;
|
|
9
9
|
import android.net.NetworkCapabilities;
|
|
10
10
|
import android.net.NetworkRequest;
|
|
11
|
+
import android.bluetooth.BluetoothAdapter;
|
|
12
|
+
import android.net.wifi.WifiManager;
|
|
11
13
|
import android.net.wifi.WpsInfo;
|
|
12
14
|
import android.net.wifi.p2p.*;
|
|
13
15
|
import android.net.NetworkInfo;
|
|
14
16
|
import android.os.Build;
|
|
15
17
|
import android.os.Handler;
|
|
16
18
|
import android.os.Looper;
|
|
19
|
+
import android.provider.Settings;
|
|
17
20
|
import android.util.Log;
|
|
18
21
|
|
|
22
|
+
import androidx.activity.result.ActivityResult;
|
|
23
|
+
|
|
19
24
|
import com.getcapacitor.*;
|
|
25
|
+
import com.getcapacitor.annotation.ActivityCallback;
|
|
20
26
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
21
27
|
|
|
22
28
|
import org.json.JSONArray;
|
|
@@ -46,9 +52,6 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
46
52
|
private ConnectivityManager connectivityManager;
|
|
47
53
|
private ConnectivityManager.NetworkCallback p2pNetworkCallback = null;
|
|
48
54
|
private Network boundP2pNetwork = null;
|
|
49
|
-
// NetworkCapabilities.TRANSPORT_WIFI_P2P는 API 31에서 public으로 추가됐다.
|
|
50
|
-
// 그 이전 SDK로 컴파일해도 동작하도록 안정적인 정수 값 5를 직접 사용한다.
|
|
51
|
-
private static final int TRANSPORT_WIFI_P2P = 5;
|
|
52
55
|
|
|
53
56
|
private final BroadcastReceiver wifiP2pReceiver = new BroadcastReceiver() {
|
|
54
57
|
@Override
|
|
@@ -335,7 +338,7 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
335
338
|
if (p2pNetworkCallback != null) return;
|
|
336
339
|
|
|
337
340
|
NetworkRequest req = new NetworkRequest.Builder()
|
|
338
|
-
.addTransportType(
|
|
341
|
+
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI_AWARE)
|
|
339
342
|
// P2P는 인터넷 capability가 없으므로 매칭을 위해 제거
|
|
340
343
|
.removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
|
341
344
|
.build();
|
|
@@ -426,7 +429,7 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
426
429
|
Network[] networks = connectivityManager.getAllNetworks();
|
|
427
430
|
for (Network n : networks) {
|
|
428
431
|
NetworkCapabilities caps = connectivityManager.getNetworkCapabilities(n);
|
|
429
|
-
if (caps != null && caps.hasTransport(
|
|
432
|
+
if (caps != null && caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI_AWARE)) {
|
|
430
433
|
try {
|
|
431
434
|
connectivityManager.bindProcessToNetwork(n);
|
|
432
435
|
boundP2pNetwork = n;
|
|
@@ -534,5 +537,54 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
534
537
|
});
|
|
535
538
|
}
|
|
536
539
|
|
|
540
|
+
// ── Wi-Fi / Bluetooth 활성화 보장 ────────────────────────────────────────
|
|
541
|
+
// 페이지 진입 시 사용자 기기의 Wi-Fi / Bluetooth 가 꺼져있으면
|
|
542
|
+
// 1) Wi-Fi 패널 → 2) Bluetooth enable intent 를 순서대로 띄우고,
|
|
543
|
+
// 최종 상태(둘 다의 enable 여부)를 한 번에 resolve 한다.
|
|
544
|
+
// Android 10+ 에서는 앱이 직접 Wi-Fi 를 켤 수 없어 시스템 패널을 통한 사용자 동의 필요.
|
|
545
|
+
@PluginMethod
|
|
546
|
+
public void ensureWifiAndBluetooth(PluginCall call) {
|
|
547
|
+
WifiManager wifiManager = (WifiManager) context
|
|
548
|
+
.getApplicationContext()
|
|
549
|
+
.getSystemService(Context.WIFI_SERVICE);
|
|
550
|
+
if (wifiManager != null && !wifiManager.isWifiEnabled()) {
|
|
551
|
+
Intent panelIntent = new Intent(Settings.Panel.ACTION_WIFI);
|
|
552
|
+
startActivityForResult(call, panelIntent, "wifiPanelResult");
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
ensureBluetoothStep(call);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
@ActivityCallback
|
|
559
|
+
private void wifiPanelResult(PluginCall call, ActivityResult result) {
|
|
560
|
+
if (call == null) return;
|
|
561
|
+
ensureBluetoothStep(call);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
private void ensureBluetoothStep(PluginCall call) {
|
|
565
|
+
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
566
|
+
if (btAdapter != null && !btAdapter.isEnabled()) {
|
|
567
|
+
Intent btIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
|
|
568
|
+
startActivityForResult(call, btIntent, "bluetoothEnableResult");
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
resolveStatus(call);
|
|
572
|
+
}
|
|
537
573
|
|
|
574
|
+
@ActivityCallback
|
|
575
|
+
private void bluetoothEnableResult(PluginCall call, ActivityResult result) {
|
|
576
|
+
if (call == null) return;
|
|
577
|
+
resolveStatus(call);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
private void resolveStatus(PluginCall call) {
|
|
581
|
+
WifiManager wifiManager = (WifiManager) context
|
|
582
|
+
.getApplicationContext()
|
|
583
|
+
.getSystemService(Context.WIFI_SERVICE);
|
|
584
|
+
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
|
|
585
|
+
JSObject ret = new JSObject();
|
|
586
|
+
ret.put("wifiEnabled", wifiManager != null && wifiManager.isWifiEnabled());
|
|
587
|
+
ret.put("bluetoothEnabled", btAdapter != null && btAdapter.isEnabled());
|
|
588
|
+
call.resolve(ret);
|
|
589
|
+
}
|
|
538
590
|
}
|