如何检查用户是否在其设备上启用了开发者选项? (没有adb通信激活,或调试USB激活,我只需要知道开发人员选项是否已启用)。
我尝试过这个解决方案: How to check programmatically whether app is running in debug mode or not? 但它对我不起作用。 提前致谢
答案 0 :(得分:6)
试试这个:
int adb = Settings.Secure.getInt(this.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0);
答案 1 :(得分:2)
你应该使用 在Settings.Global中getInt或其他 同 DEVELOPMENT_SETTINGS_ENABLED
编辑: 在API 17下面,它与Settings.Secure
相同答案 2 :(得分:1)
如果为Android 4.1或更高版本(API 16)的所有设备启用了开发人员模式,则返回true,如果未在此类设备上启用开发人员模式,则返回false,并在所有早期Android设备上返回false
@android.annotation.TargetApi(17) public boolean isDevMode() {
if(Integer.valueOf(android.os.Build.VERSION.SDK) == 16) {
return android.provider.Settings.Secure.getInt(getApplicationContext().getContentResolver(),
android.provider.Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED , 0) != 0;
} else if (Integer.valueOf(android.os.Build.VERSION.SDK) >= 17) {
return android.provider.Settings.Secure.getInt(getApplicationContext().getContentResolver(),
android.provider.Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0) != 0;
} else return false;
}
答案 3 :(得分:1)
It's Simple to Find -- Developer Mode is On or Not!!!
Java solution:
if (PreferenceHelper.isDevMode(context)) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("Please Turn Off Developer Option \n" +
" \n" +
" Go to Settings > Search developer options and toggle them off.");
builder.setCancelable(false);
builder.setNegativeButton(" Ok ", (dialog, which) -> {
dialog.dismiss();
finish();
});
builder.setPositiveButton(" Turn Off ", (dialog, which) -> {
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
alertDialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE).setTextColor(Color.parseColor("#37367C"));
return;
}
答案 4 :(得分:0)
Kotlin 解决方案:
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
fun isDevMode(context: Context): Boolean {
return when {
Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN -> {
Settings.Secure.getInt(context.contentResolver,
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0
}
Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN -> {
@Suppress("DEPRECATION")
Settings.Secure.getInt(context.contentResolver,
Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0
}
else -> false
}
}