Comments (3)
The syntax to the Kotlin code used to set a custom beacon parser is not correct. The parser must be added to the BeaconManager's list of registered parsers. See sample line of code in the reference app here:
from android-beacon-library.
I had modify the code ,but still can't parse devices
code:
object BeaconUtil {
// 425beaab-a990-f1b2-0145-6acef15d3b65
private const val regionUuid = "bce1cbda-07c5-a8b9-1098-6ed7179d24b8"
/*init {
BeaconManager.setDebug(true)
}*/
@JvmStatic
val allRegion by lazy {
Region("beacons", null, null, null)
}
@JvmStatic
val customRegion by lazy {
Region("beacon", Identifier.parse(regionUuid), null, null)
}
@JvmStatic
val iBeaconParser by lazy {
BeaconParser().apply {
setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")
setHardwareAssistManufacturerCodes(arrayOf(0x004c).toIntArray())
}
}
@JvmStatic
val beaconManager by lazy {
BeaconManager.getInstanceForApplication(PepsApplication.context).apply {
beaconParsers.clear()
beaconParsers.add(iBeaconParser)
backgroundScanPeriod = 10000
backgroundBetweenScanPeriod = 1000
if (isNotificationPermissionGranted())
enableForegroundServiceScanning(NotificationUtil.getNotification(R.string.iBeacon_service_running), NotificationUtil.ID)
}
}
private fun isBeaconPermissionsGranted(): Boolean {
return PermissionUtil.isPermissionsGranted(PepsApplication.context, *PermissionUtil.beaconPermissions.toTypedArray())
}
private fun isNotificationPermissionGranted(): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
return PermissionUtil.isPermissionsGranted(PepsApplication.context, Manifest.permission.POST_NOTIFICATIONS)
return true
}
@JvmStatic
@JvmOverloads
fun startNotify(region: Region = allRegion,
rangeNotifier: RangeNotifier? = null,
monitorNotifier: MonitorNotifier? = null) {
if (isBeaconPermissionsGranted()) beaconManager.apply {
rangeNotifier?.let {
startRangingBeacons(region)
addRangeNotifier(rangeNotifier)
}
monitorNotifier?.let {
startMonitoring(region)
addMonitorNotifier(it)
}
}
}
@JvmStatic
@JvmOverloads
fun subscribe(region: Region = allRegion,
owner: LifecycleOwner? = null,
monitoringObserver: Observer<Int>? = null,
rangingObserver: Observer<Collection<Beacon>>? = null) {
beaconManager.apply {
monitoringObserver?.let {
startMonitoring(region)
owner?.apply { getRegionViewModel(region).regionState.observe(this, it) }
?: getRegionViewModel(region).regionState.observeForever(it)
}
rangingObserver?.let {
startRangingBeacons(region)
owner?.apply { getRegionViewModel(region).rangedBeacons.observe(this, it) }
?: getRegionViewModel(region).rangedBeacons.observeForever(it)
}
}
}
fun stop(region: Region = allRegion) {
beaconManager.stopMonitoring(region)
beaconManager.stopRangingBeacons(region)
}
fun isAnyConsumerBound(): Boolean {
return beaconManager.isAnyConsumerBound
}
}
LOG:
2023-12-06 10:33:08.229 1894-1894 BeaconManager com.uaes.peps I BeaconManager started up on pid 1894 named 'com.uaes.peps' for application package 'com.uaes.peps'. isMainProcess=true
2023-12-06 10:33:08.231 1894-1894 BeaconParser com.uaes.peps D Parsing beacon layout: m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25
2023-12-06 10:33:08.231 1894-1894 BeaconParser com.uaes.peps D Parsing beacon layout: m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24
2023-12-06 10:33:08.231 1894-1894 BeaconManager com.uaes.peps W Setting a short backgroundBetweenScanPeriod has no effect on Android 8+, which is limited to scanning every ~15 minutes
2023-12-06 10:33:08.235 1894-1894 BeaconManager com.uaes.peps W Disabling ScanJobs on Android 8+ may disable delivery of beacon callbacks in the background unless a foreground service is active.
2023-12-06 10:33:08.236 1894-1894 ScanJob com.uaes.peps I Using immediateScanJobId from manifest: 208352939
2023-12-06 10:33:08.236 1894-1894 ScanJob com.uaes.peps I Using periodicScanJobId from manifest: 208352940
2023-12-06 10:33:08.238 1894-1894 BackgroundPowerSaver com.uaes.peps I Background mode not set. We assume we are in the foreground.
2023-12-06 10:33:08.238 1894-1894 BeaconManager com.uaes.peps I Attempting to starting foreground beacon scanning service.
2023-12-06 10:33:08.240 1894-1894 BeaconManager com.uaes.peps I successfully started foreground beacon scanning service.
2023-12-06 10:33:08.246 1894-1894 DecorView[] com.uaes.peps D getWindowModeFromSystem windowmode is 1
2023-12-06 10:33:08.246 1894-1894 DecorView[] com.uaes.peps D updateDecorCaptionStatus windowMode is 1
2023-12-06 10:33:08.268 1894-24514 Parcel com.uaes.peps W Expecting binder but got null!
2023-12-06 10:33:08.271 1894-1894 CycledLeScanner com.uaes.peps I Using Android O scanner
2023-12-06 10:33:08.273 1894-1894 ScanHelper com.uaes.peps D BeaconParsers set to count: 0
2023-12-06 10:33:08.273 1894-1894 BeaconService com.uaes.peps I beaconService version 2.20.3 is starting up on the main process
2023-12-06 10:33:08.275 1894-1894 ModelSpeci...Calculator com.uaes.peps W Cannot find match for this device. Using default
2023-12-06 10:33:08.275 1894-1894 ModelSpeci...Calculator com.uaes.peps W Cannot find match for this device. Using default
2023-12-06 10:33:08.276 1894-1894 BeaconService com.uaes.peps I starting with intent Intent { cmp=com.uaes.peps/org.altbeacon.beacon.service.BeaconService }
2023-12-06 10:33:08.276 1894-1894 BeaconService com.uaes.peps I binding
2023-12-06 10:33:08.277 1894-1894 DecorView[] com.uaes.peps D onWindowFocusChanged hasWindowFocus false
2023-12-06 10:33:08.311 3534-4748 ActivityManagerWrapper com.miui.home E getRecentTasks: mainTaskId=6070 userId=0 baseIntent=Intent { act=android.intent.action.MAIN flag=270532608 cmp=ComponentInfo{com.uaes.peps/com.uaes.peps.ui.activity.MainActivity} }
2023-12-06 10:33:08.317 3534-4748 ActivityManagerWrapper com.miui.home E getRecentTasks: mainTaskId=6070 userId=0 baseIntent=Intent { act=android.intent.action.MAIN flag=270532608 cmp=ComponentInfo{com.uaes.peps/com.uaes.peps.ui.activity.MainActivity} }
2023-12-06 10:33:08.388 1894-1894 DecorView[] com.uaes.peps D onWindowFocusChanged hasWindowFocus true
2023-12-06 10:33:08.388 1894-1894 HandWritingStubImpl com.uaes.peps I refreshLastKeyboardType: 1
2023-12-06 10:33:08.388 1894-1894 HandWritingStubImpl com.uaes.peps I getCurrentKeyboardType: 1
2023-12-06 10:33:08.390 1894-1894 BeaconService com.uaes.peps I start ranging received
2023-12-06 10:33:08.393 1894-24650 BluetoothAdapter com.uaes.peps D isLeEnabled(): ON
2023-12-06 10:33:08.396 1894-24465 BluetoothLeScanner com.uaes.peps D onScannerRegistered() - status=0 scannerId=10 mScannerId=0
2023-12-06 10:33:08.399 1948-7518 AppOps system_server E Bad call made by uid 1002. Package "com.uaes.peps" does not belong to uid 1002.
2023-12-06 10:33:08.486 1894-1894 BeaconService com.uaes.peps I Received settings update
2023-12-06 10:33:09.249 1894-24494 com.uaes.peps com.uaes.peps I ProcessProfilingInfo new_methods=1055 is saved saved_to_disk=1 resolve_classes_delay=8000
2023-12-06 10:33:14.687 1894-1894 BeaconService com.uaes.peps I set scan intervals received
2023-12-06 10:33:14.710 1894-1894 BeaconService com.uaes.peps I set scan intervals received
2023-12-06 10:33:14.710 1894-1894 CycledLeScanner com.uaes.peps I Adjusted scanStopTime to be 176769874
2023-12-06 10:33:14.711 1894-1894 DecorView[] com.uaes.peps D onWindowFocusChanged hasWindowFocus false
2023-12-06 10:33:14.725 1894-1894 DecorView[] com.uaes.peps D onWindowFocusChanged hasWindowFocus true
2023-12-06 10:33:14.726 1894-1894 HandWritingStubImpl com.uaes.peps I refreshLastKeyboardType: 1
2023-12-06 10:33:14.726 1894-1894 HandWritingStubImpl com.uaes.peps I getCurrentKeyboardType: 1
2023-12-06 10:33:14.791 3534-4748 ActivityManagerWrapper com.miui.home E getRecentTasks: mainTaskId=6070 userId=0 baseIntent=Intent { act=android.intent.action.MAIN flag=270532608 cmp=ComponentInfo{com.uaes.peps/com.uaes.peps.ui.activity.MainActivity} }
2023-12-06 10:33:14.804 3534-4748 ActivityManagerWrapper com.miui.home E getRecentTasks: mainTaskId=6070 userId=0 baseIntent=Intent { act=android.intent.action.MAIN flag=270532608 cmp=ComponentInfo{com.uaes.peps/com.uaes.peps.ui.activity.MainActivity} }
2023-12-06 10:33:14.816 3534-4748 ActivityManagerWrapper com.miui.home E getRecentTasks: mainTaskId=6070 userId=0 baseIntent=Intent { act=android.intent.action.MAIN flag=270532608 cmp=ComponentInfo{com.uaes.peps/com.uaes.peps.ui.activity.MainActivity} }
2023-12-06 10:33:14.902 1894-24650 BluetoothAdapter com.uaes.peps D isLeEnabled(): ON
2023-12-06 10:33:14.905 1894-24650 BluetoothAdapter com.uaes.peps D isLeEnabled(): ON
2023-12-06 10:33:14.907 1894-24465 BluetoothLeScanner com.uaes.peps D onScannerRegistered() - status=0 scannerId=10 mScannerId=0
2023-12-06 10:33:14.910 1948-4188 AppOps system_server E Bad call made by uid 1002. Package "com.uaes.peps" does not belong to uid 1002.
2023-12-06 10:33:15.221 1894-24514 OpenGLRenderer com.uaes.peps D endAllActiveAnimators on 0xb40000723907a700 (AppCompatImageView) with handle 0xb4000072a5418860
2023-12-06 10:33:15.227 1894-1894 com.uaes.peps com.uaes.peps W Accessing hidden field Landroid/view/inputmethod/InputMethodManager;->mCurRootView:Landroid/view/ViewRootImpl; (blocked, reflection, denied)
2023-12-06 10:33:15.237 1894-1894 BeaconService com.uaes.peps I stop monitoring received
2023-12-06 10:33:15.241 1894-1894 com.uaes.peps com.uaes.peps E No package ID 35 found for ID 0x35a4e900.
2023-12-06 10:33:15.245 1894-1894 BeaconService com.uaes.peps I stop ranging received
2023-12-06 10:33:15.245 1894-24650 BluetoothAdapter com.uaes.peps D isLeEnabled(): ON
2023-12-06 10:33:15.246 1894-1894 BeaconService com.uaes.peps I unbinding so destroying self
2023-12-06 10:33:15.248 1894-1894 BeaconService com.uaes.peps E onDestroy()
2023-12-06 10:33:15.248 1894-1894 BeaconService com.uaes.peps I onDestroy called. stopping scanning
from android-beacon-library.
from android-beacon-library.
Related Issues (20)
- Range beacons when app is terminating HOT 7
- Beacons ranging not working on android 13 HOT 1
- App stops scanning right after screen is locked and starts giving the results right after unlocked HOT 1
- Android beacon library - multiple regions monitoring - unable remove regions HOT 2
- startForeground Exception when app is not in foreground HOT 3
- StartupBroadcastReceiver throws NullPointerException HOT 2
- No beacons after locked screen HOT 19
- BeaconService.startForegroundIfConfigured HOT 12
- TargetSdk 34 (android 14) Beacon foreground service no longer working due to new Google restriction HOT 1
- Do we have sample app to implement the library including the operation running in Background HOT 4
- Only a maximum of 2 beacons can be received at a time HOT 1
- java.io.FileNotFoundException android-distance.json HOT 3
- android-distance.json database not found
- Crash when parsing _lengthy_ beacon data fields HOT 3
- Custom Distance calculator is being overwritten HOT 6
- Samsung devices not detecting beacons by intent after first screen off
- Can we use this with tauri mobile? HOT 3
- Main thread can be blocked sometimes
- Android 14 didDetermineStateForRegion no beacon is detected or scanned HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-beacon-library.