如何解决如何告诉 Android 在我的应用程序中在某些设备上打开自定义文件类型,例如三星
我已经阅读了几个类似的问题 (Android intent filter for a particular file extension?,Creating app which opens a custom file extension,Associating App with Epub format),但我的问题略有不同。很抱歉这篇带有图片的长篇文章,但最好能明白我的意思。
我想从文件资源管理器等应用程序中打开自定义文件类型。我的意图过滤器看起来像:
[IntentFilter(new[] { Intent.ActionView,Intent.ActionSend,Intent.ActionEdit },Categories = new[] { Intent.CategoryDefault },DataMimeType = "*/*",DataHost = "*",DataPathPattern = ".*\\.pdo",Icon = "@drawable/icon"
)]
当我在 Total Commander 中点击文件时,出现了下一个弹出窗口:
我可以选择“打开方式”或“打开方式”,然后在随后的窗口中选择我的应用程序。一切正常。
但是当我在文件资源管理器 (Samsung A51) 中点击文件时,出现了下一个弹出窗口:
所以第一个问题是我错过了什么以及如何告诉文件资源管理器使用我的应用打开这个文件。
在这个漂亮的窗口中显示我的应用程序是更好的选择:) 所以第二个问题是如何实现这种行为。提前致谢。
编辑
这是生成的AndroidManifest.xml
的相关部分 <manifest>
<application
android:name="android.app.Application"
android:debuggable="true"
android:appComponentFactory="androidx.core.app.CoreComponentFactory"
android:requestLegacyExternalStorage="true">
<activity
android:theme="@2131689703"
android:icon="@2131165558"
android:name="MainActivity"
android:launchMode="2"
android:configChanges="0x26c0"
android:alwaysRetainTaskState="true">
<intent-filter android:icon="@2131165558">
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.EDIT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:host="*" />
<data android:pathPattern=".*.pdo" />
<data android:mimeType="application/pdo" />
<data android:mimeType="application/octet-stream" />
</intent-filter>
</activity>
<activity
android:theme="@2131689957"
android:icon="@2131165558"
android:name="SplashActivity"
android:configChanges="0x480"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="xamarin.essentials.fileProvider"
android:exported="false"
android:authorities="de.novel.loadsol.fileProvider"
android:grantUriPermissions="true">
<Meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@2131820550" />
</provider>
</application>
</manifest>
编辑 2
问题似乎是某些设备特有的。在 Vivo 和 Honor 手机上,文件资源管理器可以很好地打开我的应用。
解决方法
我之前希望我的应用程序中的 .smbf
文件扩展名有类似的行为。这些是我达到的最终设置。
[IntentFilter(
actions: new string[] { Intent.ActionView },Categories = new string[] { Intent.CategoryDefault,Intent.CategoryBrowsable },DataPathPatterns = new[] { @".*\\.smbf",@".*\\.smbf" },DataMimeTypes = new[] { "*/*","*/*" },DataHosts = new[] { "*","*" },DataSchemes = new[] { "content","file" })]
,
花了一整天的时间后,我只找到了一个适用于 Samsung File Explorer 的选项。所以我又添加了一个意图过滤器:
[IntentFilter(new[] { Intent.ActionView,Intent.ActionSend,Intent.ActionEdit,Intent.ActionGetContent,Intent.ActionSendto },Categories = new[] { Intent.CategoryDefault,Intent.CategoryBrowsable,Intent.CategoryOpenable },Icon = "@drawable/icon",DataMimeType = "*/*",DataScheme = "content"
)]
这种方法的主要缺点是显而易见的 - 建议我的应用从资源管理器中打开任何文件。我尝试了不同的 mime 类型,例如 application/octet-stream
、application/binary
、application/pdo
,但它们都不起作用。当然,我正在应用中检查文件类型,不会打开“外国”文件,但是这个问题仍然很烦人。
我仍然想知道为什么 content
是与某些文件浏览器交互的单一方式(我只在三星设备中发现了这种行为,但我猜这也可能发生在其他一些设备上)。>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。