0

I've implemented a webview in which I am simply loading a facebook page. While clicking on link (share, or like), it is opening within the webview. I want to open link within the facebook app (if installed).

   public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View layoutProgressWebview = inflater.inflate(R.layout.fragment_webview,container,false);

        progressDialog = new ProgressDialog(getActivity().getApplicationContext());
        progressDialog.setMessage("Loading...");

        webView = (WebView) layoutProgressWebview.findViewById(R.id.webView);
        webView.setWebChromeClient(new ArticleWebChromeClient());
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }
        });
        webView.getSettings().setUserAgentString(userAgent);
        webView.getSettings().setJavaScriptEnabled(true);
        Bundle args = getArguments();
        String resourceUrl = args.getString(ARG_URL);
        webView.loadUrl(resourceUrl);
        return layoutProgressWebview;
    }

private class ArticleWebChromeClient extends WebChromeClient {
        public void onProgressChanged(WebView view, int progress) {
            if (progress == 100) {
                if (progressDialog != null)
                     progressDialog.dismiss();
            }
        }
    }
Rahul Chaurasia
  • 1,601
  • 2
  • 18
  • 37

1 Answers1

0

This works for me:

Go to https://graph.facebook.com/ (https://graph.facebook.com/fsintents for instance) Copy your id Use this method:

public static Intent getOpenFacebookIntent(Context context) 
{
    try 
    {
        context.getPackageManager().getPackageInfo("com.facebook.katana",0);
        return new Intent(Intent.ACTION_VIEW,Uri.parse("fb://page/<id_here>"));
    }catch (Exception e) 
    {
        return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name_here>"));    
    } 
}

This will open the Facebook app if the user has it installed. Otherwise, it will open Facebook in the browser.

https://stackoverflow.com/a/10213314/5295706

Community
  • 1
  • 1
Xinin
  • 1
  • 3
  • Thank you. The page is showing fine in webview. My problem is I need to open the links (within that webview containing the facebook profile) into the facebook application. I don't want to open any profile or page. – Rahul Chaurasia Sep 22 '15 at 10:01