如何获得从意图的文件名? [英] How to get the file name from the intent?

查看:109
本文介绍了如何获得从意图的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的清单文件。使用意图过滤器后,我从下载邮件附件的ICS文件。当我打开下载的文件就开始了我的申请。我需要的文件名,并在我的应用程序中选择文件的数据。我应该怎么做,在清单和Java文件。我很新到Android任何一个可以帮助我????

 <应用机器人:标签=@字符串/ APP_NAME机器人:图标=@可绘制/ icsicon>
    <活动机器人:名称=机器人setMIMEfile。:标签=@字符串/ APP_NAME>
     <意向滤光器>
         <作用机器人:名称=android.intent.action.VIEW/>
         <类机器人:名称=android.intent.category.DEFAULT/>
         <数据机器人:MIMETYPE =* / */>
        <数据机器人:pathPattern = />中* \\集成电路。
     &所述; /意图滤光器>
< /活性GT;
 

解决方案

 意向意图= getIntent();
字符串名称= intent.getData()getPath()。
 

字符串名称将包含所选文件的路径,从该路径可以读取文件

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>

解决方案

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

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

这篇关于如何获得从意图的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