How to get the file name from the intent?

烈酒焚心 提交于 2020-01-02 00:47:33

问题


This is my manifest file. After using intent filter i download the ics file from the mail attachment. When i open the downloaded file it start my application. I need to get the file name and data of the selected file in my application. What should i do in the manifest and the java file. I am very new to android can any one help me????

<application android:label="@string/app_name" android:icon="@drawable/icsicon">
    <activity android:name=".setMIMEfile" android:label="@string/app_name">
     <intent-filter>
         <action android:name="android.intent.action.VIEW" />
         <category android:name="android.intent.category.DEFAULT" />
         <data android:mimeType="*/*" />
        <data android:pathPattern=".*\\.ics" />    
     </intent-filter>
</activity>

回答1:


Intent intent = getIntent();                
String name = intent.getData().getPath();

String name will contain your selected file path, from that path you can read your file




回答2:


Note that

Intent intent = getIntent();
String name = intent.getData().getEncodedPath();

gives you an encoded string, e.g. a space in the file name is encoded as "%20". If you want to open the file, you have to use

intent.getData().getPath()

instead.




回答3:


You can get the file name using intent.getData().




回答4:


Intent intent = getIntent();
String name = intent.getData().getLastPathSegment();


来源:https://stackoverflow.com/questions/2971871/how-to-get-the-file-name-from-the-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!