我正在用 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/