android - 从最新的 Android 版本开始,未触发接近警报
问题描述
至少从 2015 年到 2019 年初,以下代码运行良好;但从 2019 年的某个时间开始,它就停止了工作。我不能说什么时候,因为由于健康问题,我在整个 2019 年都没有编写代码。我有一台运行 Android 6.0 的旧三星 S5。该代码适用于它。我有一台运行 Android 9.0 的三星 S9。代码在它上面失败了。我无法在 Android 7 或 8 上运行,所以我不知道它何时开始失败。
该代码执行以下操作: 方法 setupProximityAlerts 注册 ProxReceiver。然后它从数据库中获取所需的航路点位置;并为每个调用方法 addProximityAlert。它创建一个隐式意图,为其检索一个广播pendingIntent,并将该未决意图发送到mLocationManager.addProximityAlert。现在,当设备接近任何航点时,所有航点都已注册以触发/触发广播。
mProxReceiver = new ProxReceiver( );
IntentFilter sFilter = new IntentFilter( "dkr.ajijic.apps.tm.PROX_ALERT" );
mContext.registerReceiver( mProxReceiver, sFilter );
mMediaCursor = tmProviderUtils.getWaypointCursor(trkId, 0, 10000);
if (mMediaCursor.getCount() <= 1) return false;
if (mMediaCursor.moveToFirst()) {
do {
addProximityAlert(mMediaCursor);
}
while (mMediaCursor.moveToNext());
...
private void addProximityAlert( MediaCursor mMediaCursor) {
getWaypointProperties(mMediaCursor);
Intent intent = new Intent( "dkr.ajijic.apps.tm.PROX_ALERT" );
PendingIntent proxPendingIntent = PendingIntent.getBroadcast(
mContext, wptId, intent, 0);
...
mLocationManager.addProximityAlert( latitude, longitude, proxRadius, -1L, proxPendingIntent );
}
以下代码(在 ForeGround 服务中)将每个 GPS 定位发送到 LocationManager。
private void onLocationChangeUnFilter(final Location location ) {
if(location == null) return;
if(googleLocationListener != null)
googleLocationListener.onLocationChanged(location);
我知道它有效,因为当我走路时,位置光标会在地图上移动。当我接近一个航点时,ProxReceiver.onReceive 方法应该接收到一个广播。问题是:LocationManager 不再广播。
作为测试,我编写了 AlarmManager 来广播其中一个pendingIntent,而 ProcReceiver.onReceive 确实收到了广播。这意味着问题不在意图或未决意图中。所以,我很确定问题出在 LocationManager 上。
只是为了涵盖基础:这是相关的清单代码。
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...
<receiver android:name=".tour.ProxReceiver" >
<intent-filter>
<action android:name="dkr.ajijic.apps.tm.PROX_ALERT" />
</intent-filter>
</receiver>
我已经阅读了适用于 Android 7、8 和 9 的 Google 发布文档。我已经阅读了几十个 stackOverflow 问题/回复。我一直在寻找最近的文章、示例、教程等。一切都无济于事。如果有人可以提供帮助,我当然会很感激!
解决方案
推荐阅读
- c# - 为什么没有加载对象的颜色?
- php - 如何将我的 Mysqli 绑定结果之一放入数组中以使用 in_array() 函数进行匹配?
- go - 是否有更惯用的方法来根据输入创建特定类型的变量?
- uwp - 在 C++/WinRT 中实现 ICustomProperty
- javascript - 无法删除 mongodb 条目
- javascript - 您可以根据元素值制作 :after 样式吗?
- django - 由于导入错误,无法运行 gunicorn
- bash - 如果不是在下一行,如果在每 3 行找到,如何用字符串 grep 行
- ms-access - 行继续显示#DELETED
- office365 - 通过 EWS 访问 Office 365 在线存档