Android Question Launch App with USB Accessory

tman

Member
Licensed User
Longtime User
How do I get my app to launch automatically when my usb accessory (AOA) is plugged in?

Thus far I added these activity text lines to the manifest.xml
< intent-filter>
< action android:name="android.intent.action.MAIN"/>
< category android:name="android.intent.category.LAUNCHER"/>
< /intent-filter>
< intent-filter>
< action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"/>
< /intent-filter>
< meta-data android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" android:resource="@xml/accessory_filter"/>
< /activity>

I also added the proper "accessory_filter.xml" file to the res/xml directory

Now I am not sure of where to go from here.
I imagine I need some code in main activity to tell the app to open when the accessory notification is raised.
 

tman

Member
Licensed User
Longtime User
I decompiled the app made for the accessory and found this line in the manifest:
<receiver android:name="com.embarcado.rtl.notifications.NotificationAlarm" />
It looks like I need to create a service in my app to receive the intent raised when the accessory is plugged in.
I could use some guidance on how to go about this task.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
look at the service code of the decompiled app too
 
Upvote 0

tman

Member
Licensed User
Longtime User
Problem solved! I found a typo in my manifest - ugh!
The manifest alone was enough to open my app automatically when the accessory is plugged into my phone.
No further coding was needed in the app.
 
Upvote 0
Top