Android browser?

by maceghost » Tue, 03 Jun 2008 13:19:36 GMT


Sponsored Links
 I've used WebView to load local html, but can't get the browser to
load a page from the web. Why are there no working examples using the
android browser?
--~--~---------~--~----~------------~-------~--~----~



Android browser?

by Mark Murphy » Tue, 03 Jun 2008 13:30:41 GMT


 


For what it's worth, it works for me.

There have been various threads on this group and android-beginners 
regarding getting networking going properly with the emulator. For me, 
it worked without changes, but if you work in an office with proxies and 
firewalls, you might need to do some more work.

If the problem does not seem to be related to networking, please write 
back with more specific symptoms (e.g., error messages), and we can try 
to help.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ -- Available Now!

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Android browser?

by maceghost » Tue, 03 Jun 2008 15:30:36 GMT


 hat is working for you?  I could find no real examples of any code
using WebView to load a page from the internet. I'll freely admit
that I could be missing something. I'll include the code that I
managed to piece together from several disjoint sources ( none from
code.google.com ), as well as the logcat which I have displayed in
eclipse ( debug ).

package com.maceghost.test.webkit;

import android.app.Activity;
import android.content.ContentProvider;
import android.content.Context;
import android.content.Intent;
import android.content.IntentReceiver;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.GridView;

public class WebTest extends Activity {

WebView mainPage = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
try {
mainPage = (WebView) findViewById(R.id.webView);
mainPage.loadUrl("http://www.google.com/");
} catch (Exception e) {
e.printStackTrace();
}
}

}

logcat output :

INFO/DEBUG(494): debuggerd: Feb 28 2008 17:13:08
DEBUG/AndroidRuntime(496): >>>>>>>>>>>>>> AndroidRuntime START
<<<<<<<<<<<<<<
INFO/AndroidRuntime(496): Assertions enabled for ALL code (-ea and -
esa)
INFO/runtime(497): Startup: sys='/system' asset='/system/app' data='/
data'
INFO/runtime(497): Entered boot_init()!
DEBUG/runtime(497): ProcessState: 0x124e8
INFO/runtime(497): Binder driver opened. Multiprocess enabled.
DEBUG/AndroidRuntime(496): --- registering native functions ---
DEBUG/dalvikvm(496): Exception Ljava/lang/ClassNotFoundException; from
PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(496): NOTE: loadClass 'android.app.Activity
$LocalWindowManager' 0x40018950 threw an exception
WARN/Zygote(496): Zygote class init exception
java.lang.ClassNotFoundException: android.app.Activity
$LocalWindowManager with class android.app.Activity$LocalWindowManager
DEBUG/dalvikvm(496): Exception Ljava/lang/ClassNotFoundException; from
PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(496): NOTE: loadClass 'android.content.PackageManager'
0x40018950 threw an exception
WARN/Zygote(496): Zygote class init exception
java.lang.ClassNotFoundException: android.content.PackageManager with
class android.content.PackageManager
DEBUG/dalvikvm(496): Exception Ljava/lang/ClassNotFoundException; from
PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(496): NOTE: loadClass 'android.content.PackageManager
$ActivityInfo' 0x40018950 threw an exception
WARN/Zygote(496): Zygote class init exception
java.lang.ClassNotFoundException: android.content.PackageManager
$ActivityInfo with class android.content.PackageManager$ActivityInfo
DEBUG/dalvikvm(496): Exception Ljava/lang/ClassNotFoundException; from
PathClassLoader.java:205 not caught locally
DEBUG/dalvikvm(496): NOTE: loadClass 'android.content.PackageManager
$ActivityInfo$1' 0x40018950 threw an exception
WARN/Zygote(496): Zygote class init exception
java.lang.ClassNotFoundException: android.content.PackageManager
$ActivityInfo$1 with class android.content.PackageManager$ActivityInfo
$1
DEBUG/dalvikvm(496): LOADING path /system/lib/libmedia_jni.so 0x0
INFO/dalvikvm(496): Added shared lib /s



Android browser?

by Mark Murphy » Tue, 03 Jun 2008 16:15:05 GMT


 > what is working for you?  I could find no real examples of any code

What you have should work fine other than the catch block. My example in
my book is similar to your implementation, minus the try/catch block, and
using  http://commonsware.com  as the URL. Works like a champ. Moreover,
based on the logcat output, yours works fine for you -- leastways, those
DEBUG/browser messages at the end sure make it sound like the browser
loaded a page.

Your catch block probably should use android.util.Log.e() to dump the
results to the logcat output. Unless you're following the instructions for
redirecting stdout/stderr to logcat per:

 http://code.google.com/android/reference/adb.html #stdout

Try loading a different Web page other than the Google home (which has a
lot of whitespace and so the "meat" of the page might need to be scrolled
into view), and see if your catch block actually catches an error that
might offer a clue. If that doesn't help, write back with your symptoms.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
The Busy Coder's Guide to Android Development -- coming in June 2008!


--~--~---------~--~----~------------~-------~--~----~



Android browser?

by maceghost » Wed, 04 Jun 2008 02:00:12 GMT


 hank you for your help. So, what is this book you speak of...?  I've
modified my code according to your suggestions. I've also added a
couple other tests to see if I get output. Curious thing is that the
only time I see any output on the screen is when I load 'http://
commonsware.com'. None of the other attempts show anything on the
screen. No real errors, just nothing shows up, however
commonsware.com does show.

btw, here is my main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="horizontal">
<WebView android:id="@+id/webView"
android:background="#77CC0000"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:focusable="false"/>
</LinearLayout>
</LinearLayout>




public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
try {
mainPage = (WebView) findViewById(R.id.webView);
mainPage.loadData(
"<html><body>Hello World!</body></html>",
"text/html", "utf-8");

Thread.sleep(60000);

mainPage.loadData(
"<html><body><img src=\"file:///android_asset/
Winter.jpg\"></body></html>",
"text/html", "utf-8");

Thread.sleep(60000);

mainPage.loadData(
"<img src=\"file:///android_asset/Winter.jpg\">",
"image/jpeg", "utf-8");

Thread.sleep(60000);
mainPage.loadUrl("http://commonsware.com");

Thread.sleep(60000);
} catch (Exception e) {
android.util.Log.e("Exception : ", e.getMessage());
}
}



On Jun 3, 9:14am, "Mark Murphy" <[EMAIL PROTECTED]> wrote:
--~--~---------~--~----~------------~-------~--~----~



Android browser?

by Mark Murphy » Wed, 04 Jun 2008 02:15:46 GMT


 > Thank you for your help. So, what is this book you speak of...?

_The Busy Coder's Guide to Android Development_. Version 0.9 is available
in PDF and Kindle form on the CommonsWare Web site. A more formal
announcement is forthcoming.


I broke into the Google servers and hacked the WebKit code to only show
the CommonsWare site.

Note to Google: that's a joke. Honest.


That code works?

The reason I ask is that the Android docs mention that if your activity
doesn't return from callbacks like onCreate() quickly, Android will
consider the activity stuck or dead and will get rid of it. I hadn't
experimented with that feature in the emulator, but I had figured it was
already in there. I would think that minute-long sleep periods in
onCreate() ought to trigger the scavenger, but apparently not.

I seem to recall that accessing the Google Web site was hit or miss, but I
wrote that off as being something peculiar to them perhaps doing
browser-sniffing and causing Android's WebKit some problems. I can say
that  http://commonsware.com  uses nothing more complicated than CSS -- no
Javascript, no server-side smarts (until you get to the Warescription
ecommerce piece), etc.

Have you tried visiting these other sites in the built-in Browser
application? If they work there, but not in your activity, that might
trigger some ideas. But, beyond that, off the top of my head, I don't know
what might be going wrong.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ -- Available Now!



--~--~---------~--~----~------------~-------~--~----~



Android browser?

