简体   繁体   中英

Open file in android using intent

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> 

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM