opening-local-html-file-with-android-browser in android 3.x
Asked Answered
P

3

4

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?

Papillary answered 11/4, 2012 at 10:33 Comment(2)
Also seen on Android 4.0.4Salvation
@NicolasRaoul , is this issue resolved?Cu
S
2

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.

https://github.com/nicolas-raoul/OxygenGuide-Android/blob/master/src/org/github/OxygenGuide/MainActivity.java#L69

Salvation answered 9/9, 2013 at 2:59 Comment(1)
In my nexus 5 it just brings up a dialog letting me choose from couple of random (atleast to me) apps; such as Calendar, Call settings, maps and even Waze.Skywriting
E
1
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.

Errantry answered 12/1, 2015 at 10:48 Comment(0)
O
0
Uri uri = Uri.parse(url);
Intent browserIntent = new Intent(Intent.ACTION_VIEW);
browserIntent.setDataAndType(uri, "text/html");
browserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
startActivity(browserIntent);
Overunder answered 24/10, 2015 at 20:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.