简体   繁体   English

Android Wear 2.0通过手机获取位置,并在Google Play商店中支持设备支持

[英]Android Wear 2.0 getting location from phone and keeping device supported on Google Play store

Recently I've been making a Bus Checker app for Android Wear 2.0, as a standalone app so that iOS users can also use it. 最近我一直在为Android Wear 2.0制作一个Bus Checker应用程序作为一个独立的应用程序,以便iOS用户也可以使用它。

I am obviously getting the location of the watch to get the local bus stops. 我显然得到了手表的位置,以获得当地的巴士站。 This means I need to use the following permissions: 这意味着我需要使用以下权限:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Even though my Huawei Watch can get the location of the "watch" through the phone, when publishing the app to the Google Play store, it only becomes supported with the one device that supports GPS: the LG Watch Urbane 2nd Edition LTE. 即使我的华为手表可以通过手机获取“手表”的位置,但在将应用程序发布到Google Play商店时,只有支持GPS的设备支持它:LG Watch Urbane 2nd Edition LTE。

I really don't know what to do here, I want to publish my app for devices that don't have GPS and just get GPS from the phone, but to get GPS from the phone I need those permissions and those permissions cause the Huawei Watch and other non-GPS devices to become unsupported. 我真的不知道该怎么做,我想发布我的应用程序没有GPS的设备,只是从手机上获取GPS,但要通过手机获取GPS,我需要这些权限,这些权限导致华为观看和其他非GPS设备不受支持。

I have tried adding this to my manifest to test whether the Huawei Watch would become supported: 我已经尝试将此添加到我的清单中以测试华为手表是否会得到支持:

<uses-feature android:name="android.hardware.LOCATION" android:required="false" />
<uses-feature android:name="android.hardware.location.GPS" android:required="false" />
<uses-feature android:name="android.hardware.location.NETWORK" android:required="false" />

But unfortunately, it didn't work. 但不幸的是,它没有用。 The compatibility is definitely based on the permissions and not the features required. 兼容性绝对基于权限,而不是所需的功能。 I also tried this with a blank Hello World app to no avail. 我也尝试使用空白的Hello World应用程序无效。

If it is of any relevance, here is my app manifest: 如果它有任何相关性,这是我的应用程序清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.buschecker.williamvenner.buschecker">

    <uses-feature android:name="android.hardware.type.watch" android:required="true" />

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name" android:supportsRtl="true"
        android:theme="@android:style/Theme.DeviceDefault">
        <uses-library android:name="com.google.android.wearable" android:required="false" />

        <activity android:name=".MainActivity" android:label="@string/app_name"
            android:theme="@android:style/Theme.DeviceDefault.Light">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".BusStopView"
            android:theme="@android:style/Theme.DeviceDefault.Light">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

My Gradle: 我的Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.buschecker.williamvenner.buschecker"
        minSdkVersion 25
        targetSdkVersion 25
        versionCode 1
        versionName "1"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.support:wearable:2.0.0-beta2'
    compile 'com.google.android.gms:play-services-wearable:10.0.1'
    compile 'com.google.android.gms:play-services-location:10.0.1'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    provided 'com.google.android.wearable:wearable:2.0.0-beta2'
    wearApp project(':app')
}

My project structure can be found here . 我的项目结构可以在这里找到。

Some permissions imply feature requirements. 某些权限意味着功能要求。

The explicitly in the Manifest declaredared permission requirement ACCESS_FINE_LOCATION in the implies the requirement of android.hardware.location.gps 明确在Manifest声明的权限要求ACCESS_FINE_LOCATION中隐含了android.hardware.location.gps的要求

See Permissions that Imply Feature Requirements 请参阅暗示功能要求的权限

So declaring the feature as not required 因此声明该功能不是必需的

<uses-feature android:name="android.hardware.location.gps" android:required="false" />

will not apply and not prevent the Play Store from filtering your app out for GPS-less devices. 不适用,也不会阻止Play商店针对无GPS设备过滤您的应用。

To avoid that, remove the request for ACCESS_FINE_LOCATION from your Manifest. 为避免这种情况,请从Manifest中删除ACCESS_FINE_LOCATION请求。 (But declare the feature requests for anroid.hardware.location and android.hardware.location.network as required to ensure the play store keeps filtering out the app for devices without any network hardware.) (但是根据需要声明anroid.hardware.location和android.hardware.location.network的功能请求,以确保Play商店不再为没有任何网络硬件的设备过滤掉应用程序。)

And to ensure, your app can use GPS services on devices equipped with it, implement in your code a check, whether LocationManager.GPS_PROVIDER is included in the list of all availible providers. 为了确保您的应用可以在配备它的设备上使用GPS服务,请在您的代码中执行检查,以确定LocationManager.GPS_PROVIDER是否包含在所有可用提供商的列表中。 Eg as in GPS Manifest: GPS in App is optional, want to make it available to GPS less devices too : 例如,在GPS Manifest中:应用程序中的GPS是可选的,希望它也可用于GPS较少的设备

locationManager = (LocationManager)
this.getSystemService(Context.LOCATION_SERVICE);
boolean deviceHasGPS = false;
if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) {
    deviceHasGPS = true;
}

You should really consider using FusedLocationProvider for the watch because watches like the Huawei one get their location from the phone. 您应该考虑使用FusedLocationProvider作为手表,因为像华为这样的手表可以通过手机获取它们的位置。 FusedLocationProvider makes it easy to not worry about where the location is coming from. FusedLocationProvider可以轻松地不用担心位置的来源。

I'm using the fine location permission and have no issues with the app not showing up on the Huawei watch play store. 我正在使用精确的位置许可,并且没有问题,应用程序没有出现在华为手表游戏商店。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM