How to access device settings programmatically?

前端 未结 6 1689
礼貌的吻别
礼貌的吻别 2020-12-05 05:59

Is there any way to access device settings programmatically?

For Example: Settings > Developer Options > USB debugging > True/False

Thanks in advance.

<
6条回答
  •  孤街浪徒
    2020-12-05 06:29

    Try as:

     int adb = Settings.Secure.getInt(context.getContentResolver(),
      Settings.Secure.ADB_ENABLED, 0);
     // toggle the USB debugging setting
     adb = adb == 0 ? 1 : 0;
     Settings.Secure.putInt(context.getContentResolver(), 
    Settings.Secure.ADB_ENABLED, adb);
    

    In AndroidManifest.xml:

    
    
    

    and finally look at this example

    http://code.google.com/p/secure-settings-widget/source/browse/src/com/lieryan/adbwidget/ADBAppWidgetProvider.java?r=eb23b2d6989ccade05f095806db5888f1ba62737

提交回复
热议问题