wifidirectplugin 1.3.5 → 1.3.7

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,5 +1,6 @@
1
1
  package com.ht.plugins.wifidirect;
2
2
 
3
+ import android.Manifest;
3
4
  import android.content.BroadcastReceiver;
4
5
  import android.content.Context;
5
6
  import android.content.Intent;
@@ -18,12 +19,15 @@ import android.os.Handler;
18
19
  import android.os.Looper;
19
20
  import android.provider.Settings;
20
21
  import android.util.Log;
22
+ import android.widget.Toast;
21
23
 
22
24
  import androidx.activity.result.ActivityResult;
23
25
 
24
26
  import com.getcapacitor.*;
25
27
  import com.getcapacitor.annotation.ActivityCallback;
26
28
  import com.getcapacitor.annotation.CapacitorPlugin;
29
+ import com.getcapacitor.annotation.Permission;
30
+ import com.getcapacitor.annotation.PermissionCallback;
27
31
 
28
32
  import org.json.JSONArray;
29
33
  import org.json.JSONException;
@@ -31,7 +35,12 @@ import org.json.JSONObject;
31
35
 
32
36
  import java.util.*;
33
37
 
34
- @CapacitorPlugin(name = "WifiDirect")
38
+ @CapacitorPlugin(
39
+ name = "WifiDirect",
40
+ permissions = {
41
+ @Permission(alias = "bluetooth", strings = { Manifest.permission.BLUETOOTH_CONNECT })
42
+ }
43
+ )
35
44
  public class WifiDirectPlugin extends Plugin {
36
45
  private WifiP2pManager manager;
37
46
  private WifiP2pManager.Channel channel;
@@ -53,6 +62,10 @@ public class WifiDirectPlugin extends Plugin {
53
62
  private ConnectivityManager.NetworkCallback p2pNetworkCallback = null;
54
63
  private Network boundP2pNetwork = null;
55
64
 
65
+ private void showToast(String message) {
66
+ Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
67
+ }
68
+
56
69
  private final BroadcastReceiver wifiP2pReceiver = new BroadcastReceiver() {
57
70
  @Override
58
71
  public void onReceive(Context context, Intent intent) {
@@ -548,6 +561,7 @@ public class WifiDirectPlugin extends Plugin {
548
561
  .getApplicationContext()
549
562
  .getSystemService(Context.WIFI_SERVICE);
550
563
  if (wifiManager != null && !wifiManager.isWifiEnabled()) {
564
+ showToast("Turn On the Wifi.");
551
565
  Intent panelIntent = new Intent(Settings.Panel.ACTION_WIFI);
552
566
  startActivityForResult(call, panelIntent, "wifiPanelResult");
553
567
  return;
@@ -564,6 +578,14 @@ public class WifiDirectPlugin extends Plugin {
564
578
  private void ensureBluetoothStep(PluginCall call) {
565
579
  BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
566
580
  if (btAdapter != null && !btAdapter.isEnabled()) {
581
+ // Android 12+(API 31)에서는 ACTION_REQUEST_ENABLE 인텐트를 띄우려면
582
+ // BLUETOOTH_CONNECT 런타임 권한이 필요하다. 미승인 상태로 띄우면 SecurityException.
583
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
584
+ && getPermissionState("bluetooth") != PermissionState.GRANTED) {
585
+ requestPermissionForAlias("bluetooth", call, "bluetoothPermCallback");
586
+ return;
587
+ }
588
+ showToast("Turn On the Bluetooth.");
567
589
  Intent btIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
568
590
  startActivityForResult(call, btIntent, "bluetoothEnableResult");
569
591
  return;
@@ -571,6 +593,17 @@ public class WifiDirectPlugin extends Plugin {
571
593
  resolveStatus(call);
572
594
  }
573
595
 
596
+ @PermissionCallback
597
+ private void bluetoothPermCallback(PluginCall call) {
598
+ if (getPermissionState("bluetooth") == PermissionState.GRANTED) {
599
+ // 권한 승인됨 → 다시 시도하면 이번엔 enable 인텐트를 띄울 수 있다.
600
+ ensureBluetoothStep(call);
601
+ } else {
602
+ // 권한 거부 시 크래시 대신 현재 상태만 반환한다.
603
+ resolveStatus(call);
604
+ }
605
+ }
606
+
574
607
  @ActivityCallback
575
608
  private void bluetoothEnableResult(PluginCall call, ActivityResult result) {
576
609
  if (call == null) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wifidirectplugin",
3
- "version": "1.3.5",
3
+ "version": "1.3.7",
4
4
  "description": "HT-Installer Wifi Direct Plugin",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",