Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid USB Host mode service - Start based on USB_DEVICE_ATTACHED
    primarykey
    data
    text
    <p>I want to write a service in Android which starts based on USB_DEVICE_ATTACHED intent. So, basically my service should start when a specific USB Device(FT232C - VID:PID 0403:6010) is connected and stop when that USB device is detached. Is it possible to do that or should I always have an Activity which starts this service in case it is not already started? The intent of the service in the end is to update the location on the LocationProvider with a TEST_PROVIDER based on what location is provided from this USB device.</p> <p>I already tried creating a service with this configuration in AndroidManifest.xml</p> <pre><code> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.testlocservice" android:versionCode="1" android:versionName="1.0"&gt; &lt;uses-sdk android:minSdkVersion="12" android:targetSdkVersion="15" /&gt; &lt;uses-feature android:name="android.hardware.usb.host"/&gt; &lt;supports-screens android:resizeable="true" android:smallScreens="true" android:anyDensity="true" android:largeScreens="true" android:xlargeScreens="true" android:normalScreens="true"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE"/&gt; &lt;application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:theme="@style/AppTheme"&gt; &lt;service android:name="com.testlocservice.LocationService" android:process=":LocService" android:enabled="true" android:exported="true"&gt; &lt;intent-filter&gt; &lt;action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /&gt; &lt;/intent-filter&gt; &lt;meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" /&gt; &lt;/service&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>The xml/device_filter.xml contains this</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;usb-device vendor-id="0403" product-id="6010"/&gt; &lt;/resources&gt; </code></pre> <p>My LocationService class has overridden onStartCommand() which handles the USB_DEVICE_ATTACHED intent</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload