在Amazon Fire TV Stick中获取设备位置

时间:2018-05-10 11:55:26

标签: android-location wifimanager amazon-fire-tv

开发Fire TV Stick应用程序与Android TV和Box类似,但有一些不同的方法可以访问设备的不同功能。

现在我正在尝试使用Wifi位置管理器获取设备(亚马逊消防电视棒)位置,但位置返回null,如下面的代码所示。

私人LocationManager locationManager;

@SuppressLint("MissingPermission")
private Location getWifiLocation() {
    // SETUP Location Manager
    locationManager = (LocationManager) getApplicationContext()
            .getSystemService(Context.LOCATION_SERVICE);
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (locationManager != null) {
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, myLocationListener);
    }
    Location location = null;
    if (locationManager != null) {
        location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    }
    return location;
}

private LocationListener myLocationListener
        = new LocationListener() {

    @Override
    public void onLocationChanged(Location location) {
        if (location != null) {
            double latitude = location.getLatitude();
            double longitude = location.getLongitude();

        }
    }

感谢您的时间。

0 个答案:

没有答案