[英]Google Awareness API cannot register location fence (Fence API) Kotlin
Ive been trying to use Google Awareness API (Fence API) and I can register every other kind of fence - headphones, walking- and my broadcast reciever that handles callbacks from fence state changes is working but keep getting com.google.android.gms. common.api.ApiException:注册位置围栏时出现 7503
寻找有关堆栈溢出的类似帖子,并确保我没有关闭我的手机位置 - 以下是我一直试图仅用于位置围栏类型的代码
显现:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.location_try_dos">
<!-- Needed For Awarness - Fence API -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<receiver
android:name=".FenceReciever"
android:enabled="true"
android:exported="false"></receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.awareness.API_KEY"
android:value="MYKEY" />
</application>
</manifest>
MainActivity.kt
override fun onStart() {
super.onStart()
Timber.i("onStart Called")
//there was two optations for manifest
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED){
Toast.makeText(this,
"Have Permissions Needed",
Toast.LENGTH_LONG).show()
val locationFence:AwarenessFence = LocationFence.entering(37.4220,-122.0841, 1609.0)
Awareness.getFenceClient(this).updateFences(FenceUpdateRequest.Builder()
.addFence(FENCE_KEY, locationFence,
PendingIntent.getBroadcast(
this,
FENCE_INTENT_ID,
Intent(this,FenceReciever::class.java),
PendingIntent.FLAG_UPDATE_CURRENT))
.build())
.addOnSuccessListener { Log.i("FENCE API", "Fence was successfully registered.") }
.addOnFailureListener { e -> Log.e("FENCE API", "Fence could not be registered: $e") }
}
}
万一有人也遇到这个问题。
android 10 api 29 在物理设备上
如果您在 api 30 上进行测试 - 您只需要“在应用程序正在使用时允许”即可正确注册位置围栏
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.