Intent to call FACEBOOK

The following is that trigger an intent and the same call the Facebook app. I managed to send email

Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.setType("plain/text");
sendIntent.setData(Uri.parse("[email protected]"));
sendIntent.setClassName("com.google.android.gm", "com.google.android.gm"); sendIntent.putExtra(Intent.EXTRA_EMAIL, new
String[]{"[email protected]"});
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "ASSUNTO");
sendIntent.putExtra(Intent.EXTRA_TEXT, "TEEEXTO");
startActivity(sendIntent);

Could you adapt this code to call the face app? Right now, thank you.

Author: Guilherme Nascimento, 2015-12-11

1 answers

Facebook is a website and not a native Google app, so you have three options:

  • calling a webView (doesn't need a Intent necessarily) or using native browser
  • Call facebook Facebook app, you will need the facebook app to be installed.
  • using the official API

Intent with Facebook app:

As I said it is necessary to have the application installed, as this answer of the soen

  • Just to start the default screen:

    Intent intent = new Intent("android.intent.category.LAUNCHER");
    intent.setClassName("com.facebook.katana", "com.facebook.katana.LoginActivity");
    startActivity(intent);
    
  • To start inbox:

    String uri = "facebook://facebook.com/inbox";
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
    startActivity(intent);
    
  • Other screens:

    facebook://facebook.com/inbox
    facebook://facebook.com/info?user=544410940     (id do usuário, somente numeros)
    facebook://facebook.com/wall
    facebook://facebook.com/wall?user=544410940   (irá mostrar apenas informações visiveis para amigos, caso contrário redireciona para outro activity)
    facebook://facebook.com/notifications
    facebook://facebook.com/photos
    facebook://facebook.com/album
    facebook://facebook.com/photo
    facebook://facebook.com/newsfeed
    

Using the official package

This is more complicated, but allows you some extra control

Using the default browser installed

The following code will use the default browser, it can facilitate if the user uses the browser to connect to facebook, because so it will probably already be logged in (I have not tested)

Uri uri = Uri.parse("http://www.facebook.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);

Using webView

The following code will use the webView:

WebView webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
setContentView(webview);

...

webview.loadUrl("http://facebook.com/");

In this case you can use the javascript interface to detect events or trigger events, just use addJavascriptInterface

 2
Author: Guilherme Nascimento, 2017-05-23 12:37:27