Search code examples
androidfacebook-like

Adding facebook like button to Android app to redirect to a facebook fan page


I am working on an android app and would like to add a facebook like button, that when clicked, redirects the user to the apps fan page on facebook, is there a way to this.


Solution

  • create ImageView that uses facebook like button as image and set its OnClickListener to your own implementation that starts activity with Intent thats action is ACTION_VIEW and Uri your facebook like page. That would look something like this:

    ImageButton img = new ImageButton(this);
    //set img's image to the fb like image
    
    img.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent open = new Intent(Intent.ACTION_VIEW, Uri.parse("http://..."));
            startActivity(open);
        }
    });