Android Wear 2.0 从手机获取位置并保持设备在 Google Play 商店中的支持

标签 android google-play wear-os android-wear-2.0

最近我一直在为 Android Wear 2.0 制作一个 Bus Checker 应用程序,作为一个独立的应用程序,以便 iOS 用户也可以使用它。

我显然正在获取 watch 的位置以获取本地的巴士站。这意味着我需要使用以下权限:

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

尽管我的华为 watch 可以通过手机获取“ watch ”的位置,但在将应用程序发布到 Google Play 商店时,它只支持一款支持 GPS 的设备:LG Watch Urbane 2nd Edition LTE。

我真的不知道在这里做什么,我想为没有 GPS 的设备发布我的应用程序,只从手机获取 GPS,但是要从手机获取 GPS,我需要这些权限,而这些权限会导致华为 watch 和其他非 GPS 设备将不受支持。

我尝试将其添加到我的 list 中以测试是否支持华为 watch :
<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" />

但不幸的是,它没有用。兼容性绝对基于权限,而不是所需的功能。我也尝试了一个空白的 Hello World 应用程序,但无济于事。

如果有任何相关性,这是我的应用 list :
<?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>

我的 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')
}

我的项目结构可以找到here .

最佳答案

某些权限意味着功能要求。

Manifest 中明确声明的权限要求 ACCESS_FINE_LOCATION 暗示了 android.hardware.location.gps 的要求

Permissions that Imply Feature Requirements

所以声明该功能不需要

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

将不适用,也不会阻止 Play 商店为无 GPS 设备过滤您的应用。

为避免这种情况,请从您的 list 中删除对 ACCESS_FINE_LOCATION 的请求。
(但是根据需要声明对 anroid.hardware.location 和 android.hardware.location.network 的功能请求,以确保 Play 商店不断过滤掉没有任何网络硬件的设备的应用程序。)

为了确保您的应用程序可以在配备它的设备上使用 GPS 服务,请在您的代码中检查 LocationManager.GPS_PROVIDER 是否包含在所有可用提供程序的列表中。
例如。如 GPS Manifest: GPS in App is optional, want to make it available to GPS less devices too :
locationManager = (LocationManager)
this.getSystemService(Context.LOCATION_SERVICE);
boolean deviceHasGPS = false;
if (locationManager.getAllProviders().contains(LocationManager.GPS_PROVIDER)) {
    deviceHasGPS = true;
}

关于Android Wear 2.0 从手机获取位置并保持设备在 Google Play 商店中的支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41917425/

相关文章:

android - 如何使用 Eclipse 构建和运行 cordova 项目以及运行 android 项目

java - Google 回合制匹配自定义匹配 UI

代表另一家公司在 Google Play 商店上发布应用

android - 打开带有 Google Play 商店链接的 Android 应用

android - 从 URL 打开 PDF

android - 是什么决定了 Google Play 将向哪些设备提供应用程序?

java - Android Wear 消息监听器

android - 是否可以在我的应用程序中从 Androidwatch 获取心率更新?

android - 具有配置的资源 attr/textSize 的重复值

java - 使用httpclient时抛出OutOfMemoryError