USB recovery on application launch

I am new to android. I am trying to detect a usb attached to an android device. When USB is connected for the first time, specialiec app opens (works fine).

Now what I'm trying to do is if the app is already open and the USB device is plugged in, it should give me a toast that "device is plugged in".

Can anyone please help how to do this. I tried using onNewIntetnt () to check the returned intent, but still don't get toasts. Help plz

protected void onNewIntent(Intent intent) {
        // TODO Auto-generated method stub
        super.onNewIntent(intent);
        if (intent.getAction().equals(DongleManager.ACTION_USB_DEVICE_ATTACHED)) {
            Slog.d(TAG, "USB ATTACHED");
            Toast.makeText(this, "USB ATTACHED", Toast.LENGTH_SHORT).show();
        }

    }

      

+3


source to share





All Articles