June 12, 2014

How to add Facebook 'Like' button in Android app?

Official Facebook SDK does not provide implementation of theirs plugin 'Like' for Android. There is just html-plugin designed for web-sites and applications. Let's try to adapt this plugin for Android!

In this post we will look at the two things:

Using Facebook 'Like' button for single page

Just add single-line dependency in your gradle project:

dependencies {
    compile 'com.shamanland:facebook-like-button:0.1.8'
}

This library contains several widgets:

FacebookLikeButton - button which opens FacebookLikeActivity by clicking on it.


FacebookLikeBox - button with a specific background and with ability to check 'likes' count of your url.


FacebookLikePlugin - container which combines both FacebookLikeButton and FacebookLikeBox in different variations.


So, first you need is to include FacebookLikeButton with specified style in your layout:

<com.shamanland.facebook.likebutton.FacebookLikeButton
    style="@style/Widget.FacebookLikeButton"
    />

Before configuring your button you need to add app xml namespace into the root node:

xmlns:app="http://schemas.android.com/apk/res-auto"


Add following attributes to your button: pageUrl - original url of page which should to be liked, pageTitle - title of this page, pageText - short description of page, pagePictureUrl - url of page picture.

<com.shamanland.facebook.likebutton.FacebookLikeButton
    style="@style/Widget.FacebookLikeButton"
    app:pageUrl="http://your.site.com/page.html"
    app:pageTitle="Title of your page"
    app:pageText="Short description of your page"
    app:pagePictureUrl="http://your.site.com/picture.png"
    />

For example:



Do not forget to declare FacebookLikeActivity in your AndroidManifest.xml:

<activity
    android:name="com.shamanland.facebook.likebutton.FacebookLikeActivity"
    android:label="@string/com_shamanland_facebook"
    android:theme="@style/Theme.Facebook.Like"
    />

Make sure that you have internet permission:

<uses-permission android:name="android.permission.INTERNET"/>

That's all! Now you can compile and launch your app. When user clicks 'Like' button, then he will see WebView with official web-plugin 'Like' from Facebook:

Now, if you want to include box with count of 'likes' - you should use FacebookLikePlugin:

<com.shamanland.facebook.likebutton.FacebookLikePlugin
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
    <com.shamanland.facebook.likebutton.FacebookLikeButton
        style="@style/Widget.FacebookLikeButton"
        app:pageUrl="http://your.site.com/page.html"
        app:pageTitle="Title of your page"
        app:pageText="Short description of your page"
        app:pagePictureUrl="http://your.site.com/picture.png"
        />
    <com.shamanland.facebook.likebutton.FacebookLikeBox
        style="@style/Widget.FacebookLikeBox"
        app:calloutMarker="left"
        />
</com.shamanland.facebook.likebutton.FacebookLikePlugin>

Modified example:


Note about attribute calloutMarker: if you re-arrange 'like' and 'box' buttons, then you need to select corresponding value for calloutMarker: left, top, right, bottom.

Using Facebook 'Like' button in the ListView


There is no fundamental difference between single button and buttons inside ListView. You need just to set up button inside your Adapter.getView() method.

Use corresponding getters of class FacebookLikeButton: setPageUrl(), setPageTitle(), setPageText(), setPagePictureUrl().

NOTE: @style/Widget.FacebookLikeButton already has item android:id with the value R.id.com_shamanland_facebook_like. Use this value with method findViewById(). You can also override android:id in xml to use your own value.

Check this code example from library sources:
Well, I hope my library will help somebody to make awesome app with social features. Feel free to ask me anything, subscribe to repository and check for updates.

Project page: http://blog.shamanland.com/p/facebook-like-button.html
Sources: https://github.com/shamanland/facebook-like-button

24 comments:

  1. Whenever progressed admirably, endeavor versatile apps help business activities run all the more proficiently all through the associations and drive ROI. https://iphoneappdevelopmentcompany.com/ Be that as it may, associations center around the wrong approach to big business apps.

    ReplyDelete
  2. Situs terbaik yang harus anda pilih adalah yang memang memiliki jaminan keamanan. Jaminan keamanan ini menjadi bagian yang sangat penting sekali dan sudah sebaiknya dan sewajarnya untuk anda bisa mendapatkannya
    asikqq
    http://dewaqqq.club/
    http://sumoqq.today/
    interqq
    pionpoker
    bandar ceme
    freebet tanpa deposit
    paito warna terlengkap
    syair sgp

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Free Android App Maker is extraordinary compared to other free utility to make an android application. Here one can submit Android application at application store in only couple of minutes.
    https://appcloner.app
    https://appcloner.net

    ReplyDelete
  5. This is my first time i visit here and I found so many interesting stuff in your blog especially it's discussion, thank you. appcloner's website

    ReplyDelete
  6. Mobile developers are finding the platform extremely user-friendly. In the second quarter of the year 2012, approximately 105 million Android smartphones have been sold which represents an overall share of 68% of smartphone sales figures until that quarter.Cheat Engine APK

    ReplyDelete
  7. This is the first & best article to make me satisfied by presenting good content. I feel so happy and delighted.By Learn Digital Marketing Course Training in Chennai it will help to get Digital Marketing Course Training with Placement Institute in Chennai. If you Learn Social Media Marketing Training with Placement Institute in Chennai, you will get job soon.

    Learn Best Digital Marketing Course Training in Chennai in professional institute to get reputed job.

    ReplyDelete
  8. Contact them and tell them your requirement and ask them whether they can develop a mobile application as per your requirement at an affordable cost or not?Best Mobile app development Companies in India

    ReplyDelete
  9. Thank you for another great article. Where else could anyone get that kind of information in such a perfect way of writing? I have a presentation next week, and I am on the look for such information. hack facebook

    ReplyDelete
  10. To make Android advertise increasingly well known Android Application are free for everybody, he/she can download from various site. A large number of free apps been downloaded every day by Android client. Bulk SMS Service Provider in Sharjah UAE

    ReplyDelete

  11. You write this post very carefully I think, which is easily understandable to me. Not only this, but another post is also good. As a newbie, this info is really helpful for me. Thanks to you.
    Tally ERP 9 Training
    tally classes
    Tally Training institute in Chennai
    Tally course in Chennai

    ReplyDelete
  12. Pergi untuk taruhan luar, bukan yang di dalam. Menang dalam roulette mungkin bukan dalam memilih nomor yang menang tetapi dalam memilih apakah nomor yang menang berada di bawah
    98toto

    ReplyDelete
  13. As an enterprise mobile app developer, your app should endeavor to come with proper authentication plans, server-side validation, and encryption of essential data to overcome these security issues.Best Mobile App development Companies in UK

    ReplyDelete
  14. As a matter of fact, the users want their favorite brands and companies to develop their own mobile applications for a customized user experience.Smart AudioBook Player Pro

    ReplyDelete
  15. Developing apps for the Android gives a set of choice to developers, and right to use to an ever-growing customer pedestal to the app proprietor. However, android developers face challenges in the development process.navigate here

    ReplyDelete
  16. even a novice with absolutely no technical knowledge can go ahead and perform the conversion with ease using the Free FLV to MP4 Converter. file converter

    ReplyDelete
  17. Being an open source stage, it tends to be introduced by any telephone producer, that makes the assembling cost of these telephones a lot lesser than the telephones having their own OS or any that is paid. itools crack


    ReplyDelete