注册接收特定文件类型的应用程序

时间:2017-11-01 14:09:53

标签: android xamarin android-intent

编辑:在评论代码应该是正确的之后,我正在玩一些东西,我发现:

当我尝试从文件浏览器打开pgn文件时,我的应用程序在列表中。我之前没有尝试这个,因为我的主要目标是通过其他应用程序捕获文件共享。不知道它有什么不同。明天我会努力寻找改进,欢迎任何想法...

原始问题,不再那么重要了

我希望我的应用程序成为使用具体mime类型打开Intent的可能应用程序之一。我很确定必须在某处覆盖这个主题,但无论我尝试什么,我的应用程序仍然是不可见的(对于其他mime类型它也是不可见的)。这是github上另一个应用程序的应用程序清单中的代码的一部分。

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="application/x-chess-pgn" />
</intent-filter>

这是我做的尝试之一

[Activity(MainLauncher = true, Theme = "@android:style/Theme.Light.NoTitleBar.Fullscreen",LaunchMode =Android.Content.PM.LaunchMode.SingleTop)]
[IntentFilter(actions: new[] { "android.intent.action.VIEW" },DataMimeTypes = new[] {"application/x-chess-pgn"}, Categories = new [] {Android.Content.Intent.CategoryDefault} )]
public class StartPageActivity : Activity
{
...
}

这是另一个

protected async override void OnCreate(Bundle savedInstanceState)
{
    IntentFilter filter = new IntentFilter(Intent.ActionView, "application/x-chess-pgn");
    BroadcastReceiver receiver = new PgnBroadcast();
    RegisterReceiver(receiver, filter);
    ...
}

我也在尝试在清单文件中做同样的事情,但这并不是我的口味,它也没有用。对于具体的意图类型,系统是否可以看到我的应用程序需要执行的其他操作?视频或链接将非常受欢迎。

1 个答案:

答案 0 :(得分:0)

不熟悉android的系统属性我在错误的地方挖掘。我一直在通过分享操作测试接收文件。为了能够抓住这个,必须有

  

&#34; android.intent.action.SEND&#34;

意图过滤器中的操作。现在,我的应用程序在文件浏览器和共享中都可以看作开启。

[IntentFilter(actions: new[] { "android.intent.action.VIEW", "android.intent.action.SEND" },DataMimeTypes = new[] { "application/x-chess-pgn" }, Categories = new [] {Android.Content.Intent.CategoryDefault} )]
相关问题