我正在开发一个安卓应用程序。
我的目标:
如果用户打开 SDCard(或)保管箱(或)电子邮件等内的任何文件夹中的 pdf、doc、ppt 或 xls 文件...,他们必须导航到我的应用程序(在我的应用程序中,我将根据他们选择的文件)。
我做了什么:
如果用户单击 PDF 文件,我可以获得文件路径,然后他们将导航到我的应用程序。为此,我完成了以下代码。
代码片段:
在 AndroidManifest.xml 中,我添加了以下代码:
<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 中
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 中添加什么?
我在互联网上搜索过。但我没有得到任何明确的文件(或)教程。任何人都可以帮助我这样做吗?