How to open an instagram profile in a webView, for Android with Android Studio?

0

I am developing an exercise that implements a Navigation Drawer from the template that Android Studio has and I have been modifying it and placing functionalities to the menu buttons.

One of my buttons directs to an Instagram profile, what I want is that you never leave my application and show the instagram profile in the main content of my NavigationDrawer, but currently although I am treating it as a webView it keeps opening with the device's default browser, I do not know if it is necessary to use some special instagram Apis; next I show them the code in the Fragment that adds functionality to the button. I appreciate your help.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    String url="aquí va la url";
    WebView view=(WebView) getActivity().findViewById(R.id.wvinstagram);
    view.getSettings().setJavaScriptEnabled(true);
    view.loadUrl(url);
}

In this way what it does is open the profile with the browser, I tried the onCreateView method as follows and the application closes,

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    View view = inflater.inflate(R.layout.instagram,container,false);

    String url="aquí coloco la url";
    WebView v =(WebView) getActivity().findViewById(R.id.wvinstagram);
    v.getSettings().setJavaScriptEnabled(true);
    v.loadUrl(url);

    return view;
}

I annul the fraction of code for the WebView and it runs normally without content.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.instagram,container,false);

    return view;
}
    
asked by Ivan Alfredo 31.07.2017 в 17:09
source

1 answer

1

You have to assign the web client before loading the url to avoid opening the browser:

WebView v =(WebView) getActivity().findViewById(R.id.wvinstagram);
v.getSettings().setJavaScriptEnabled(true);
v.setWebViewClient(new WebChromeClient());
v.loadUrl(url);
    
answered by 31.07.2017 / 19:12
source