我正在使用Android Studio 2.1.1。
从API 22升级到API 23之前有效的基本功能不再起作用。
2个例子:
1)获取返回API 22中指定路径中所有文件和文件夹的文件列表,现在在API 23中文件为空:
File f = new File(dirPath);
File[] files = f.listFiles();
2)从设备返回帐户返回API 22中的所有电子邮件帐户,现在在API 23 帐户中为空:
Pattern emailPattern = Patterns.EMAIL_ADDRESS;
accounts = AccountManager.get(this).getAccounts();
其他例子不能简单描述,所以我希望只给出两个例子就足够了。
我的API 22的gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
compileOptions.encoding = 'windows-1251'
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
defaultConfig {
applicationId "com.soft.StudyNJoy"
minSdkVersion 14
targetSdkVersion 22
multiDexEnabled true
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard-android.txt', 'proguard-project.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.guava:guava:18.0'
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/commons-codec.jar')
compile files('libs/commons-io-2.4.jar')
compile files('libs/commons-net-3.3.jar')
compile files('libs/dropbox-android-sdk-1.6.jar')
compile files('libs/httpmime-4.0.3.jar')
compile files('libs/iSpeech-SDK-1.4.2.jar')
compile files('libs/json_simple-1.1.jar')
compile files('libs/PayPal_MPL.jar')
compile files('libs/sqlcipher.jar')
}
升级到API 23后的gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.3'
compileOptions.encoding = 'windows-1251'
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
defaultConfig {
applicationId "com.soft.StudyNJoy"
minSdkVersion 14
targetSdkVersion 23
multiDexEnabled true
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles 'proguard-android.txt', 'proguard-project.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:cardview-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.google.guava:guava:18.0'
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/commons-codec.jar')
compile files('libs/commons-io-2.4.jar')
compile files('libs/commons-net-3.3.jar')
compile files('libs/dropbox-android-sdk-1.6.jar')
compile files('libs/httpmime-4.0.3.jar')
compile files('libs/iSpeech-SDK-1.4.2.jar')
compile files('libs/json_simple-1.1.jar')
compile files('libs/PayPal_MPL.jar')
compile files('libs/sqlcipher.jar')
}
所有必要的权限都在清单文件中 - 从API 22升级到API 23期间没有任何变化。
有谁知道什么可能是错的?
在此先感谢,亲切的问候
格哈德
答案 0 :(得分:0)
In API 23 there is two kind of permissions, normal - that will be granted automatically if you add it to manifest, and dangerous - that should be granted by user via UI. ACCOUNT_MANAGER - is second kind of permissions. You need to request the permission method in this case first - https://developer.android.com/training/permissions/requesting.html
答案 1 :(得分:0)
You have to get Runtime permission for API 23.