在我的应用中打开某种文件类型

时间:2016-03-10 13:52:17

标签: android xamarin intentfilter

我的应用生成.smbf文件,当用户想要使用文件管理器应用打开它们时,我想在我的应用中打开这些文件。 搜索后,我找到了一种使用意图过滤器的方法,这是我的代码:

[Android.App.Activity(Label = "Setting", Theme = "@style/MyTheme", WindowSoftInputMode = SoftInput.StateHidden, Icon = "@drawable/Icon")]
[Android.App.IntentFilter(actions: new string[] { Intent.ActionView, Intent.ActionEdit }, Categories = new string[] { Intent.CategoryDefault }, DataPathPattern = @".*\\.smbf", DataHost = "*", DataScheme = "file")]
public class Setting : MyActivity
{..}

生成的清单:

<activity android:icon="@drawable/icon" android:label="Setting" android:theme="@style/MyTheme" android:windowSoftInputMode="stateHidden|adjustUnspecified" android:name="md5307edafcc42f816474105a485627044f.Setting">
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.EDIT" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:host="*" android:pathPattern=".*\\.smbf" android:scheme="file" />
  </intent-filter>
</activity>

但我的应用程序未显示在可以打开* .smbf文件的应用程序列表中。 (使用solid和es文件资源管理器测试) 还有什么我应该做的吗?

2 个答案:

答案 0 :(得分:0)

您的文件是否位于包含句点的路径中?当在完整路径中存在某些时段时,使用这样的pathPattern存在一个长期存在的问题。从2010年开始看我的古老问题。6年内没有任何改变,这有点令人难过。

https://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i

答案 1 :(得分:0)

添加mimeType属性后,我的问题已解决: 133 123 20 -1 DataMimeType = "*/*"