我正在构建react native应用程序,我想检测用户是否开启了开发者选项。在MainActivity.java文件中,我总是收到SettingNotFoundException异常。
import android.provider.Settings.Secure;
import android.provider.Settings.Global;
import android.provider.Settings.SettingNotFoundException;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
int devOptions = Secure.getInt(this.getContentResolver(), Global.DEVELOPMENT_SETTINGS_ENABLED);
}catch (SettingNotFoundException e){
Log.d(getClass().getName(), "Called");
}
}
使用这个代码
try {
int devOptions = Settings.Secure.getInt(this.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED);
Log.d("DevOptions","Got Devoptions : "+devOptions);
} catch (Settings.SettingNotFoundException e){
Log.d(getClass().getName(), "Called");
}
并使用这个导入语句
import android.provider.Settings;