我需要在我的 Android 应用程序中设置 gps。但是函数 requestLocationUpdates 需要以这种方式检查权限:
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
如果我删除返回(从如果)应用程序崩溃。如果我把返回函数 requestLocationUpdates 将不会被调用!
怎么修?