简体   繁体   中英

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.

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.

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.

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.

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:

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

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.

To avoid that, remove the request for ACCESS_FINE_LOCATION from your Manifest. (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.)

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. Eg as in 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;
}

You should really consider using FusedLocationProvider for the watch because watches like the Huawei one get their location from the phone. FusedLocationProvider makes it easy to not worry about where the location is coming from.

I'm using the fine location permission and have no issues with the app not showing up on the Huawei watch play store.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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