android - 如何在没有用户关注的情况下在 Android M 中启用 Android 权限

标签 android android-6.0-marshmallow

我正在用 L 代码库构建 apk,这个应用程序使用 android.permission.READ_PHONE_STATE,它在 M 设备上也能正常工作。

但是当我使用相同的权限构建相同的应用程序时,android M 会提示用户关注,有没有办法在没有用户关注的情况下启用这些权限。

我的应用是系统应用。

最佳答案

如果您想使用 Android API 23 的任何新功能,这是不可能的。

Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app. This approach streamlines the app install process, since the user does not need to grant permissions when they install or update the app. It also gives the user more control over the app's functionality; for example, a user could choose to give a camera app access to the camera but not to the device location. The user can revoke the permissions at any time, by going to the app's Settings screen.

在其他情况下,您可以将 Android API 降级到 22,但不推荐...

你应该把你的 build.gradle 改成这样:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "your.app.id"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
}

像这样:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "you.app.id"
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:design:22.2.0'
}

请记住只编译 android 库版本 22 或更低版本的依赖项,例如 'com.android.support:design:22.2.0'

关于android - 如何在没有用户关注的情况下在 Android M 中启用 Android 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36354263/

相关文章:

java - 为什么一个半透明的 Activity 显示另一个非半透明的 Activity ?

android - 在 Android 中获取当前活跃用户

android - 如何在安卓分享界面添加PhoneGap应用

Android M 权限永远不想显示带有复选框的选项 "Never ask again"

Android 在运行时抛出异常时询问权限

android - 如何清除 Android Marshmallow 中的所有应用缓存数据

android - 在 openSUSE 13.2 中运行的 Android Studio Workspace 中的设备权限不足

android - API 24 AccessibilityService.dispatchGesture() 方法如何工作?

fingerprint - 为多个用户使用来自 Android 的新指纹 API

android - 在 Android M 开发者预览版中找不到 PackageInstallerActivity