2012-09-12 48 views
1

可能重复:
Intent for editing plain text file with the installed file editor (if any)ActivityNotFound即使活动存在

我试图打开我已经下载了一些文本文件。当我用intent启动活动时,它会给ActivityNotFound异常。

try { 
    Uri path = Uri.parse(path+"/sampletext.txt"); 
    Intent intent = new Intent(Intent.ACTION_VIEW); 
    PackageManager packageManager = ctx.getPackageManager(); 
    intent.setType("text/plain") ; 
    List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); 
    if (list.size() > 0) { 
     intent.setDataAndType(path, "text/plain"); 
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     ctx.startActivity(intent) ; 
    } 

} catch (Exception e){ 
    e.printStackTrace() ; 
} 

当我调试,我发现,则为list.size为1

有哪些我失踪的任何其他信息?

任何类型的点都会帮助我。

谢谢。

+0

我可以从文件浏览器打开相同的文件,但不能从我的应用程序打开。 – Vinay

+0

@ Merlin我不想编辑文件..我需要打开文件阅读.. – Vinay

+0

这是一样的想法 – Merlin

回答

2

ActivityNotFound异常通常在清单文件中没有声明匹配活动或被另一个应用程序注册为共享活动时发生。

您可能需要编辑您的路径:

Uri path = Uri.parse("file://" + path + "/sampletext.txt");

一个更好的方式来做到这一点是使用简便方法:

Uri data = Uri.fromFile(file);

但你需要创建一个使用该方法的文件对象

+0

当我呕吐时,我发现快速办公室[在我的HTC手机]列在我从queryIntentActivities(..)得到的回应。 – Vinay

+0

你认为文件路径会触发ANF异常而不是FileNotFound异常吗? – Vinay

+0

不是真的,但你从来没有现在什么机器人在幕后...这是值得一试 – Merlin

相关问题