-1

Hi everyone i am finding difficulty in accessing the file from my project assets folder. This is my xml file

<LinearLayout 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"
android:orientation="vertical"
tools:context="androidhive.info.materialdesign.activity.HomeFragment"
android:paddingLeft="10dp"
android:paddingRight="10dp">


<!--<TextView-->
    <!--android:id="@+id/label"-->
    <!--android:layout_alignParentTop="true"-->
    <!--android:layout_marginTop="10dp"-->
    <!--android:layout_width="fill_parent"-->
    <!--android:layout_height="wrap_content"-->
    <!--android:gravity="center_horizontal"-->
    <!--android:textSize="30sp"-->
    <!--android:text="About PES"-->
    <!--android:textStyle="bold"/>-->

<!--<TextView-->
    <!--android:layout_below="@id/label"-->
    <!--android:layout_width="fill_parent"-->
    <!--android:layout_height="wrap_content"-->
    <!--android:layout_marginTop="10dp"-->
    <!--android:textColor="@color/text"-->
    <!--android:text="@string/aboutpes"-->
    <!--android:layout_centerHorizontal="true"-->
    <!--android:textIsSelectable="true" />-->
<WebView android:id="@+id/webPage"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"/>

This my fragment file

public class HomeFragment extends Fragment{
private WebView webView;
public HomeFragment() {
    // Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   // setContentView(R.layout.fragment_home);

}

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_home, container, false);
    webView = (WebView) rootView.findViewById(R.id.webPage);
    //  webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient());
    webView.loadUrl("file:///android_assets/programs.html");

    // Inflate the layout for this fragment
    return rootView;
}


public void onAttach(Activity activity) {
   super.onAttach(activity);
}


public void onDetach() {
   super.onDetach();
}

}

Would be grateful if somebody suggests me where i am going wrong. So that i can correct myself.

3
  • 1
    what problem u are getting ? also make sure added INTERNET Permission in AndroidManifest.xml Jun 24, 2015 at 8:31
  • ya i have added the INTERNET permission in AndroidManifest file.. The error i am getting is webpage not available Jun 24, 2015 at 8:33
  • ok try to use android_asset instead of android_assets Jun 24, 2015 at 8:35

1 Answer 1

0

Try this

webView = (WebView) rootView.findViewById(R.id.webPage);
webView .setWebViewClient(new WebViewClient() {  
  @Override  
  public boolean shouldOverrideUrlLoading(WebView view, String url)  
  {  
    view.loadUrl(url);
    return true;
  }  
}); 
webView .loadUrl("file:///android_assets/programs.html");
2
  • Hi Neal still it display's the same error - the web page not available Jun 24, 2015 at 8:37
  • check your folder name, is it "assets" or "asset" ...? Jun 24, 2015 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.