Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
29
rated 0 times [  34] [ 5]  / answers: 1 / hits: 28291  / 14 Years ago, thu, february 24, 2011, 12:00:00

I'm a complete noob to Android and this is just a simple test. Based it on this tutorial.



Here goes the HelloWebApp.java



package com.company.something;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class HelloWebApp extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView webView = (WebView)findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(file:///android_asset/www/index.html);
}
}


And this is from res/layout/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=fill_parent
android:layout_height=fill_parent
>
<WebView
android:layout_width=fill_parent
android:layout_height=fill_parent
android:id=@+id/webView
/>
</LinearLayout>


Plus this is all I changed on the Manifest:



<activity android:name=.HelloWebApp
android:label=@string/app_name
android:theme=@android:style/Theme.Black.NoTitleBar.Fullscreen
android:screenOrientation=landscape>


As for the javascript, I've tried everything. Complicated, simple, inside the body at the bottom, in a button, on the head. Nothing works. The html works fine.



Thanks in advance for any help.


More From » android

 Answers
56

You missed the part in the tutorial where he adds



webView.setWebChromeClient(new WebChromeClient());


right after adding



webView.getSettings().setJavaScriptEnabled(true);


The JavaDoc for this method says:




Sets the chrome handler. This is an implementation of WebChromeClient for use in handling Javascript dialogs, favicons, titles, and the progress. This will replace the current handler.



[#93595] Wednesday, February 23, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jarod

Total Points: 62
Total Questions: 111
Total Answers: 83

Location: Saint Vincent and the Grenadines
Member since Sat, Sep 11, 2021
3 Years ago
jarod questions
;