Home > Uncategorized > How to Use HTML, CSS and JavaScript in Android

How to Use HTML, CSS and JavaScript in Android

1. Create project called “htmlIntent”
2. create activity “WebviewExample”
3. in assets folder create a folder named “www”
4. create “local.html” file inside www folder
5. create a activity called “WebviewOtherExample”
6. manifest file
see below to details –

public class WebviewExample extends Activity{
WebView webview;
private Handler handler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
webview = new WebView(this);
setContentView(webview);

WebSettings settings = webview.getSettings();
settings.setJavaScriptEnabled(true);
webview.setWebChromeClient(new WebChromeClient() {
public boolean onJSAlert(WebView view, String url, String message, JsResult result)
{
return true;
}
});
webview.addJavascriptInterface(new JSInterface(), “jsinterface”);
webview.loadUrl(“file:///android_asset/www/local.html”);
}

public void clickTest(){
Intent nintent = new Intent(WebviewExample.this,WebviewOtherExample.class);
startActivityForResult(nintent,0); // if we did startActivityForResult we could get the data back??
}
public class JSInterface {

public void specialClick() {
handler.post(new Runnable() {
public void run() {

Intent nintent = new Intent(WebviewExample.this,WebviewOtherExample.class);
startActivityForResult(nintent,0); // if we did startActivityForResult we could get the data back??
}
});
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
{
super.onActivityResult(requestCode, resultCode, intent);
//Bundle extras = intent.getExtras();
switch(requestCode)
{
case 0:
if (resultCode == RESULT_OK)
{
Log.v(“WEBVIEW”,”Got Results”);
}
break;
}
}

}

5. create a activity called “WebviewOtherExample”

public class WebviewOtherExample extends Activity {
Button aButton;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
aButton = (Button) findViewById(R.id.Button01);
aButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
WebviewOtherExample.this.finish();

}
});
}
}

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: