I know there is something for WiFi and Bluetooth by using intent filter -> ACTION_ACL_CONNECTED, ACTION_ACL_DISCONNECT_REQUESTED, and ACTION_ACL_DISCONNECTED...But is there something in general to check if any kind of connected device has been removed. For example: I have connected my Android device to my Mac, now the Smartphone is locked and i remove the connection to my Mac and i can trigger a local push or sound or something in this direction...
Update
Tried the answer from @Rajesh Gopu which looks good but unfortunately didn´t work :(
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
registerReceiver(mUsbReceiver, filter); //register
Toast.makeText(getApplicationContext(), "ON CREATE", Toast.LENGTH_LONG).show();
}
// BroadcastReceiver when insert/remove the device USB plug into/from a USB port
BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {//get Event
Toast.makeText(getApplicationContext(), "ON RECEIVE", Toast.LENGTH_LONG).show();
String action = intent.getAction();
System.out.println("BroadcastReceiver Event");
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
Toast.makeText(getApplicationContext(), "CONNECTED", Toast.LENGTH_LONG).show();
System.out.println("BroadcastReceiver USB Connected");
} else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
Toast.makeText(getApplicationContext(), "DISCONNECTED", Toast.LENGTH_LONG).show();
System.out.println("BroadcastReceiver USB Disconnected");
}
}
};
}