Skip to content Skip to sidebar Skip to footer

Android Facebook Sdk And Url Methods Form Successful Friends Dialog, But Cannot Commit

This is one that I'm beginning to think is a bug, please, Please prove me wrong: I want to programmatically friend a user on Facebook; they are only and most certainly someone the

Solution 1:

So, it is a bug on facebook, one that they are aware of, and one that they are not going to fix any time soon ( shortage in developer talent? "strategy"? I'll ask Mark... ). Hearing this dissappointing news, I then tried the url in chrome a few different ways, and big surprise: it works fine when you request the desktop site on the confirm screen.

So, there is one way left to us mobile devs, and that is to make a dialog that jails a webview with

  1. a desktop-seeming user-agent
  2. a URL override to stop the fb website from redirecting through Intent.ACTION_VIEW

here's my implementation (in a fragment):

privatevoidsendRequestDialog() {
    String requestUri = "https://www.facebook.com/dialog/friends/?id="+
         Id+"&app_id="+getString(R.string.fb_app_id)+
         "&redirect_uri=http://www.facebook.com";
    WebView webView = newWebView(this.getActivity());
    webView.getSettings().setUserAgentString(getString("Mozilla/5.0 (X11; Linux x86_64; rv:10.0) Gecko/20100101 Firefox/10.0"));
    webView.setWebViewClient(newWebViewClient(){
        publicbooleanshouldOverrideUrlLoading(WebView view, String url){
            returnfalse;
        }
    });
    webView.loadUrl(requestUri);
    AlertDialog.Builder dialog = newAlertDialog.Builder(this.getActivity());
    dialog.setView(webView);
    dialog.setPositiveButton("Done", newDialogInterface.OnClickListener() {

            publicvoidonClick(DialogInterface dialog, int which) {

                dialog.dismiss();
            }
        });
    dialog.show();

Of course, you'll want to make those strings references, but this works and looks good in the UI.

Onwards! -AnB

Post a Comment for "Android Facebook Sdk And Url Methods Form Successful Friends Dialog, But Cannot Commit"