poiché questa è una delle pagine più popolari nei risultati di Google per questo argomento. Vorrei contribuire con il mio codice che controlla le interfacce disponibili. Funziona con un telefono Gingerbread che ho, ma non con il mio Galaxy S3.
// DETECT INTERFACE NAME
Log.i("UsbTethering","Detecting tetherable usb interface.");
String[] available = null;
ConnectivityManager connMgr = (ConnectivityManager)connectivityServiceObject;
Method[] wmMethods = connMgr.getClass().getDeclaredMethods();
for(Method getMethod: wmMethods)
{
if(getMethod.getName().equals("getTetherableUsbRegexs"))
{
try
{
available = (String[]) getMethod.invoke(connMgr);
break;
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
// DETECT INTERFACE NAME
if(available.length > 0)
{
for(String interfaceName : available)
{
Log.i("UsbTethering", "Detected " + String.valueOf(available.length) + " tetherable usb interfaces.");
Log.i("UsbTethering", "Trying to " + desiredString + " UsbTethering on interface " + interfaceName + "...");
Integer returnCode = (Integer)method.invoke(connectivityServiceObject, interfaceName);
if(returnCode == 0)
{
Log.i("UsbTethering", "UsbTethering " + desiredString + "d.");
return true;
}
else
{
Log.w("UsbTethering", "Failed to " + desiredString + "Usb Tethering. ReturnCode of method " + method.getName() + ": " + String.valueOf(returnCode));
}
}
}
"La risposta è sempre la stessa, le normali applicazioni non possono farlo, solo le app di sistema." - Più precisamente, non c'è nulla nell'SDK Android per gestire il tethering USB. – CommonsWare
Sì, quindi come ha fatto l'app a riuscirci? Potrebbe non essere nell'SDK ma è certamente possibile! Era un trucco sporco? Un exploit? Forse è stato riparato in 4.0? –