15

How can I check if the user has developer option enabled on its device? (not with adb comunication active, or debug USB active, I need to know only if Developer Option are enabled).

I've tried this solution: How to check programmatically whether app is running in debug mode or not? but it doesn't work for me. Thanks in advance

Community
  • 1
  • 1
  • Please show us what you have tried so far – Abhinav Singh Maurya Jul 23 '15 at 08:22
  • @AbhinavSinghMaurya see modified question –  Jul 23 '15 at 08:24
  • Device developer option enablement vs debug mode (the solution you referenced) are two separate things. Determining whether the developer option is enabled so the production app can kill itself for security, like Fortnight does, is something I do with my game app and would recommend to anyone who doesn't want their intellectual property hacked. – Androidcoder Nov 03 '20 at 14:38

6 Answers6

24

try this:

int adb = Settings.Secure.getInt(this.getContentResolver(),
                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED , 0);
JoGe
  • 872
  • 10
  • 26
  • 1
    For API 16 You can use: `Settings.Secure.DEVELOPMENT_SETTINGS_ENABLED` – JoGe Jul 23 '15 at 08:38
  • For API lower than 16? –  Jul 23 '15 at 10:17
  • I'm not sure whether this is supported in API < 16. Other way is to work with try-catch block and open the preferences page if error occurred. `startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));` – JoGe Jul 23 '15 at 11:46
  • 1
    if it be 1 means that it is ebnabled or there is another value to check – Mahmoud Mabrok Nov 18 '20 at 11:28
4

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

Will Bobo
  • 408
  • 4
  • 11
  • But DEVELOPMENT_SETTINGS_ENABLED was introduced in API 17. How can I check this on previous API level? –  Jul 23 '15 at 08:30
  • 1
    You will find it here below API 17 : http://developer.android.com/reference/android/provider/Settings.Secure.html – Will Bobo Jul 23 '15 at 08:30
3

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
    }
}
android developer
  • 114,585
  • 152
  • 739
  • 1,270
2

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;
        }
Silas S. Brown
  • 1,469
  • 1
  • 17
  • 18
-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;
            }
-1

I had search for so many methods finally i got the method and its is working fine in android studio also in app it is mentioned below

startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
Syscall
  • 19,327
  • 10
  • 37
  • 52
sham
  • 17
  • 2