之前提出过同样的问题,我对它们进行了全部测试,并且没有进行任
我在一个文件中写了一个序列化对象,我的名字就像575454.myCustomExe
我希望我的应用程序只打开*.myCustomExe
而不是更多。
我如何保存文件:
File file = new File(Environment.getExternalStoragePublicDirectory("MyAppFolder") , getId() + ".myCustomExe");
if (!file.exists()) {
file.getParentFile().mkdirs();
file.createNewFile();
}
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(serializableObject);
out.close();
我的意图过滤器:
<activity
android:name=".ui.activity.ImportActivity">
<intent-filter android:icon="@drawable/ic_save"
android:label="label"
android:priority="1">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="content" />
<data android:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern=".*\.myCustomExe"/>
</intent-filter>
我也试过<data android:pathPattern=".*\\.myCustomExe" />
。
Android上没有太多使用文件扩展名。从Android Q开始,Android上的文件使用率不高。没有要求ContentProvider
在content
Uri
上放置类似文件的扩展名。所以,虽然你认为你所拥有的东西在技术上是正确的,但正如你所注意到的那样,它将无法正常工作。
您无法做到这一点,因为您无法更改其他应用的行为。
如果您希望支持像Intent
这样的常见ACTION_VIEW
操作,最好的办法是将文件保存为常用的元格式(例如,JSON,XML),文件扩展名匹配,然后对相应的MIME类型进行<intent-filter>
过滤。您将需要处理用户选择不是由您的应用创建的文件的可能性,尽管从技术上讲,即使使用自定义扩展,您也需要处理该文件。