by maceghost » Wed, 04 Jun 2008 02:40:01 GMT


 'm almost willing to go out on a limb and say that if I don't sleep
for more then a second after loadUrl() then the page doesn't show.
When I sleep for 1 second, sometimes the page will not show and
sometimes the page will draw 1/2 way and then stop. If I sleep for 3
or more seconds, the page will show ( relatively ) consistently. At
this point, all I do is this:

mainPage.loadUrl("http://commonsware.com");
Thread.sleep(3000);

I should try some other web pages, but google.com and yahoo.com both
don't show up. It's also curious to me that if the page shows up 1/2
way or enough to reveal the <home> link at the top, I can click on the
home link and it will display the whole page.

This all seems a bit flakey to me. One thing I might add is that I'm
running through eclipse ( 3.3.2 ).


On Jun 3, 11:15am, "Mark Murphy" <[EMAIL PROTECTED]> wrote:
--~--~---------~--~----~------------~-------~--~----~



Android browser?

by Mark Murphy » Wed, 04 Jun 2008 02:43:44 GMT


 > I'm almost willing to go out on a limb and say that if I don't sleep

That's strange.


I run my emulator outside an IDE. I don't know that it matters.

Are you on the M5 SDK?

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ -- Available Now!


--~--~---------~--~----~------------~-------~--~----~



Android browser?

by maceghost » Wed, 04 Jun 2008 02:50:25 GMT


 It's been strange from the outset. I now know that I can also load
" http://code.google.com/android" ; ( seems appropriate ) but only if I
have a sleep after the loadUrl().  I'm on M5 SDK.

android-sdk_m5-rc15_windows

Maybe I should try this on my linux box...or outside of the IDE.




--~--~---------~--~----~------------~-------~--~----~



Android browser?

by Gene Vayngrib » Sat, 14 Jun 2008 05:38:13 GMT


 Watch your server log when requests come in and see which was the last
served before webkit gets stuck.
On our web site ( http://neoyou.org ) we saw webkit hang on receiving
images.
On a hunch we configured our http server to close connection on every
response and that fixed the problem for now (could not yet track down
what combination of headers gets webkit confused).
Also, webkit on Android hangs on 2 redirects in a row. It can handle
single redirect though.

For the extensive use of webview api look at our open source product
 http://bhoost.com  which greatly enhances the webkit to allow web apps
to access Android APIs and plenty more.
Click on Download Tab to browse sources online check them out from
svn.

Hope this helps, - let me know how did it go.




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. MapView In Android

Hai,

I am Using a MapView in my application and showing the map according to the
longitude and latitude getting by the other part of the application. The
logintude and latitude may change according to the user input. The First
time map showing correctly but from the second time onwards it shows
"android.view.InfalteException". How to solve it . If needs i will put the
code also.

Please Help,
Thank you.

-- 

2. InputStream read on raw Resource leaks memory?

This stems from an issue I posted in the android-ndk group, but I
found recently that that's not really where the problem stems from.
Basically, I'm writing a game, for which I store all my
assets(textures, 3d models, level maps, etc) as raw resources(which I
load through my Activity into byte arrays which are then passed to the
ndk for processing). However, after 7 times of loading the activity,
it would crash saying either "Out of Memory" or "Bitmap exceeds VM
budget". After a bunch of work paring down what the issue could be, I
found that if I only load each byte array once, into static arrays,
the problem no longer occurs.

Clearly a memory leak is occurring here and I have reason to believe
that it's not in my actual storage of the byte arrays since even if
the arrays are made non-static, setting them to null and then
reloading them results in the same crash after 7 runs. I've tried
closing the input stream after each resource is loaded, but that
didn't help either. I'm wondering if there's a reason why reading raw
resources this way leaks memory and also if there's a way to stop this
from occurring.

Thanks for any help.

-- 

3. How to evenly spread the column width in the list activity?

4. File Pushing Problem on to the Emulator

5. New Developer

6. Hello Android app not working?

7. Trouble recording audio