java - 设备位置在另一台设备上为空(GoogleMaps 活动)
问题描述
我目前正在开发我的第二个包含谷歌地图活动的安卓应用程序。在这个活动中,我想向用户展示他们当前的位置。我设法做到了,它适用于我的两种设备(华为 P smart 和 Galaxy S5)。我还向我的朋友发送了该应用程序的 APK,在他的设备(华为 P9 Lite)上,调用 task.getResult() 后,当前位置返回 null。在他的设备上,该方法将始终跳转到 else 语句(意味着 currentLocation == null)。我使用了以下方法。
private void getDeviceLocation() {
Log.d(TAG, "getDeviceLocation: getting the devices current location");
try {
mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
mFusedLocationProviderClient.getLastLocation()
.addOnSuccessListener(this, new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location currentLocation) {
Log.d(TAG, "onComplete: found location!");
if (currentLocation != null) {
moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),
DEFAULT_ZOOM);
} else {
Log.d(TAG, "onComplete: current location is null");
Toast.makeText(MapsActivity.this, "unable to get current location", Toast.LENGTH_SHORT).show();
}
}
});
} catch (SecurityException e) {
Log.e(TAG, "getDeviceLocation: SecurityException: " + e.getMessage());
}
}
我已经尝试/做了以下事情:
- 将所有必需的权限/功能添加到我的清单
- 尝试我在这里找到的其他一些解决方案,据我所知,它们都没有在不同的设备上显示不同的结果
- 将 minSDK 更改为 17(之前为 23)。
- 添加 nullcheck 和 try & catch
因为我在自己的设备上没有任何问题,并且在我的 logcat 中找不到任何值得注意的东西(因为它都在我的设备上运行),所以我很难理解为什么会发生这种情况。
解决方案
推荐阅读
- edi - 如何为 EDI 数据交换创建 VAN?
- python - 如何将用户的输入转化为单个变量?
- java - 通过强制转换返回不同对象的方法
- vim - vimgrep 可以与环视断言一起使用吗?
- amazon-web-services - AWS EC2 策略无法更改用户数据
- templates - django:如何创建由父表和子表组成的表,但只有最新的孩子?
- javascript - 如何从文件标签内的硬盘中获取那些选定的文件并将其传递给另一个php函数
- c - 'sys/cdefs.h':在 Eclipse for C/C++ 上没有此类文件或目录错误
- java - org.openqa.selenium.NoSuchElementException:没有这样的元素:无法在 selenium 中找到元素,java 使用 TestNG
- java - 这个表达式的数据类型是什么?(3 + 4 / (int)3.14) * 5