ActivityNotFound even when Activity is present [duplicate]
-
01-07-2021 - |
Question
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.
Solution
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