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
How to Separate a Country Code from a Phone Number in Android
Adb Is Not Detecting My Android Device on Ubuntu
Android: Open a Pdf from My App Using the Built in Pdf Viewer
Sending Files Using Post With Httpurlconnection
How to Set Button Click Effect in Android
Android.Support.V7.App.Activitycompat Not Found
How to Convert Image to Zpl Code for Printing Using Zebra Printer
How to Emulate Gps Location in the Android Emulator
How to Select a Video from the Gallery and Get It's Real Path
Convert File: Uri to File in Android
Link Should Be Open in Same Web View in Android
Remove Items from Listview With a Custom Adapter
I Get Fragment Not Attached to a Context. What Context Need to Use
App Restarts Rather Than Resumes
How to Prevent User Go Back to Protected Page After Logout