我该如何检查用户设备上是否启用了开发者选项? (不是通过adb通信或调试USB启用,我只需要知道是否已启用开发者选项)。
我尝试了这个解决方案: 如何以编程方式检查应用程序是否处于调试模式? 但它对我不起作用。 提前致谢
我该如何检查用户设备上是否启用了开发者选项? (不是通过adb通信或调试USB启用,我只需要知道是否已启用开发者选项)。
我尝试了这个解决方案: 如何以编程方式检查应用程序是否处于调试模式? 但它对我不起作用。 提前致谢
试试这个:
int adb = Settings.Secure.getInt(this.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0);
Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED
。 - JoGestartActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
- JoGe@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
}
}
@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;
}
我搜索了很多方法,最终找到了一个方法,它在Android Studio中运行良好,在应用程序中也能正常工作,具体如下:
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
Cordova或Ionic解决方案:
https://github.com/Secullum/cordova-plugin-devoptionschecker
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
cordova.plugins.devoptionschecker.check(successCallback, errorCallback);
}
function successCallback(result) {
// json object which returns devOptionsEnabled: true - enabled, false - disabled
console.log(result);
}
function errorCallback(error) {
console.log(error);
}
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;
}