Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从打开相关文件获取内容Android SDK_Android_File_Android Intent_File Association - Fatal编程技术网

从打开相关文件获取内容Android SDK

从打开相关文件获取内容Android SDK,android,file,android-intent,file-association,Android,File,Android Intent,File Association,因此,我将一个特定的文件类型与我的应用程序相关联,我希望能够使它在打开该类型的文件时,应用程序打开并能够从文件中检索信息。我该怎么做呢?我知道我可以使用以下方法关联该文件: <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:scheme="file" androi

因此,我将一个特定的文件类型与我的应用程序相关联,我希望能够使它在打开该类型的文件时,应用程序打开并能够从文件中检索信息。我该怎么做呢?我知道我可以使用以下方法关联该文件:

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file"  android:host="*" android:pathPattern=".*\\.shrt" android:mimeType="*/*"  />

当然,代码在意图过滤器的清单文件中,但是获取文件的文本让我陷入困境。我找不到任何关于这个主题的文章(只有一篇,没有解决方案)

我正在将特定文件类型与我的应用程序关联

不,你不是。您正试图将文件扩展名与应用程序关联。随着时间的推移,这将越来越没有用处,因为Android为了更好的访问控制,越来越远离文件,而更多地转向
ContentProvider
s提供的内容

欢迎您将文件扩展名与应用程序关联起来,但您还需要考虑采用合适的MIME类型,并支持其他方案(例如,<>代码>内容>代码>),或者可能不再考虑一般的文件。 获取文件的文本让我陷入困境


onCreate()
中,调用
getIntent().getData()
获取文件的
Uri
。从那里,您可以在
Uri
上调用
getPath()
,以获取文件的路径(以除去
文件://
方案)。此时,它应该是标准的Java文件I/O。

按文件类型,我指的是文件扩展名。谢谢你澄清这一点,尽管消息的语气似乎是消极的。这不是重点,谢谢你,我将尝试这个解决方案。