1

Possible Duplicate:
Intent for editing plain text file with the installed file editor (if any)

I am trying to open some text file which I have downloaded. When I start the activity with intent it gives ActivityNotFound Exception.

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() ;
}

When I debugged, I found that the list.size is 1.

Is there any other information which I am missing?

Any kind of points would help me.

Thanks.

Community
  • 1
  • 1
Vinay
  • 2,395
  • 3
  • 30
  • 35

1 Answers1

2

ActivityNotFound Exception is generally encoutered when there is no matching activity declared in the manifest file or registered by another application as a shared activity.

You may need to edit your path:

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

a better way to do this is to use the convenience method:

Uri data = Uri.fromFile(file);

but you would need to create a File object to use that method

Moog
  • 10,193
  • 2
  • 40
  • 66
  • When I debuged I found that quick office [On my HTC phone] is listed in the response which I got from queryIntentActivities(..). – Vinay Sep 12 '12 at 19:58
  • Do you think file path would trigger a ANF Exception and not FileNotFound Exception? – Vinay Sep 12 '12 at 20:06
  • Not really, but you never now what android does behind the scenes ... it's worth a try – Moog Sep 12 '12 at 20:07
  • No problem ... you're right though ... a FileNotFoundException or InvalidIntentDataException would make more sense and ultimately more helpful – Moog Sep 12 '12 at 20:31