1

I want to navigate to a facebook fan page when I click on a button in my adroid application. I am new to android. Can anybody help me to do this.

CocoNess
  • 4,213
  • 4
  • 26
  • 43

3 Answers3

5

Why don't you try like this.

String url = "http://www.facebook.com/yourfanpagename";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

Place above code inside of your button click.

Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
1

Just use intents for it. Here is an example,

In your button's click event:

// Open Website
    Intent intent;

    try {
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/yourPage"));
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    } catch (Exception e) {
        Log.e("Exception Caught", e.toString());
    }

Hope this helps!!

Amit Jayant
  • 2,501
  • 2
  • 29
  • 38
1

You can do it in two ways:

  1. Using intent to open the browser, like this:

    String url = "http://www.facebook.com/your_page";
    Intent i = new Intent(Intent.ACTION_VIEW);
    
    i.setData(Uri.parse(url));
    startActivity(i);
    
  2. Use a webview in your layout and open a link in application.It is more preferable.

You can find the link here to implement it.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
AppMobiGurmeet
  • 719
  • 3
  • 6