with android 2.x i could use the solution
browserIntent.setClassName("com.android.browser", "com.android.browser.BrowserActivity")
resolved in the post:
opening local html file with Android Browser
but with android 3.2 i have this error:
Unable to find explicit activity class
(com.android.browser/com.android.browser.BrowserActivity);
have you declared this activity in your AndroidManifest.xml?
I think that the class com.android.browser.BrowserActivity
doesn't exist in Android 3.x
Any solution?
Not a satisfying solution, but in a demo application I alternatively used the following code:
String url = "content://com.android.htmlfileprovider/sdcard/mydir/myfile.html";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "text/html");
startActivity(intent);
Usually at least one of the two works.
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity")
Will open whatever app has the packagename "com.android.browser". The issue with using this is that over various versions of android and various manufacturers, the default browser changes. For example Nexus devices tend to come pre-installed with the chrome app, which has a different package name.
Unable to find explicit activity class
(com.android.browser/com.android.browser.BrowserActivity);
have you declared this activity in your AndroidManifest.xml?
The error you have copied explains that there is no application with that package name browserIntent.setClassName() is used to open a specific app explicitly which means it shouldn't provide a prompt asking which browser you would like to use.
If this is what you want to avoid (pop up), then you can check what browsers are on the device and possibly suggest downloading it before making links clickable.
you also could use the code from the other suggestion.
String url = "content://com.android.htmlfileprovider/sdcard/mydir/myfile.html";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), "text/html");
startActivity(intent);
This specifies that you want to open an activity that can handle the "text/html" type data. By viewing it. This would provide you with a list of applications (different installed browsers) for you to select.
Uri uri = Uri.parse(url);
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setDataAndType(uri, "text/html");
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(browserIntent);
来源:https://stackoverflow.com/questions/10104244/opening-local-html-file-with-android-browser-in-android-3-x