난 정말 이해가 안 감사드립니다. 코드의 다음 조각에서 usbCharge는 간단한 충전기에서 거짓이고 컴퓨터에서 어디서 사실입니다.
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);
}
}