android - Android Wear Geofence 调用 addGeofences-method 返回异常:1000
问题描述
我在Fossil Falster 3上玩Wear OS(它正在运行API 28)。另外请知道我只是从 开始,所以下面的代码至少可以说是不好的。Kotlin
我想使用广播接收器创建一个地理围栏。
在我的MainActivity.kt
我有以下内容:
override fun onStart() {
super.onStart()
requestForegroundAndBackgroundLocationPermissions()
val locations = arrayOf(Location("tgh", 58.798233, 11.123959))
val geofences = locations.map {
Geofence.Builder()
.setRequestId(it.name)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setCircularRegion(it.latitude, it.longitude, 100F)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_DWELL)
.setLoiteringDelay(10)
.build()
}
val geofencingRequest = GeofencingRequest.Builder().apply {
setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
addGeofences(geofences)
}.build()
val geofencePendingIntent: PendingIntent by lazy {
val intent = Intent(this, GeofenceReceiver::class.java)
PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
val geofencingClient = LocationServices.getGeofencingClient(this)
geofencingClient.addGeofences(geofencingRequest, geofencePendingIntent).run {
addOnFailureListener {
// display error
exception -> Log.d(TAG, "addOnFailureListener Exception: $exception")
}
addOnSuccessListener {
// move on
Log.d(TAG, "addOnSuccessListener, move on")
}
}
}
在GeofenceReceiver
同一个文件中:
class GeofenceReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val geofencingEvent = GeofencingEvent.fromIntent(intent)
if (geofencingEvent.hasError()) {
Log.d(TAG, "geofencingEvent.hasError()")
} else {
geofencingEvent.triggeringGeofences.forEach {
val geofence = it.requestId
Log.d(TAG, "location at: " + geofence)
}
}
}
}
具有以下manifest
代码段:
<receiver android:name=".GeofenceReceiver"
android:enabled="true"
android:exported="true"/>
差不多就是这样。当我运行代码时,addOnFailureListener
会触发并打印错误消息并导致 1000 异常。
异常 1000 根据谷歌文档的意思GEOFENCE_NOT_AVAILABLE
。我已将手表和手机上的定位功能启用到手机上的最高级别 ( Improve Location Accuracy is ON
)。在手表上,我已设置使用手表和手机的位置(最高级别)。我仍然不断收到 1000 错误代码。
解决方案
推荐阅读
- c# - 如何检查列表中具有唯一组合的多个属性,其中属性名称可作为单独的集合使用。[C#]
- azure - Azure IoTHub 函数 Cosmos DB (js)
- html - Flex lists not wrapping
- mysql - 合并mysql中某些列中具有不同值的行
- java - 使用 vertx 将 Mongo 集合流式传输到 Kafka 主题的方法应该是什么?
- c# - 获取数据类型的全名
- android - 使用领域之外的事务查询对象是一种好习惯吗?
- php - 如果 CI 中的杂货杂货中的字符串太长,则在 x 个字符后添加 ...
- mysql - 为所有记录查找特定值的 SQL 查询
- xampp - 当 sudo PATH=$PATH /opt/lampp/xampp startapache 时如何保留/设置我的 CONDA 环境变量