GoogleApiClient 不适用于电视应用程序
GoogleApiClient is not working for TV application
使用 GoogleApiClient 我可以通过这种方式获取位置:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
@Override
public void onConnected(Bundle connectionHint) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
mLatitudeText = String.valueOf(mLastLocation.getLatitude());
Log.d("the lat is",mLatitudeText);
mLongitudeText = String.valueOf(mLastLocation.getLongitude());
Log.d("the lon is",mLongitudeText);
}
}
但这不适用于 android TV 应用程序。 onConnected
和 onConnectionFailed
都没有被调用。我也没有找到任何文档。
关于 handling TV hardware 的 Android 开发者文档指出:
TVs have a different purpose from other devices, and so they do not have hardware features that other Android-powered devices often have. For this reason, the Android system does not support the following features for a TV device:
GPS - android.hardware.location.gps
这可能会误导你。
文档提供了一些解决方案提示:
TVs are stationary, indoor devices, and do not have built-in global positioning system (GPS) receivers. If your app uses location information, you can still allow users to search for a location, or use a static location provider such as a zip code configured during the TV device setup.
使用 GoogleApiClient 我可以通过这种方式获取位置:
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
@Override
public void onConnected(Bundle connectionHint) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
mLatitudeText = String.valueOf(mLastLocation.getLatitude());
Log.d("the lat is",mLatitudeText);
mLongitudeText = String.valueOf(mLastLocation.getLongitude());
Log.d("the lon is",mLongitudeText);
}
}
但这不适用于 android TV 应用程序。 onConnected
和 onConnectionFailed
都没有被调用。我也没有找到任何文档。
关于 handling TV hardware 的 Android 开发者文档指出:
TVs have a different purpose from other devices, and so they do not have hardware features that other Android-powered devices often have. For this reason, the Android system does not support the following features for a TV device:
GPS - android.hardware.location.gps
这可能会误导你。
文档提供了一些解决方案提示:
TVs are stationary, indoor devices, and do not have built-in global positioning system (GPS) receivers. If your app uses location information, you can still allow users to search for a location, or use a static location provider such as a zip code configured during the TV device setup.