boolean enableAdb = (Settings.Secure.getInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0) > 0);//判斷adb調試模式是否打開 if (enableAdb) { ToastUtil.showShort("adb調試模式已經打開"); } else { startDevelopmentActivity();//跳轉到開發者選項界面 }
/** * 打開開發者模式界面 */ private void startDevelopmentActivity() { try { Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS); startActivity(intent); } catch (Exception e) { try { ComponentName componentName = new ComponentName("com.android.settings", "com.android.settings.DevelopmentSettings"); Intent intent = new Intent(); intent.setComponent(componentName); intent.setAction("android.intent.action.View"); startActivity(intent); } catch (Exception e1) { try { Intent intent = new Intent("com.android.settings.APPLICATION_DEVELOPMENT_SETTINGS");//部分小米手機采用這種方式跳轉 startActivity(intent); } catch (Exception e2) { } } } }