Android 如何将文件与我的应用程序关联
您好,我在这里找到了如何将文件扩展名与我的应用程序关联的解决方案。我明显的表情Android 如何将文件与我的应用程序关联,android,Android,您好,我在这里找到了如何将文件扩展名与我的应用程序关联的解决方案。我明显的表情 manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.micha.aa"> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-per
manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.micha.aa">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/plain"/>
<data android:scheme="file"/>
<data android:host="*" />
<data android:pathPattern=".*\\.ur"/>
</intent-filter>
</activity>
<activity android:name=".CurrentItem"
android:screenOrientation="portrait">
</activity>
</application>
</manifest>
当我在s7 edge上打开我的文件浏览器并点击我的文件时,我得到一个错误
无法打开该文件,您的手机没有用于打开该文件的应用程序
我已经读到这个片段应该有用
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/plain"/>
<data android:scheme="file"/>
<data android:host="*" />
<data android:pathPattern=".*\\.ur"/>
</intent-filter>
充其量,对于使用文件
Uri
尝试查看文件的应用程序来说,
将起作用。在Android 7.0+上,Uri
通常是一个内容
Uri
,其路径不一定以.ur
结尾。因此,我应该如何更改路径模式才能打开扩展名为的文件。Urt这是不可能的。同样,内容
Uri
不需要以任何特定的文件扩展名结尾,例如https://stackoverflow.com/questions/44634414/how-to-associate-file-with-my-app
不会以.html
结尾。通过在应用程序内部为用户提供“打开”选项,将重点放在应用程序引入内容上,使用ACTION\u GET\u CONTENT
和/或ACTION\u OPEN\u DOCUMENT
。例如,三星在其备忘录应用程序中如何关联到,如果您将备忘录保存在扩展名为.memo的外部内存中,然后单击它,则无论“您在应用程序中单击它”,应用程序备忘录都将打开此文件意味着使用ACTION\u视图
和文件
意图
,那么他们大概有一个与您类似的
。如果“你在应用程序中点击它”意味着使用ACTION\u VIEW
和content
Intent
,那么无论“你在应用程序中点击它”意味着添加了
使用的MIME类型,或者三星在他们的设备上为他们的特定MIME类型修改了MimeTypeMap
。如果你开发自己的手机系列,你也可以做同样的事情。否则,客户端应用程序将不知道用于内容的特定MIME类型。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/plain"/>
<data android:scheme="file"/>
<data android:host="*" />
<data android:pathPattern=".*\\.ur"/>
</intent-filter>