wifidirectplugin 1.3.5 → 1.3.6

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