我已经从FTP服务器上下载了一些Office文件(doc,xls,pdf等),现在我想使用第三方应用程序查看这些文件。
我正在使用以下代码进行Intent(在本例中为PDF文件):
PackageManager packageManager = getPackageManager();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("application/pdf");
List list = packageManager.queryIntentActivities(intent,PackageManager.MATCH_DEFAULT_ONLY);
if (list.size() > 0)
{
Uri uri_path = Uri.parse(path);
intent.setDataAndType(uri_path, "application/pdf");
try
{
startActivity(intent);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(getApplicationContext(),"No Application Available to View PDF", Toast.LENGTH_SHORT).show();
}
}
但是当我尝试打开文件时,白屏会出现并消失。在DDMS中,我得到以下内容:
01-14 16:14:17.900: ERROR/Quickoffice(1204): java.lang.NullPointerException
01-14 16:14:17.900: ERROR/Quickoffice(1204): at s.a(Unknown Source)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at com.qo.android.quickcommon.OfficeActivity.a(Unknown Source)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at com.qo.android.quickcommon.OfficeActivity.a(Unknown Source)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at com.qo.android.quickword.Quickword.onCreate(Unknown Source)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at android.app.ActivityThread.access$1500(ActivityThread.java:122)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at android.os.Handler.dispatchMessage(Handler.java:99)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at android.os.Looper.loop(Looper.java:132)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at android.app.ActivityThread.main(ActivityThread.java:4028)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at java.lang.reflect.Method.invokeNative(Native Method)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at java.lang.reflect.Method.invoke(Method.java:491)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
01-14 16:14:17.900: ERROR/Quickoffice(1204): at dalvik.system.NativeStart.main(Native Method)
请帮我解决这个问题。我不明白这个问题。当我使用“ES文件资源管理器”转到SDCard并打开文件时,它会被打开。所有文件(doc xls和PDF)都可以正确打开。
答案 0 :(得分:1)
得到了我的回答。我需要为我的URI添加以下内容:
File file = new File(path);
Uri uri_path = Uri.fromFile(file);
intent.setDataAndType(uri_path, "application/pdf");
try
{
startActivity(intent);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(getApplicationContext(),"No Application Available to View PDF", Toast.LENGTH_SHORT).show();
}