当我在Android活动中请求位置更新时,自动屏幕旋转将停止在设备中的所有应用中运行。即使在我杀死应用程序,锁定设备和放大器后它也无法正常工作解锁,开关自动旋转关闭&在设置中。事实上,我不知道我需要做些什么来让它再次发挥作用。它只是在一段时间后才开始自行工作。
我发现当我删除命令LocationServices.FusedLocationApi.requestLocationUpdates()
时屏幕旋转正常,当我使用该命令时,屏幕会停止自动旋转。
有人可以解释一下我做错了什么吗?顺便说一句,我正在使用Android Nougat(7.1.1)在Nexus 9上运行我的应用程序
GoogleApiClient m_GoogleApiClient;
LocationRequest m_LocationRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*.....*/
m_GoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
m_LocationRequest = new LocationRequest();
m_LocationRequest.setInterval(10000);
m_LocationRequest.setFastestInterval(5000);
m_LocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}
@Override
public void onConnected(Bundle connectionHint) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
try {
// WHEN I REMOVE FOLLOWING LINE, AUTO-ROTATE WORKS
LocationServices.FusedLocationApi.requestLocationUpdates(m_GoogleApiClient, m_LocationRequest, this);
} catch (Exception e) {
e.printStackTrace(); // NO EXPECTION CAUGTH
}
}
}
@Override
public void onLocationChanged(Location location) {
/*....*/ // THE CODE HERE DOES NOT INFLUENCE THE SCREEN ROTATION ISSE
}
总体而言,获取位置更新的代码运行正常,它只是停止自动旋转的屏幕...