Android - How to check if Developer option is enabled

15,602

Solution 1

try this:

int adb = Settings.Secure.getInt(this.getContentResolver(),
                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0);

Solution 2

You should use getInt or another in Settings.Global with DEVELOPMENT_SETTINGS_ENABLED

Edit : Below API 17, it is the same but with Settings.Secure

Solution 3

Here's a method that returns true if developer mode is enabled for all devices at Android 4.1 or above (API 16), returns false if developer mode is not enabled on such devices, and returns false on all earlier Android devices down to 1.0.

        @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;
        }

Solution 4

Kotlin solution:

@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
    }
}

Solution 5

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;
            }
Share:
15,602
Admin
Author by

Admin

Updated on June 05, 2022

Comments