Android - How to Check If Developer Option Is Enabled

Foolproof way to detect if developer options are enabled?

You can't do it any more foolproof than Android itself does it:

 public static boolean isDevelopmentSettingsEnabled(Context context) {
final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
final boolean settingEnabled = Settings.Global.getInt(context.getContentResolver(),
Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,
Build.TYPE.equals("eng") ? 1 : 0) != 0;
final boolean hasRestriction = um.hasUserRestriction(
UserManager.DISALLOW_DEBUGGING_FEATURES);
final boolean isAdmin = um.isAdminUser();
return isAdmin && !hasRestriction && settingEnabled;
}

Your code was close, but didn't account for
Build.TYPE.equals("eng") ? 1 : 0)

How to detect if developer settings are enabled on the device?

Try this

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

if developer options are enabled the value will be 1, otherwise it will be 0

Check if developer mode is enabled in a native Android module

An instance of ReactInstanceManager can be obtained by the package if it inherits from ReactInstancePackage:

public class MyPackage extends ReactInstancePackage {

@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext, ReactInstanceManager reactInstanceManager) {
// store the provided instance of ReactInstanceManager
this.reactInstanceManager = reactInstanceManager;

// ...
}
//...
}

This instance can be used later to check whether the dev mode is enabled:

boolean devModeIsEnabled = this.reactInstanceManager
.getDevSupportManager()
.getDevSupportEnabled();

Android - Detect when developer option or USB debugging mode is being turned on

Since there's no way for an unrooted device to turn the debugging mode on from background while other application is running on the front including by user action for example by clicking on a toggle button on the notification bar, I can just do the checking on the application resume without using any timer



Related Topics



Leave a reply



Submit