I have a simple android screen which consists of a button as shown below
I also have a local webpage
named webpage.html
stored within my assets
folder on android studio.
When the button
on the android screen is clicked, I want to open the local webpage that I have stored. If I try opening http://www.google.com
it works just fine. But it seems to have a problem in opening any local page for now. Following is my MainActivity.java
code snippet -
//click this button to open a web page
public void onOpenWebBrowser(View v)
{
Intent webPageIntent = new Intent(Intent.ACTION_VIEW);
webPageIntent.setData(Uri.parse("/Users/user/AndroidStudioProjects/ProjectName/app/src/main/assets/webpage.html"));
try {
startActivity(webPageIntent);
} catch (ActivityNotFoundException ex) {
// can do something about the exception.
}
}
@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;
}
And here are the contents of my activity_main.xml
file -
<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=".MainActivity" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="onOpenWebBrowser"
android:text="Open Web Browser" />
</RelativeLayout>
P.S - The webpage works fine when and if I open it from the outside, in a browser. Please help!