java - 带有 PendingIntent 的 LocationManager.requestLocationUpdates 在 API 26 上不起作用
问题描述
我正在编写一个使用 gps 跟踪和记录设备位置的应用程序,它在 API 21 上运行良好,但是当我切换到 API 26 时它停止工作。
我使用了定期发送未决意图的请求位置更新:
public void startLocationUpdates() throws SecurityException
{
String provider = LocationManager.GPS_PROVIDER;
PendingIntent pi = getLocationPendingIntent(true);
//this method keep updating unless we specify it to stop
mLocationManager.requestLocationUpdates(provider, 0, 0, pi);
}
我正在使用此接收器处理待处理的意图:
public class LocationReceiver extends BroadcastReceiver
{
private static final String TAG = "LocationReceiver";
@Override
public void onReceive(Context context, Intent intent)
{
Log.d(TAG, "Receive an intent");
Location= (Location)intent.getParcelableExtra(LocationManager.KEY_LOCATION_CHANGED);
Log.d(TAG, this + " Got location from " + loc.getProvider() + ": " + loc.getLatitude() + ", " + loc.getLongitude());
}
}
我认为这与这条线有关:
2019-02-08 21:41:05.872 1995-2015/system_process W/BroadcastQueue: Background execution not allowed: receiving Intent { act=com.pproject.runtracker.ACTION_LOCATION flg=0x10 (has extras) } to com.pproject.runtracker/.Controller.LocationReceiver
我不确定这意味着什么
解决方案
推荐阅读
- http-live-streaming - nginx rtmp 到 hls 流式传输
- zebra-printers - 在 ZPL 文件中包含各种符号(如 Recycle、Rain)以打印标签的方法
- sql - 如何在 SQL 脚本中命名字段?
- macos - 为较旧的 Mac OS 版本构建 golang 应用程序的正确方法是什么?
- android - 华为定位包在室内无法获取到我的位置
- python - 该列表如何在 django 中返回值和键
- javascript - 在 Typescript 中使用外部 JS-Library(基本原语图)
- javascript - 如何使用 JavaScript 检查另一个元素中是否有一个元素
- java - 无法解析intellij中的符号jsonobject
- python - 图形大小随颜色条变化