Legal Disclaimer

Tech in your hand
Custom Search

Feedback ? Send it to admin@fullchipdesign.com or join me at fullchip@gmail.com

Legal Disclaimer

An easy approach to understand tech specs
Learn to Impress
Home.Pics.LTE Home.OFDMA  .
Home Android Intent
Previous.
Next.

Android sample code to use intent to load static html webpages.

In previous topic we discussed an experiment application in android to create a list of buttons with attached html content. Once the user clicks the buttons static html web pages are loaded on the device screen using intent..setData(Uri.parse(url))

 

package com.example.fcd;

 

import android.net.Uri;

import android.os.Bundle;

import android.app.Activity;

import android.content.Intent;

import android.view.Menu;

import android.view.View;

 

public class MainActivity extends Activity {

 

@Override

protected void onCreate(Bundle savedInstanceState) {

 super.onCreate(savedInstanceState);

 setContentView(R.layout.activity_main);

}

 

@Override

public boolean onCreateOptionsMenu(Menu menu) {

 // Inflate the menu; this adds items to the action bar if it is present.

 getMenuInflater().inflate(R.menu.activity_main, menu);

 return true;

}

 public void load (View view) {

 String url = "http://www.fullchipdesign.com/verilog.htm";

 Intent intent= new Intent(Intent.ACTION_VIEW);

 intent.setData(Uri.parse(url));

 // incorrect - intent.setData(Uri.parse("content://intro.txt"));

 startActivity(intent);

 // do something

 

}

 public void load2 (View view) {

 String url = "http://www.fullchipdesign.com/verilog_initial_clocks_reset.htm";

 Intent intent= new Intent(Intent.ACTION_VIEW);

 intent.setData(Uri.parse(url));

 // incorrect - intent.setData(Uri.parse("content://intro.txt"));

 startActivity(intent);

 // do something

 

}

 

 

}

Above two lines of code are required to invoke methods to load intents. These intents will inturn parse html web-pages. Lets review the complete code below.

MainActivity.java code is located under project_name/src/com/example/project_name/MainActivity.java

main_activity.java - This file has a new method to startActivity with click from android buttons.

 

While creating buttons in activity_main.xml we used following commands.

 

android:onClick="load"

android:onClick="load2"

 

 

In the above code two methods are defined with intents to parse html content when the buttons are clicked on the home screen of the app.

public void load (View view) { .. }

public void load2 (View view) { .. }

Previous topic : Android Project Home