Advertisement
Sketchware

Abrir Facebook

Jan 9th, 2023
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.72 KB | None | 0 0
  1. Button button = (Button) findViewById(R.id.button);
  2. button.setOnClickListener(new View.OnClickListener() {
  3.     @Override
  4.     public void onClick(View v) {
  5.         String facebookUrl = "https://www.facebook.com";
  6.         try {
  7.             Intent i = new Intent(Intent.ACTION_VIEW);
  8.             String facebookUrlScheme = "fb://facewebmodal/f?href=" + facebookUrl;
  9.             i.setData(Uri.parse(facebookUrlScheme));
  10.             startActivity(i);
  11.         } catch (Exception e) {
  12.             // Abrir o link no navegador se o aplicativo do Facebook não estiver instalado
  13.             Intent i = new Intent(Intent.ACTION_VIEW);
  14.             i.setData(Uri.parse(facebookUrl));
  15.             startActivity(i);
  16.         }
  17.     }
  18. });
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement