Android開發:設置USB tethering 和USB debugging

設置 USB tethering

  1.  public void setUSBTethering(boolean enabled){  
  2.          
  3.     ConnectivityManager cm =  
  4.             (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);  
  5.         if (cm.setUsbTethering(enabled) != ConnectivityManager.TETHER_ERROR_NO_ERROR ){  
  6.                 
  7.               System. out.println("usb tethering set failed !" );  
  8.         }  
 
設置 USB debugging
  1. public void enableUSBDebugging()  
  2.  
  3.        int adbEnabled=0;  
  4.         
  5.        try {  
  6.              adbEnabled = Settings.Secure. getInt(getContentResolver(), Settings.Secure.ADB_ENABLED );  
  7.       } catch (SettingNotFoundException e) {  
  8.              e.printStackTrace();  
  9.       }  
  10.         
  11.        if(adbEnabled != 1){  
  12.              Settings.Secure. putInt(getContentResolver(),Settings.Secure. ADB_ENABLED, 1);  
  13.       }  
  14.         
  15.  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章