Android-在我的应用程序中获取选定的pdf,doc,ppt或xls的文件路径 [英] Android - get file path of a selected pdf, doc, ppt or xls in my app
问题描述
我正在开发一个android应用程序.
I am developing an android application.
我的目标:
如果用户打开SDCard(或)保管箱(或)电子邮件等内的任何文件夹中的pdf,doc,ppt或xls文件,则他们必须导航到我的应用中(在我的应用中,我将执行一些操作根据他们选择的文件进行处理.
If the user open the pdf, doc, ppt or xls files in any folder inside the SDCard (or) dropbox (or) email etc..., they must navigate into my app(In my app, I will do some process based on the files they selected).
我做什么:
如果用户单击PDF文件,则可以获取文件路径,并且他们将导航到我的应用程序中.为此,我完成了以下代码.
If the user click on the PDF file, I can get the filepath and they are navigate into my app. For this I have done the following code.
代码段:
在AndroidManifest.xml中,我添加了以下代码:
In the AndroidManifest.xml, I have added the following code:
<activity android:name="com.openwith.OpenwithActivity" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:mimeType="*/*" />
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.pdf" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.pdf" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.pdf" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.pdf" />
</intent-filter>
</activity>
在OpenwithActivity.java
In OpenwithActivity.java
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
public class OpenwithActivity extends Activity {
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_openwith);
Intent intent = getIntent();
Uri data = intent.getData();
if (data != null) {
String filePath = data.getPath();
}
}
}
我需要什么:
我只得到pdf文件的路径.如果要获取doc,ppt和xls文件的路径,我需要在AndroidManifest.xml中添加什么内容?
I am getting only the pdf file's path. If I want get doc, ppt and xls file's path, what I need to add in the AndroidManifest.xml?
我在互联网上搜索过.但是我没有任何清晰的文档(或教程). 谁能帮助我做到这一点?
I have searched in the internet. But I didn't get any clear documents (or) tutorials. Can anyone hep me to do this?
推荐答案
为其他文件类型添加与pdf相同的意图过滤器条目.
Add the same intent-filter entries for the other file types as you did for the pdf.
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.ppt" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.ppt" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.ppt" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.ppt" />
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.xls" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.xls" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.xls" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.xls" />
<data android:scheme="http" android:host="*" android:pathPattern=".*\\.doc" />
<data android:scheme="https" android:host="*" android:pathPattern=".*\\.doc" />
<data android:scheme="content" android:host="*" android:pathPattern=".*\\.doc" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.doc" />
对于图像,这应该做到:
And for the images, this should do:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="image/*" android:scheme="http" android:host="*" />
<data android:mimeType="image/*" android:scheme="https" android:host="*" />
<data android:mimeType="image/*" android:scheme="content" android:host="*" />
<data android:mimeType="image/*" android:scheme="file" android:host="*" />
</intent-filter>
这篇关于Android-在我的应用程序中获取选定的pdf,doc,ppt或xls的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!