[英]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.