Xamarin Android C#: Using the xml resource folder and manifest to define an intent filter for detecting connected usb devices crashs application

Viewed 1650

hope the day is good!

I have followed this step by step guide in the android development guide for detecting the connection of a usb device here: http://developer.android.com/guide/topics/connectivity/usb/accessory.html (In C# with xamarin though not java and going about the intent filter path so that it could automatically detect the device via a broadcast receiver)

Needless to say, it did not work out as expected and caused my app to crash immediately when started up.

After quite a few hours I have managed to pinpoint at least one of the problems but there may be more. The problem is that if I create the "accessory_filter.xml" in the xml folder (that I created) in the res folder then my app will crash no matter what. Even if my code does not use it at all, as soon as that xml file exists my app will crash straight after starting.

Any help, advice or assistance would be greatly appreciated! Thank you.

EDIT: This is my Android manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="Scout.App" android:versionCode="1" android:versionName="0.0.0" android:installLocation="auto">
    <uses-feature android:name="android.hardware.usb.accessory" />
  <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RESTART_PACKAGES" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <application android:label="myapplication">
    <activity android:name="MainActivity">
            <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>
  </application>
</manifest>

And my accessory_filter.xml:

<?xml version="1.0" encoding="utf-8" ?>
<resources><usb-accessory model="modelname" manufacturer="Me" version="1.0"/></resources>
1 Answers
Related