I don't really understand why but checking the charge state seems to do the job. In the following piece of code usbCharge is false when on simple charger and true where on a computer.
public void onReceive(final Context context, Intent intent) {
IntentFilter extraFilterToGetBatteryInfo = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent extraIntentToGetBatteryInfo = context.getApplicationContext().registerReceiver(null, extraFilterToGetBatteryInfo);
int chargePlug = extraIntentToGetBatteryInfo.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
if (usbCharge) {
// Enable tethering
Intent tetherSettings = new Intent();
tetherSettings.setClassName("com.android.settings", "com.android.settings.TetherSettings");
tetherSettings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(tetherSettings);
}
}