是否可以从Android Wear SDK获取GPS位置?

Bha*_*ath 2 android wear-os

我通过连接我的Samsung GEAR Live Android设备bluetooth.我GPS在Android设备上启用了有效的互联网连接.

现在,我正试图从中获取GPS位置Wearable App.

LocationManager locationManager = (LocationManager) getSystemService(Activity.LOCATION_SERVICE);
            // getting GPS status
            boolean isGPSEnabled = locationManager
                    .isProviderEnabled(LocationManager.GPS_PROVIDER);
            // getting network status
            boolean isNetworkEnabled = locationManager
                    .isProviderEnabled(LocationManager.NETWORK_PROVIDER);
            if (isGPSEnabled == false && isNetworkEnabled == false) {
                location = null;
            } else if (isGPSEnabled) {
                location = locationManager
                        .getLastKnownLocation(LocationManager.GPS_PROVIDER);
            }
            if (isNetworkEnabled && location == null) {
                location = locationManager
                        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

            }
Run Code Online (Sandbox Code Playgroud)

但是,isGPSEnabledisNetworkEnabled两者都返回false.

可能是什么原因?如何获得位置Wearable App

Mac*_*ęga 6

Android Wear是一款普通的Android设备.这些API返回false,因为您的Android Wear设备没有GPS或网络连接.

  1. 您可以实施自己的"GPS提供商",将手机获取的GPS位置发送到您的可穿戴应用.

  2. 您可以使用Google Play服务位置API来获取GPS位置,因为它们已在Wear上自动运行.以下是Google+上发布的帖子:https://plus.google.com/+PaulGoldstein/posts/FhkgND7USgx

要实施Google Play服务,请按照以下教程进行操作:
检索当前位置:
https ://developer.android.com/training/location/retrieve-current.html
接收位置更新:
https ://developer.android.com/training/位置/接收位置updates.html

请注意,它应该与任何位置API的工作,所以你也可以使用像的API ActivityRecognitionApi,GeofencingApi等等
https://developer.android.com/reference/com/google/android/gms/位置/包summary.html