-
Notifications
You must be signed in to change notification settings - Fork 837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
altbeacon does not detect beacon devices on Android 12 and later #1197
Comments
@G-Roman1988 Could you please attach minimal reproducible sample? I can confirm that this library detects IBeacon Beacons on Android 12+. |
|
Hi @G-Roman1988 You don't need your foreground service. The library already declared everthing and you just need to build notification, notification channel, grant notification permission(if I'm not mistaken). This code starts the foreground service. ForegroundService -> https://altbeacon.github.io/android-beacon-library/foreground-service.html If you need to have BLE comunications with BLE device when the beacons are found:
val builder = Notification.Builder(this) In your service -> startForeground() with the same notification id and notification. So, you will foregound service scanning in library and your own.
Side notes: override fun onCreate() { It looks strange and not sure that it can work - cast applicationContext to Activity. |
Hello @VolodaUa! I dropped the personal foreground service and set altbeacon to use its own foreground service, which is declared. I created the channel for notification and notification but it doesn't work and the notification doesn't show either. to app info on notification is not active to allow notifications. on this link : https://altbeacon.github.io/android-beacon-library/foreground-service.html there is some information but i am new to android and i don't understand much there. I am leaving the code below modified and please help me out of this deadlock. package com.gtdvm.echopoint import android.annotation.SuppressLint //import android.window.OnBackInvokedCallback //import androidx.core.app.ComponentActivity class BluetoothServices(private val activity: AppCompatActivity): RangeNotifier, MonitorNotifier {
createNotificationChannel()
beaconManager.setEnableScheduledScanJobs(false)
//if (throwable is RxB){ //} @SuppressLint("CheckResult")
beacons?.forEach{beacon ->
this.removeDeviceOfList(region?.bluetoothAddress)
when (state) {
e.printStackTrace()
e.printStackTrace()
Log.d("NOTIFICATION_CHANEL", "the create notification channel function was called")
// .setContentIntent(pendingIntent)
} this is log after i modified with foreground service. 2024-07-08 07:03:35.953 12677-12677 BeaconManager com.gtdvm.echopoint I BeaconManager started up on pid 12677 named 'com.gtdvm.echopoint' for application package 'com.gtdvm.echopoint'. isMainProcess=true |
I solved it with the foreground service notification, when I start the scan, the notification also appears, but the beacon devices are not identified on android 12 and higher but on android 11, everything is fine. in the log, no changes, I see no errors or warnings. |
Hi @G-Roman1988 I'll check once I have free time. Please attach the minimal reproducible project without the build folder. Just project folder. Before that, I would recommend you do the following now:
Emulate your beacon using this app. Only iBeacon part!!! beaconManager.foregroundScanPeriod = 1100L |
I had a similar issue and removing neverForLocation from BLUETOOTH_SCAN permission solved my issue. |
[Echopoint.zip](https://github.com/user-attachment Hello ! I have tried all your ideas with no success. I have attached code from the project zip file, maybe you can identify what the problem is and where. for me when i start scan the notification shows after a second and I don't know if that's good or not. I have this in my diary: 2024-07-24 12:34:07.085 6848-6848 BeaconManager com.gtdvm.echopoint I BeaconManager started up on pid 6848 named 'com.gtdvm.echopoint' for application package 'com.gtdvm.echopoint'. isMainProcess=true |
@G-Roman1988 This file is not available. |
I'm attaching the file again and if it doesn't work I'll leave this link for download |
Hello! The Android beacon/altbeacon library (version 2.20.6) does not identify any beacon devices on Android 12 and above, but on Android 11 and below the same code works (it identifies). I am working on an application to help visually impaired people identify public transport and I am stuck with this problem. I have tried many solutions I found on the internet and in the documentation, but with no success. Steps to reproduce the problem: create a standard iBeacon and set a UUID for personal proximity, then try to scan beacon devices with the Android beacon/altbeacon library version 2.20.6 on Android 12+. In the log, it shows something about the scan job immediately and the periodic scan time. I will leave the code and manifest file below. Please, anyone who can help, any solution is welcome. package com.gtdvm.echopoint
import android.annotation.SuppressLint
import android.app.Activity
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.bluetooth.BluetoothGatt
import android.bluetooth.BluetoothGattCallback
import android.bluetooth.BluetoothManager
import android.bluetooth.le.ScanCallback
import android.bluetooth.BluetoothGattService
import android.bluetooth.BluetoothGattCharacteristic
import android.bluetooth.BluetoothGattCharacteristic.PERMISSION_READ
import android.bluetooth.BluetoothGattCharacteristic.PERMISSION_WRITE
import android.bluetooth.BluetoothGattCharacteristic.PROPERTY_WRITE
import android.bluetooth.BluetoothGattCharacteristic.PROPERTY_NOTIFY
import android.bluetooth.BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT
import android.bluetooth.BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
import android.bluetooth.BluetoothGattDescriptor
import com.polidea.rxandroidble3.RxBleClient
import com.polidea.rxandroidble3.RxBleConnection
import com.polidea.rxandroidble3.RxBleDevice
import com.polidea.rxandroidble3.RxBleDeviceServices
import com.polidea.rxandroidble3.scan.ScanSettings
import com.polidea.rxandroidble3.scan.ScanFilter
import com.polidea.rxandroidble3.scan.ScanResult
import com.polidea.rxandroidble3.RxBleScanResult
import com.polidea.rxandroidble3.exceptions.BleException
import com.polidea.rxandroidble3.exceptions.BleDisconnectedException
import com.polidea.rxandroidble3.NotificationSetupMode
import com.polidea.rxandroidble3.RxBleConnection.RxBleConnectionState
import android.location.LocationManager
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.content.pm.PackageManager
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import android.content.Context
import android.content.ServiceConnection
import android.icu.number.IntegerWidth
import android.os.Build
import android.os.Looper
import android.os.ParcelUuid
import android.os.RemoteException
import android.provider.Settings
import android.util.Log
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.defaultDecayAnimationSpec
import androidx.compose.ui.res.integerResource
import androidx.compose.ui.res.stringArrayResource
import androidx.lifecycle.ViewModelProvider
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.core.Completable
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.core.SingleSource
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.internal.operators.observable.ObservableIgnoreElementsCompletable
import io.reactivex.rxjava3.internal.operators.observable.ObservableJust
import io.reactivex.rxjava3.internal.operators.observable.ObservableScan
import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.newFixedThreadPoolContext
import java.lang.StringBuilder
import java.nio.ByteBuffer
import java.util.UUID
//import com.gtdvm.echopoint.Utils.getMajor
//import com.gtdvm.echopoint.Utils.getMinor
//import com.gtdvm.echopoint.Utils.getUUID
import org.altbeacon.beacon.BeaconManager
import org.altbeacon.beacon.BeaconParser
import org.altbeacon.beacon.MonitorNotifier
import org.altbeacon.beacon.RangeNotifier
import org.altbeacon.beacon.Region
import org.altbeacon.beacon.*
//import android.window.OnBackInvokedCallback
//import android.window.OnBackInvokedDispatcher
//import androidx.activity.OnBackPressedCallback
//import androidx.core.app.ComponentActivity
//import androidx.activity.result.ActivityResultLauncher
//import androidx.activity.result.ActivityResult
//import androidx.activity.result.ActivityResultCallback
//import android.Manifest
class BluetoothServices(private val activity: AppCompatActivity): RangeNotifier, MonitorNotifier {
private var managerDevices: ManagerDevices = ManagerDevices(activity)
private var beaconManager: BeaconManager = BeaconManager.getInstanceForApplication(activity)
private var rxBleClient: RxBleClient = RxBleClient.create(activity)
var currentBleConnection: RxBleConnection? = null
private var selectedRxBleDeviceClient: RxBleDevice? = null
private var scanDisposable: Disposable? = null
private var connectionDisposable: Disposable? = null
//private val compositeDisposable = CompositeDisposable()
private var personalBleService: BluetoothGattService? = null
private var notificationCaracteristic: BluetoothGattCharacteristic? = null
private var writeCaracteristic: BluetoothGattCharacteristic? = null
private var descriptorBLE2902: BluetoothGattDescriptor? = null
private val devicesFound = mutableListOf()
//beaconManager.foregroundScanPeriod = 16000L
// beaconManager.foregroundBetweenScanPeriod = 0L
beaconManager.backgroundMode = false
beaconManager.addMonitorNotifier(this)
beaconManager.addRangeNotifier(this)
}
//if (throwable is RxB){
//}
})
} else{
Log.e("ERROR", "Caracteristica nu poate fii scrisa")
}
} else{
Log.e("ERROR", "nu sa găsit caracteristica cu uuid specificat")
}
} catch (e: Exception){
Log.e("EXCEPTION", "$e")
}
}
@SuppressLint("CheckResult")
private fun RxBleConnection.enableNotificationCharacteristic (): Observable? {
Log.e("NOTIFICATION-CHARACTERISTIC", "the notify function was called")
return if (notificationCaracteristic != null && notificationCaracteristic?.uuid == UUID.fromString(notificationUUID)){
Log.e("NOTIFICATION-CHARACTERISTIC", "caracteristica nu este null")
val prn = notificationCaracteristic!!.properties and PROPERTY_NOTIFY
val pen = notificationCaracteristic!!.permissions and PERMISSION_READ
Log.d("INFORMATION_CHARACTERISTIC", "propriety: $prn permission: $pen")
if (prn == PROPERTY_NOTIFY){
Log.d("MESSAGE", "are permissions for notification")
this.setupNotification(notificationCaracteristic!!)
.flatMap{notificationObservable ->
if (!this.isEnabledDescriptor2902()){
Log.d("DESCRIPTOR_STATUS", "descriptor status is disabled")
this.writeDescriptor(descriptorBLE2902!!, BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)
.subscribe({
Log.d("WRITE_DESCRIPTOR_STATUS", "descriptor was written successfully")
},{
Log.d("WRITE_DESCRIPTOR_STATUS", "an error occurred when writing the descriptor")
})
}
notificationObservable}
} else{
Log.d("ERROR", "cannot permissions for notification")
Observable.error(Throwable("caracteristica de notification nu se citeste sau de activat notification"))
}
} else{
Observable.error(Throwable("caracteristica cu UUID specificat nu afost găsit sau este null"))
}
}
beacons?.forEach{beacon ->
if (isPointer(beacon.id1)){
val iBeacon = IBeacon(beacon.bluetoothAddress)
iBeacon.uuid = beacon.id1.toString()
iBeacon.major = beacon.id2.toInt()
iBeacon.minor = beacon.id3.toInt()
iBeacon.rssi = beacon.rssi
iBeacon.manufacturer = beacon.manufacturer.toString()
devicesFound.add(iBeacon)
iBeaconsView.updateListIBeacons(devicesFound)
}
}
}
this.removeDeviceOfList(region?.bluetoothAddress)
iBeaconsView.updateListIBeacons(devicesFound)
}
}
when (state) {
MonitorNotifier.INSIDE -> Log.d("BeaconMonitoring", "Inside region: ${region?.uniqueId}")
MonitorNotifier.OUTSIDE -> Log.d("BeaconMonitoring", "Outside region: ${region?.uniqueId}")
}
}
e.printStackTrace()
//emiter.onError(e)
}
//return devicesFound
}
}
e.printStackTrace()
}
}
}
this is the manifesto
I don't know and don't understand if I am doing something wrong or if there is a problem with the altbeacon library or with Android. So please, anyone who has experience and knowledge, help me understand how I can solve this problem.
The text was updated successfully, but these errors were encountered: