I want to detect wheather my android phone is connected via USB or not...for this i′m using this code:
public static boolean isConnected(Context context) {
intent = context.registerReceiver(null, new IntentFilter("android.hardware.usb.action.USB_STATE"));
return intent.getExtras().getBoolean("connected");
}
But is there a possibility to explicit know if i am connected to a PC?! Because the Solution i have fires the Event even i connect my phone to a printer or sth else with an USB Port...
I already tried the Solution @nios just posted, but if isCharging and usbCharge booleans are set to true, it′s not guaranted that your are connected to a PC...Even if you are connected to a Printer both booleans will bet set to true...Thats my Problem
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…