Depending on your application result, if really don't have needing, you can do a WebView
and avoid this work on choose a browser to open your html file. Is simple, you can create a web_file_reader.xml with the following code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".WebActivity" >
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/web_viewer1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<Button
android:id="@+id/but_leave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="leave page" />
</RelativeLayout>
And so, on your class onCreate
callback method, do:
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.relatorios_activity);
Button leave = (Button) findViewById(R.id.but_leave);
sair.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
finish();
}
});
String fileURL = "file://" + filePath; //it's your file path name string
WebView webView = (WebView) findViewById(R.id.wev_viewer1);
webView.setVerticalScrollBarEnabled(true);
webView.setHorizontalScrollBarEnabled(true);
webView.getSettings().setBuiltInZoomControls(true);
webView.loadUrl(fileURL);
}
Set a button to open the following intent from your main activity:
Intent browserView = new Intent(/*your main activity context*/,WebActivity.class);
startActivity(browserView);
This will open any html file with any configuration of layout and/or java script depending for you O.S version on a new Activity.