wifidirectplugin 1.1.1 → 1.1.2
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.
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
package com.ht.plugins.wifidirect;
|
|
2
2
|
|
|
3
|
+
import android.content.BroadcastReceiver;
|
|
3
4
|
import android.content.Context;
|
|
5
|
+
import android.content.Intent;
|
|
6
|
+
import android.content.IntentFilter;
|
|
4
7
|
import android.net.wifi.WpsInfo;
|
|
5
8
|
import android.net.wifi.p2p.*;
|
|
6
9
|
import android.net.NetworkInfo;
|
|
@@ -24,13 +27,44 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
24
27
|
private List<WifiP2pDevice> peerWifiDirDevices = new ArrayList<>();
|
|
25
28
|
private static final String TAG = "WifiDirectPlugin";
|
|
26
29
|
|
|
30
|
+
private final BroadcastReceiver wifiP2pReceiver = new BroadcastReceiver() {
|
|
31
|
+
@Override
|
|
32
|
+
public void onReceive(Context context, Intent intent) {
|
|
33
|
+
String action = intent.getAction();
|
|
34
|
+
|
|
35
|
+
if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
|
|
36
|
+
NetworkInfo networkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
|
|
37
|
+
if (networkInfo != null && networkInfo.isConnected()) {
|
|
38
|
+
Log.d(TAG, "Wi-Fi Direct connected");
|
|
39
|
+
|
|
40
|
+
// 필요한 경우 연결된 상태를 Flutter/Ionic에 전달하는 코드를 여기서 실행
|
|
41
|
+
// 예: call JavaScript 이벤트 전송 또는 콜백 호출
|
|
42
|
+
} else {
|
|
43
|
+
Log.d(TAG, "Wi-Fi Direct disconnected");
|
|
44
|
+
// 연결 해제 상태 처리
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
27
50
|
@Override
|
|
28
51
|
public void load() {
|
|
29
52
|
context = getContext();
|
|
30
53
|
manager = (WifiP2pManager) context.getSystemService(Context.WIFI_P2P_SERVICE);
|
|
31
54
|
channel = manager.initialize(context, context.getMainLooper(), null);
|
|
55
|
+
|
|
56
|
+
IntentFilter intentFilter = new IntentFilter();
|
|
57
|
+
intentFilter.addAction(WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION);
|
|
58
|
+
context.registerReceiver(wifiP2pReceiver, intentFilter);
|
|
32
59
|
}
|
|
33
60
|
|
|
61
|
+
public void unload() {
|
|
62
|
+
try {
|
|
63
|
+
context.unregisterReceiver(wifiP2pReceiver);
|
|
64
|
+
} catch (IllegalArgumentException e) {
|
|
65
|
+
Log.w(TAG, "Receiver not registerd or already registered");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
34
68
|
@PluginMethod
|
|
35
69
|
public void scanWifiPeers(PluginCall call) {
|
|
36
70
|
if(manager == null || channel == null) {
|
|
@@ -100,6 +134,7 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
100
134
|
config.wps.setup = WpsInfo.KEYPAD;
|
|
101
135
|
config.wps.pin = pin;
|
|
102
136
|
} else {
|
|
137
|
+
Log.d(TAG, "Pin: " + pin);
|
|
103
138
|
Log.w(TAG, "Invalid Pin");
|
|
104
139
|
}
|
|
105
140
|
}
|
|
@@ -109,17 +144,20 @@ public class WifiDirectPlugin extends Plugin {
|
|
|
109
144
|
public void onSuccess() {
|
|
110
145
|
Log.d(TAG, "connect onSuccess Called");
|
|
111
146
|
call.resolve();
|
|
147
|
+
unload();
|
|
112
148
|
}
|
|
113
149
|
|
|
114
150
|
@Override
|
|
115
151
|
public void onFailure(int reason) {
|
|
116
152
|
Log.e(TAG, "connect onFailure Called");
|
|
117
153
|
call.reject("Connection failed: " + reason);
|
|
154
|
+
unload();
|
|
118
155
|
}
|
|
119
156
|
});
|
|
120
157
|
} catch (Exception e) {
|
|
121
158
|
Log.e(TAG, "connect exception", e);
|
|
122
159
|
call.reject("Connection exception: " + e.getMessage());
|
|
160
|
+
unload();
|
|
123
161
|
}
|
|
124
162
|
|
|
125
163
|
}
|