0
내가 위치를 얻기 위해 안드로이드 6.0이 코드를 사용하고 작동하지 않습니다 : 위치 코드는 더 이상
public class MainActivity extends AppCompatActivity implements LocationListener{
protected LocationManager locationManager;
protected LocationListener locationListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (checkPermission())
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
lati = location.getLatitude();
longi = location.getLongitude();
}
@Override
public void onProviderDisabled(String provider) {
Log.d("Latitude", "disable");
}
@Override
public void onProviderEnabled(String provider) {
Log.d("Latitude", "enable");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Latitude", "status");
}
private boolean checkPermission(){
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return false;
}
return true;
}
}
나는 true로 프로그램 속성에서 권한을 설정합니다.
이전에는 작동했지만 위성이나 위성 위치를 찾지 못했습니다.
Google지도는 즉시 인공 위성을 찾습니다.
무엇을 변경해야합니까?
무슨 일이야? 오류? 어떤 점이 보입니까? ?? – josedlujan
아무 것도. 위치 아이콘이 나타 났으며 아직 위치를 찾지 못한 것처럼 보였습니다. 그런 다음지도를 열었습니다. 위치가 바로 그곳이었습니다. 따라서 하드웨어 문제는 아닙니다. –
@ P.Dee'compileSdkVersion'과'targetSdkVersion'을 22로 변경 한 다음 그 권한이 문제가된다면 다시 시도하십시오. 'Marshmallow +'장치에서 위치 권한을 요청해야합니다. – DwlRathod