Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
339 views
in Technique[技术] by (71.8m points)

android facebook like

I want to integrate a like button in my android app. I used the code

likeWebView = (WebView) findViewById( R.id.webView1 );
 likeWebView.getSettings().setJavaScriptEnabled(true);
 String url = "http://www.facebook.com/plugins/like.php?" +
           "href=" + URLEncoder.encode("likeurl" ) + "&" +
           "layout=standard&" +
           "show_faces=false&" +
           "width=500&" +
           "action=like&" +
           "colorscheme=light&" +
           "access_token=" + URLEncoder.encode( "read_stream" );
likeWebView.loadUrl( url );

But after login it is showing a blank page. Please give me a solution to add a Like button.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Finally Facebook and Launched Like Button for Android

Steps:

1 - Add Facebook Library to Project

2 - Create App on Facebook 3 - Update Manifest

**In the Application tab add meta-data**

<meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/fb_id" />

4 - Add LikeView in Layout

//activitymain.xml
<com.facebook.widget.LikeView
            android:id="@+id/like_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            >
        </com.facebook.widget.LikeView>

5 - ActivityMain.java

//set facebook page or link to this like button
LikeView likeView;
UiLifecycleHelper uiHelper;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activitymain);
    uiHelper = new UiLifecycleHelper(this, null);
    likeView = (LikeView) findViewById(R.id.like_view);
    likeView.setObjectId("https://www.facebook.com/<page_username>");//it can be any link

    likeView.setLikeViewStyle(LikeView.Style.STANDARD);
    likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
    likeView.setHorizontalAlignment(LikeView.HorizontalAlignment.LEFT);

}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    uiHelper.onActivityResult(requestCode, resultCode, data, null);

}

Output enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...