Register the application to start when connecting a USB device to a PC

I created an Android application that I would like to open automatically when a USB device running Android is connected to a PC.

Is it possible to register my application for working with a USB connection? How to do it?

+5
source share
3 answers

You can listen Intent.ACTION_UMS_CONNECTED(usb mass loading mode is running) or Intent.ACTION_POWER_CONNECTED(the phone is now charging) with BroadcastReceiver.

, , . . USB - , - , . , .

, , , ( , ). , , , .

+4

Manifest.xml :

<receiver android:name=".BattStatusShow">
    <intent-filter>
        <action android:name="android.intent.action.ums_connected" />
    </intent-filter>
</receiver>

BroadcastReceiver, USB .

public class BattStatusShow extends BroadcastReceiver{ 
  if (intent.getAction().equalsIgnoreCase( "android.intent.action.UMS_CONNECTED")) {
    //do stuff here, like signal the view of your app it needs to do something
  }
}

, , , Android- . , , Nokia PC Station Nokia .

+4

All Articles