我试图从android developer:https://developer.android.com/codelabs/advanced-android-kotlin-training-geofencing?authuser=2#0上运行这个应用程序。
地学正在增加,但什么也没有触发。我试过检查这个页面:https://simpleinout.helpscoutdocs.com/article/232-my-geofences-arent-working-android,但是我的手机似乎没问题.
当我得到一条“添加地理信息”的日志时,如何才能不触发广播呢?我的模拟器、意图或broadcastReceiver有什么问题吗??
BroadcastReceiver:
class GeofenceBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == ACTION_GEOFENCE_EVENT) {
val geofencingEvent = GeofencingEvent.fromIntent(intent)
if (geofencingEvent.h意图:
private val geofencePendingIntent: PendingIntent by lazy {
val intent = Intent(this, GeofenceBroadcastReceiver::class.java)
intent.action = ACTION_GEOFENCE_EVENT
PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}增加地理位置:
addOnCompleteListener {
// Add the new geofence request with the new geofence
geofencingClient.addGeofences(geofencingRequest, geofencePendingIntent)?.run {
addOnSuccessListener {
// Geofences added.此外,ACCESS_BACKGROUND_LOCATION和ACCESS_FINE_LOCATION的位置“始终允许”。
发布于 2022-01-11 14:21:15
终于弄明白了。密码里什么都没有。在仿真器上测试不起作用(至少对我不起作用,通过单击设置并以这种方式改变位置)
对我起作用的是在一个真正的设备上测试:
location
。
https://stackoverflow.com/questions/70665948
复制相似问题