我使用isFromMockProvider来防止模拟位置。我可以构建我的应用程序而不会出现任何错误。但是,当我在手机上安装应用程序时(第9类Android)。我的应用程序崩溃并停止运行。在具有较低版本android的设备中可以。 我是否错过了应用程序配置中的某些内容?我该如何解决该问题? 我的代码:
public boolean isMockSettingsON() {
// returns true if mock location enabled, false if not enabled.
boolean isMock = false;
if (android.os.Build.VERSION.SDK_INT >= 18) {
isMock = location.isFromMockProvider();
} else {
isMock = !Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
}
return isMock;
}
和我的build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "x"
minSdkVersion 11
targetSdkVersion 26
versionCode 1
versionName "3.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:support-v4:23.1.0'
implementation 'com.android.support:appcompat-v7:23.1.0'
implementation 'com.orhanobut:wasp:1.13'
implementation 'com.fasterxml.jackson.core:jackson-core:2.6.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.6.3'
implementation 'de.greenrobot:greendao:2.1.0'
}