Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin表单中的文件关联(Android不工作)_C#_Android_Xamarin_Xamarin.forms_Xamarin.android - Fatal编程技术网

C# Xamarin表单中的文件关联(Android不工作)

C# Xamarin表单中的文件关联(Android不工作),c#,android,xamarin,xamarin.forms,xamarin.android,C#,Android,Xamarin,Xamarin.forms,Xamarin.android,应用程序需要从web下载以及邮件附件接收XML文件。 在iOS上,一切正常,但在Android上,文件关联不起作用。该程序运行正常,但当试图打开XML文件时,Android会说“无法打开文件” 我尝试了不同的Memetype、DataSheme和Actions,但都没有成功 [Activity(Label = "MyApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, LaunchMode =

应用程序需要从web下载以及邮件附件接收XML文件。 在iOS上,一切正常,但在Android上,文件关联不起作用。该程序运行正常,但当试图打开XML文件时,Android会说“无法打开文件”

我尝试了不同的Memetype、DataSheme和Actions,但都没有成功

[Activity(Label = "MyApp", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTask,
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new[] { Intent.ActionView},
    Categories = new[] { Intent.CategoryDefault },
    DataScheme = "file",
    DataHost = "*",
    DataPathPattern = ".*\\.xml",
    DataMimeType = @"application/xaml+xml")]

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        string action = Intent.Action;
        string type = Intent.Type;

        //If opened to recieve a file
        if (Intent.ActionView.Equals(action) && !String.IsNullOrEmpty(type))
        {
            Console.WriteLine("Opened to recieve a file!");
        }

        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        OxyPlot.Xamarin.Forms.Platform.Android.PlotViewRenderer.Init();
        LoadApplication(new App());
    }
我希望应用程序用于打开和发送.xml文件 然后再处理


编辑:链接到测试应用程序,控制台在工作时说“打开以接收文件”。https://dracoon.team/#/public/shares-下载/bmcpjb5xglwyqarahpnl2x1Ohmbcrv6

供那些正在寻找如何将你的应用程序与
open with…
关联的解决方案的人使用(我无法找到此问题的明确答案)。以下是对我有效的方法:

我用的是Xamarin 16.7

就像Louis(OP)一样,我尝试了以下
IntentFilter

[IntentFilter(new[] { Intent.ActionView},
    Categories = new[] { Intent.CategoryDefault },
    DataScheme = "file",
    DataHost = "*",
    DataPathPattern = ".*\\.txt",
    DataMimeType = @"*/*")]
要测试上面的意图过滤器,我会转到默认的文件应用程序,并尝试打开一个txt文件,但我的应用程序不会显示为选项

然后我把它改成:

[IntentFilter(new[] { Intent.ActionView }, 
Categories = new[] { Intent.CategoryDefault }, DataMimeType = @"text/plain")]
它成功了。问题是在
DataScheme
中,当尝试用…打开
时,它不是
文件
,而是
内容


如果您遇到此类问题,请确保过滤器设置正确。

您可以分享一个基本演示,以便我们可以在我们这边进行测试吗?@JessieZhang在问题中添加了testproject下载链接抱歉,如何重现此问题?@JessieZhang启动android模拟器并尝试打开xml(从邮件或文件应用程序中)-由于文件关联,应用程序应该能够打开它,但表示无法打开xml抱歉,伙计,在我在android设备上运行应用程序并尝试从电子邮件打开xml后,应用程序无法打开xml。换句话说,与xml没有自动关联。