使用intent在android中打开文件

发布于 2024-12-21 16:25:08 字数 459 浏览 5 评论 0原文

使用意图使我的应用程序从电子邮件应用程序启动后,如何打开导致启动的文件?通常我只是使用

fis = openFileInput("test.txt");

但由于它只是从意图启动应用程序我不知道名称。我假设这与获取 URI 有关。我正在使用启动应用程序

<intent-filter>
   <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="*/*" />
   <data android:pathPattern=".*\\.xls" />
</intent-filter> 

After using a intent to cause my app to launch from the email application, how do I open the file that caused the launch? Normally I just use

fis = openFileInput("test.txt");

But since its just launching the application from a intent I don't know the name. I am assuming it will have something to do with acquiring the URI. I am launching the app using

<intent-filter>
   <action android:name="android.intent.action.VIEW" />
   <category android:name="android.intent.category.DEFAULT" />
   <data android:mimeType="*/*" />
   <data android:pathPattern=".*\\.xls" />
</intent-filter> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日裸衫吸 2024-12-28 16:25:08

要获取文件的 InputStream,您可以在 Activity 的 onCreate() 方法中使用如下代码:

Uri dataUri = getIntent().getData();
ContentResolver cr = getContentResolver();
InputStream input = cr.openInputStream(dataUri);
//input.read() or whatever you want...

To get InputStream for the file you could use the code like this in your Activity's onCreate() method:

Uri dataUri = getIntent().getData();
ContentResolver cr = getContentResolver();
InputStream input = cr.openInputStream(dataUri);
//input.read() or whatever you want...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文