请按以下步骤检查您的代码:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_FINE_LOCATION); } else { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); }
设置 -> 应用程序 -> 您的应用程序 -> 权限 -> 位置
此操作应该已解决您的问题。
上一篇:AndroidStudio出现错误:安装失败,原因:‘cmdpackageinstall-create…’
下一篇:Androidstudio出现JavaDocerrorthrowsaNullPointerException错误