Bug 40059 - Using IntentFilterAttribute.Data* string[] does not generate the respective value
Summary: Using IntentFilterAttribute.Data* string[] does not generate the respective v...
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 6.0.1 (C6SR1)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2016-04-01 17:45 UTC by Jon Douglas [MSFT]
Modified: 2016-04-06 01:20 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Jon Douglas [MSFT] 2016-04-01 17:45:04 UTC
*Description:

There is a set of Data string[] IntentFilterAttributes that one can use for adding <data /> tags to the Intent Filter. However these items seem to not generate correctly and are not documented in the Xamarin.Android API definition. Instead they only generate an empty <data /> tag for each item:

https://developer.xamarin.com/api/type/Android.App.IntentFilterAttribute

Definition of each string[]:

    public string[] DataHosts { get; set; }

    public string[] DataMimeTypes { get; set; }

    public string[] DataPaths { get; set; }

    public string[] DataPathPatterns { get; set; }

    public string[] DataPathPrefixes { get; set; }

    public string[] DataPorts { get; set; }

    public string[] DataSchemes { get; set; }

Given the simple IntentFilterAttribute code:

    [IntentFilter(
       new[] { Intent.ActionView },
       Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
       DataSchemes = new string[]
       {
            "http",
            "https",
            "content",
            "file",
       })]

Note: You can use any Data* string[] here from the list above and it will just generate empty <data />

We see that the generated AndroidManifest.xml does not behave in the same manner as expected:

      <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data />
        <data />
        <data />
        <data />
      </intent-filter>

Instead we see empty data tags. Ideally we should see the following for each data tag.

        <data android:scheme="http" />
        <data android:scheme="https" />
        <data android:scheme="content" />
        <data android:scheme="file" />

Now there are some defined limitations to Intent-Filters and the <data> element that can be described here:

=============================

http://developer.android.com/guide/components/intents-filters.html#Resolution

Each <data> element can specify a URI structure and a data type (MIME media type). There are separate attributes — scheme, host, port, and path — for each part of the URI:

<scheme>://<host>:<port>/<path>

Each of these attributes is optional in a <data> element, but there are linear dependencies:

If a scheme is not specified, the host is ignored.
If a host is not specified, the port is ignored.
If both the scheme and host are not specified, the path is ignored.

=============================

*Workaround:

1. One can use the singular versions of these Data* string[] attributes instead with multiple Intent-Filters.

    public string DataHost { get; set; }

    public string DataMimeType { get; set; }

    public string DataPath { get; set; }

    public string DataPathPattern { get; set; }

    public string DataPathPrefix { get; set; }

    public string DataPort { get; set; }

    public string DataScheme { get; set; }

2. One can manually edit the AndroidManifest.xml to include the proper definition. (Be wary of it regenerating over existing definitions)

*Reproduction:

1. Create a File->New Android Project
2. Add an Intent-Filter with one of the examples above the MainActivity.cs

EX:

    [IntentFilter(
       new[] { Intent.ActionView },
       Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
       DataSchemes = new string[]
       {
            "http",
            "https",
            "content",
            "file",
       })]
    [Activity]
    public class MainActivity : Activity

3. View the generated AndroidManifest.xml in obj\Debug\android\AndroidManifest.xml

*Version Information:

Microsoft Visual Studio Professional 2015
Version 14.0.25123.00 Update 2
Microsoft .NET Framework
Version 4.6.01038

Installed Version: Professional

Xamarin   4.0.3.214 (0dd817c)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   6.0.3.5 (a94a03b)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   9.6.1.8 (3a25bf1)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 1 Jonathan Pryor 2016-04-06 01:20:48 UTC
It looks like this was fixed in monodroid/bbf82a02 (January 2016) but was never cherry-picked to Cycle6.

This should be fixed in Cycle7.