C# Xamarin表单中的文件关联(Android不工作)
应用程序需要从web下载以及邮件附件接收XML文件。 在iOS上,一切正常,但在Android上,文件关联不起作用。该程序运行正常,但当试图打开XML文件时,Android会说“无法打开文件” 我尝试了不同的Memetype、DataSheme和Actions,但都没有成功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 =
[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没有自动关联。