Usb Connection Notification

USB Connection notification

Ajay,

I wasn't able to find anything specific to just "USB Connected," but there are a few Broadcast Actions that may be of interest in this case depending on what you are trying to accomplish:

  • ACTION_MEDIA_SHARED: External media is unmounted because it is being shared via USB mass storage.
  • ACTION_UMS_CONNECTED: The device has entered USB Mass Storage mode. This is used mainly for the USB Settings panel.
  • ACTION_UMS_DISCONNECTED: The device has exited USB Mass Storage mode. This is used mainly for the USB Settings panel.

There doesn't seem to be a Broadcast Action specific to USB simply being plugged in, you could also try doing something with:

  • ACTION_POWER_CONNECTED: External power has been connected to the device.

But this would go off for both USB connected to a computer and USB connect ONLY to a power source...

Interestingly, I also found this LINK simply stating that there was no Broadcast Action for "USB Connected".

You may be out of luck in this case :-\

Get notification when a new drive is connected via USB or other means (C#)

A windows service should do the trick

Try reworking the CodeProject DriveDetector as a service and you should have what you need

Get Broadcast when USB cable is connected

Add this to your manifest

<receiver android:name=".YourReceiverClassName">
<intent-filter>
<action android:name="android.intent.action.UMS_CONNECTED" />
<action android:name="android.intent.action.UMS_DISCONNECTED" />
</intent-filter>
</receiver>

Modify you onReceive inside yourReceiverClassName to this

public void onReceive(Context context, Intent intent) {

if (intent.getAction().equalsIgnoreCase( "android.intent.action.UMS_CONNECTED"))
{
Log.d(TAG,"USB connected..");
}

if (intent.getAction().equalsIgnoreCase( "android.intent.action.UMS_DISCONNECTED"))
{
Log.d(TAG,"USB connected..");
}

}



Related Topics



Leave a reply



Submit