10

如何检查用户是否在其设备上启用了开发者选项?(没有激活 adb 通信或调试 USB 激活,我只需要知道是否启用了开发人员选项)。

我试过这个解决方案: 如何以编程方式检查应用程序是否在调试模式下运行? 但这对我不起作用。提前致谢

4

6 回答 6

16

尝试这个:

int adb = Settings.Secure.getInt(this.getContentResolver(),
                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0);
于 2015-07-23T08:31:31.337 回答
3

您应该在 Settings.Global 中使用 getInt或其他 DEVELOPMENT_SETTINGS_ENABLED

编辑:在 API 17 下,它是相同的,但使用Settings.Secure

于 2015-07-23T08:27:40.963 回答
2

如果为 Android 4.1 或更高版本 (API 16) 的所有设备启用开发人员模式,则返回 true 的方法,如果未在此类设备上启用开发人员模式,则返回 false ,并在所有早期 Android 设备(低至 1.0)上返回 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;
        }
于 2018-04-01T21:45:16.540 回答
1

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
    }
}
于 2021-06-15T21:41:03.250 回答
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;
            }
于 2021-07-12T08:31:54.277 回答
0

Cordova 或离子溶液:

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);
}
于 2021-11-09T11:56:22.240 回答