Android Add file opening method and parameter passing

Source: Internet
Author: User

Previous file sharing, this article about opening files, file open mode selection, and select our own app is to get the file to be processed.

To make our own app appear in the file open mode, just set up the manifest file Androidmanifast.xml, add a <intent-filter> under <activity>

<Intent-filter>       <ActionAndroid:name= "Android.intent.action.VIEW"></Action>       <DataAndroid:mimetype= "Text/comma-separated-values" />       <categoryAndroid:name= "Android.intent.category.DEFAULT"></category></Intent-filter>

You must create a new <intent-filter> here, or you will get an error. Here is an example of the error:

< Intent-filter >         <  android:name= "Android.intent.action.MAIN"/>         <   android:name= "Android.intent.category.LAUNCHER"/></ Intent-filter >

This is the main startup item of the program, if we add a mimetype under this <intent-filter> tag, the program runs completely without exception, but the icon to open the app is missing.

Here the mimetype write is our file format, here is the CSV so fill "text/comma-separated-values".

After processing the file, get the parameters by intent

Intent mintent = getintent ();        String action = mintent.getaction ();        If (Textutils.equals (Action, Intent.action_view)) {            uri uri = mintent.getdata ();            if (Textutils.equals (Uri.getscheme (), "file")) {
String path = Uri.getpath ();
       }
}

You can do all kinds of things by getting the file path.

Android Add file opening method and parameter passing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.