使用 Android Studio 在 App 中设置 Android Wear 权限

Setting Android Wear permissions in App with Android Studio

全部:

我收到了我写的 Android 表盘的 Android 隐私政策通知之一。我在 Android Studio 中编写的,它具有以下权限:

android.permission.ACCESS_NETWORK_STATE
android.permission.GET_ACCOUNTS
android.permission.INTERNET
android.permission.READ_EXTERNAL_STORAGE
android.permission.USE_CREDENTIALS
android.permission.WAKE_LOCK
android.permission.WRITE_EXTERNAL_STORAGE
com.google.android.c2dm.permission.RECEIVE

我真的不需要所有这些。我真的认为我只需要 WAKE_LOCK 并且我认为还有一个。它不应该使用任何类型的书写、访问网络或任何其他内容。

但奇怪的是,我在我的应用程序中找不到这些权限所在的任何位置。这是我的 Wear 清单:

<?xml version="1.0" encoding="utf-8"?>

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

<!-- Required to act as a custom watch face. -->
<uses-permission android:name="com.google.android.permission.PROVIDE_BACKGROUND" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.DeviceDefault" >
    <service
        android:name=".MorseWatchFace"
        android:label="@string/my_digital_name"
        android:permission="android.permission.BIND_WALLPAPER" >
        <meta-data
            android:name="android.service.wallpaper"
            android:resource="@xml/watch_face" />
        <meta-data
            android:name="com.google.android.wearable.watchface.preview"
            android:resource="@drawable/preview_digital" />
        <meta-data
            android:name="com.google.android.wearable.watchface.preview_circular"
            android:resource="@drawable/preview_digital_circular" />

        <intent-filter>
            <action android:name="android.service.wallpaper.WallpaperService" />

            <category android:name="com.google.android.wearable.watchface.category.WATCH_FACE" />
        </intent-filter>
    </service>

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

这是我的手机清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="monte.morsewatch">

<application android:allowBackup="true" android:label="@string/app_name"
    android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">

</application>

我知道我错过了什么。电子邮件说我必须在 1 月 30 日之前修复它,但我不确定我需要更改什么才能修复它。

非常感谢任何帮助。

基于此 documentation, the user must now grant permissions to Wear apps separately from the handset versions of the apps. Previously, when a user installed a Wear app, it automatically inherited the set of permissions that the user had granted to the handset version of the app. To declare that your app needs a permission, you're right in putting a <uses-permission> element in your app manifest, as a child of the top-level <manifest> 元素。

也可能有助于了解如何在您的应用中删除不需要的权限。

The extra permissions are probably being added by some part of Google Play Services - and which probably doesn't need them for what you're doing.

Solution #1 is to only use the pieces of Google Play Services that you actually need. In your Wear module's build.gradle file, you might have an entry that looks like this:

dependencies {
    compile com.google.android.gms:play-service:8.4.0
}

However, that will bring in the entire Play Services library - which requires a number of extra permissions. It might well be that all you need is this:

    compile com.google.android.gms:play-services-wearable:8.4.0

...or perhaps other specific modules. But the point is, don't include more than you need.

If you've pared the dependencies back as far as you can, and you're still getting extra permissions in your merged manifest, then you may need Solution #2 - which I described in detail in a different answer:

希望对您有所帮助!