@capgo/capacitor-ibeacon 8.1.29 → 8.1.31
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.
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"
|
|
26
26
|
tools:targetApi="upside_down_cake" />
|
|
27
27
|
|
|
28
|
+
<!-- Required to show foreground service notification on Android 13+ -->
|
|
29
|
+
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
|
30
|
+
|
|
28
31
|
<!-- Required for receiving boot completed to restart beacon monitoring -->
|
|
29
32
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
|
30
33
|
|
|
@@ -30,6 +30,7 @@ import org.altbeacon.beacon.Identifier;
|
|
|
30
30
|
import org.altbeacon.beacon.MonitorNotifier;
|
|
31
31
|
import org.altbeacon.beacon.RangeNotifier;
|
|
32
32
|
import org.altbeacon.beacon.Region;
|
|
33
|
+
import org.altbeacon.beacon.Settings;
|
|
33
34
|
|
|
34
35
|
@CapacitorPlugin(
|
|
35
36
|
name = "CapacitorIbeacon",
|
|
@@ -43,7 +44,7 @@ import org.altbeacon.beacon.Region;
|
|
|
43
44
|
)
|
|
44
45
|
public class CapacitorIbeaconPlugin extends Plugin implements BeaconConsumer {
|
|
45
46
|
|
|
46
|
-
private final String pluginVersion = "8.1.
|
|
47
|
+
private final String pluginVersion = "8.1.31";
|
|
47
48
|
private static final String FOREGROUND_CHANNEL_ID = "beacon_service_channel";
|
|
48
49
|
private static final int FOREGROUND_NOTIFICATION_ID = 456;
|
|
49
50
|
private BeaconManager beaconManager;
|
|
@@ -66,6 +67,9 @@ public class CapacitorIbeaconPlugin extends Plugin implements BeaconConsumer {
|
|
|
66
67
|
// This is critical for beacon detection when app is in background
|
|
67
68
|
beaconManager.setEnableScheduledScanJobs(false);
|
|
68
69
|
|
|
70
|
+
// Prevent Android from downgrading long-running BLE scans to opportunistic mode
|
|
71
|
+
beaconManager.adjustSettings(new Settings.Builder().setLongScanForcingEnabled(true).build());
|
|
72
|
+
|
|
69
73
|
// Configure background scan periods (in milliseconds)
|
|
70
74
|
// Default background scan: 10 seconds scan, 5 minutes between scans
|
|
71
75
|
// We use more aggressive settings for better detection
|
|
@@ -366,6 +370,12 @@ public class CapacitorIbeaconPlugin extends Plugin implements BeaconConsumer {
|
|
|
366
370
|
return;
|
|
367
371
|
}
|
|
368
372
|
|
|
373
|
+
if (!hasBluetoothPermissions()) {
|
|
374
|
+
ret.put("status", "denied");
|
|
375
|
+
call.resolve(ret);
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
|
|
369
379
|
// On Android 10+, check for background location
|
|
370
380
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
371
381
|
boolean hasBackgroundLocation =
|
|
@@ -557,12 +567,8 @@ public class CapacitorIbeaconPlugin extends Plugin implements BeaconConsumer {
|
|
|
557
567
|
@PluginMethod
|
|
558
568
|
public void enableBackgroundMode(PluginCall call) {
|
|
559
569
|
Boolean enabled = call.getBoolean("enabled", true);
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
call.resolve();
|
|
563
|
-
} catch (Exception e) {
|
|
564
|
-
call.reject("Failed to enable background mode", e);
|
|
565
|
-
}
|
|
570
|
+
setBackgroundModeEnabled(enabled != null && enabled);
|
|
571
|
+
call.resolve();
|
|
566
572
|
}
|
|
567
573
|
|
|
568
574
|
@PluginMethod
|
|
@@ -592,6 +598,16 @@ public class CapacitorIbeaconPlugin extends Plugin implements BeaconConsumer {
|
|
|
592
598
|
|
|
593
599
|
// Helper methods
|
|
594
600
|
|
|
601
|
+
private boolean hasBluetoothPermissions() {
|
|
602
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
603
|
+
return (
|
|
604
|
+
ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED &&
|
|
605
|
+
ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
|
|
595
611
|
private Region createRegion(String identifier, String uuid, Integer major, Integer minor) {
|
|
596
612
|
List<Identifier> identifiers = new ArrayList<>();
|
|
597
613
|
identifiers.add(Identifier.parse(uuid));
|
|
@@ -708,33 +724,39 @@ public class CapacitorIbeaconPlugin extends Plugin implements BeaconConsumer {
|
|
|
708
724
|
}
|
|
709
725
|
}
|
|
710
726
|
|
|
711
|
-
private
|
|
727
|
+
private boolean enableForegroundServiceIfNeeded() {
|
|
712
728
|
if (foregroundServiceEnabled || Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
713
|
-
return;
|
|
729
|
+
return true;
|
|
714
730
|
}
|
|
715
731
|
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
732
|
+
try {
|
|
733
|
+
// Create notification channel for foreground service
|
|
734
|
+
android.app.NotificationChannel channel = new android.app.NotificationChannel(
|
|
735
|
+
FOREGROUND_CHANNEL_ID,
|
|
736
|
+
"Beacon Service",
|
|
737
|
+
android.app.NotificationManager.IMPORTANCE_LOW
|
|
738
|
+
);
|
|
739
|
+
channel.setDescription("Background beacon monitoring service");
|
|
723
740
|
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
741
|
+
android.app.NotificationManager notificationManager = getContext().getSystemService(android.app.NotificationManager.class);
|
|
742
|
+
if (notificationManager != null) {
|
|
743
|
+
notificationManager.createNotificationChannel(channel);
|
|
744
|
+
}
|
|
728
745
|
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
746
|
+
// Build notification for foreground service
|
|
747
|
+
android.app.Notification.Builder builder = new android.app.Notification.Builder(getContext(), FOREGROUND_CHANNEL_ID);
|
|
748
|
+
builder.setSmallIcon(android.R.drawable.ic_dialog_info);
|
|
749
|
+
builder.setContentTitle("Beacon Monitoring");
|
|
750
|
+
builder.setContentText("Scanning for nearby beacons");
|
|
734
751
|
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
752
|
+
// Enable foreground service mode in AltBeacon
|
|
753
|
+
beaconManager.enableForegroundServiceScanning(builder.build(), FOREGROUND_NOTIFICATION_ID);
|
|
754
|
+
foregroundServiceEnabled = true;
|
|
755
|
+
return true;
|
|
756
|
+
} catch (Exception e) {
|
|
757
|
+
android.util.Log.w("CapacitorIbeacon", "Foreground service scanning unavailable, continuing without it", e);
|
|
758
|
+
return false;
|
|
759
|
+
}
|
|
738
760
|
}
|
|
739
761
|
|
|
740
762
|
private void disableForegroundServiceIfNeeded() {
|
|
@@ -742,7 +764,12 @@ public class CapacitorIbeaconPlugin extends Plugin implements BeaconConsumer {
|
|
|
742
764
|
return;
|
|
743
765
|
}
|
|
744
766
|
|
|
745
|
-
|
|
746
|
-
|
|
767
|
+
try {
|
|
768
|
+
beaconManager.disableForegroundServiceScanning();
|
|
769
|
+
} catch (Exception e) {
|
|
770
|
+
android.util.Log.w("CapacitorIbeacon", "Failed to disable foreground service scanning", e);
|
|
771
|
+
} finally {
|
|
772
|
+
foregroundServiceEnabled = false;
|
|
773
|
+
}
|
|
747
774
|
}
|
|
748
775
|
}
|
|
@@ -4,7 +4,7 @@ import CoreLocation
|
|
|
4
4
|
|
|
5
5
|
@objc(CapacitorIbeaconPlugin)
|
|
6
6
|
public class CapacitorIbeaconPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
7
|
-
private let pluginVersion: String = "8.1.
|
|
7
|
+
private let pluginVersion: String = "8.1.31"
|
|
8
8
|
public let identifier = "CapacitorIbeaconPlugin"
|
|
9
9
|
public let jsName = "CapacitorIbeacon"
|
|
10
10
|
public let pluginMethods: [CAPPluginMethod] = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-ibeacon",
|
|
3
|
-
"version": "8.1.
|
|
3
|
+
"version": "8.1.31",
|
|
4
4
|
"description": "iBeacon plugin for Capacitor - proximity detection and beacon region monitoring",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -55,8 +55,7 @@
|
|
|
55
55
|
"prepublishOnly": "bun run build",
|
|
56
56
|
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs",
|
|
57
57
|
"example:install": "cd example-app && bun install --frozen-lockfile",
|
|
58
|
-
"example:build": "bun run build && cd example-app && bun install --frozen-lockfile && bun run build"
|
|
59
|
-
"example:capgo:deploy": "bun run example:build && bun scripts/deploy-example-capgo.mjs"
|
|
58
|
+
"example:build": "bun run build && cd example-app && bun install --frozen-lockfile && bun run build"
|
|
60
59
|
},
|
|
61
60
|
"devDependencies": {
|
|
62
61
|
"@capacitor/android": "^8.0.0",
|