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

47 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
  18. A backlink is a link created when one website links to another. Backlinks are important to SEO & impact for higher ranking. In my 7+ years seo Career i see, without backlinks a website doesn't rank higher on google SERP.

    Get Your 300+ High Quality DoFollow Backlinks Here!

    Order Now with Full Confidence & 100% satisfaction.

    ReplyDelete
  19. With Brandsoo, it’s never been easier or more convenient to shop high quality domain names and professional logos that’ll instantly give your brand a domain names for sale leg up and resonate with your audience! With many different domain sellers all competing for your business, you need to know where your business and brand will see.

    ReplyDelete
  20. The data science field is quickly emerging in India. Many startups are focusing on relevant technologies. 360DigiTMG data science training in hyderabad

    ReplyDelete
  21. Forex Signals, MT4 and MT5 Indicators, Strategies, Expert Advisors, Forex News, Technical Analysis and Trade Updates in the FOREX IN WORLD

    Forex Signals Forex Strategies Forex Indicators Forex News Forex World

    ReplyDelete
  22. Forex Signals, MT4 and MT5 Indicators, Strategies, Expert Advisors, Forex News, Technical Analysis and Trade Updates in the FOREX IN WORLD

    Forex Signals Forex Strategies Forex Indicators Forex News Forex World

    ReplyDelete
  23. Situs Judi bola online UFA88 Terpercaya, juga memiliki casino online seperti, baccarat, roulette, Judi slot online, sabung ayam dan dadu online.

    ReplyDelete
  24. Adam the alien - Animated films A close encounter with a likable robot from another solar system leads to a star-crossed friendship Do aliens exist and an impossible intergalactic mission to save Extraterrestrial life the robot’s friends— despite overwhelming New cartoon movies odds.

    ReplyDelete
  25. TogelResult.info - Adalah Situs data hk Khusus yang menyediakan Daftar keluaran hk Result Nomor Togel dan Data hasil keluaran live draw hk seperti hk sgp sydney yang sudah terpercaya keluaran togel hk.

    ReplyDelete
  26. Thanks for the Information.Interesting stuff to read.Great Article.
    I enjoyed reading your post, very nice share.
    Data Science Course Training in Hyderabad

    ReplyDelete
  27. Shield Security Solutions Provides Ontario Security Training, Security Guard License or Security License in Ontario. Get Started Today

    ReplyDelete
  28. Very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, data sciecne course in hyderabad

    ReplyDelete
  29. Very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, data scientist courses

    ReplyDelete
  30. This Was An Amazing ! I Haven't Seen This Type of Blog Ever ! Thankyou For Sharing, data science course in hyderabad with placements

    ReplyDelete
  31. Vince Offer is and actor, producer and infomercial star. He is the best known infomercial star in the world. His products the SHAMWOW, InVINCEable, SlapChop, Schticky and more have sold millions. Vince Offer has also produced and starred in the films Underground Comedy Movie and The Inappropriate Comedy with Adrian Brody, Dante and Michelle Rodriguez.

    ReplyDelete
  32. Very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, best data science courses in hyderabad

    ReplyDelete
  33. Very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, data science online training

    ReplyDelete
  34. Very nice blogs!!! i have to learning for lot of information for this sites…Sharing for wonderful information.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing, data sciecne course in hyderabad

    ReplyDelete
  35. Website laten maken? Onze professionals bouwen een omzetverhogende, professionele én unieke website of webshop! Een website laten maken kan vandaag nog

    Website laten maken | webdesigner | website freelancer | webdeveloper | webdesigner

    ReplyDelete
  36. Discover antimicrobial protection that’s built-in right into the finish of select TikTok Locksmith Services.

    ReplyDelete
  37. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts.
    data science training in Hyderabad

    ReplyDelete