wifidirectplugin 1.3.4 → 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;
|
|
@@ -531,5 +537,54 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
531
537
|
});
|
|
532
538
|
}
|
|
533
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
|
+
}
|
|
534
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
|
+
}
|
|
535
590
|
}
|