Facebook as a button in an Android application

I want to display as a button in an android application. Below is the code that I use to display the Like button in an Android app.

String url = "http://www.facebook.com/plugins/like.php?layout=standard&show_faces=true&width=80&height=50&action=like&colorscheme=light&href=http://beta.demo.dy/web/service/304.htm" webview = (WebView) findViewById(R.id.webView1); webview.loadUrl(url); webview.setWebViewClient(new LikeWebviewClient()); public class LikeWebviewClient extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } 

But when I run this application, it displays a white area. How to solve this problem?

+7
source share
6 answers

The Facebook SDK did not provide a like button function for its own mobile applications (as of October 17, 2011). It is available in mobile web applications. For more information, you can check this link:
Mobile - Facebook Developers
Like a button - Facebook developers

+4
source

A similar option can be easily implemented in languages ​​of native platforms (Android, iOS), as well as in browsers (curl, PHP, JavaScript) as follows. Go to the developer.facebook app section and in the Open Graph section of the App Developer configuration add a built-in Like action that should appear in the drop-down list when you add a new Open Graph action. For the latest updates see here .

After that, select "Get Code" to get a sample code, as shown below for the Android platform. You can choose the platform of your choice. Please note that app_specific_unique_identifier is unique to applications, I deleted it for security reasons, and you should use it for your application.

I was able to successfully test the Like stream. Hope this helps.

 Bundle params = new Bundle(); params.putString("object", "http://samples.ogp.me/<app_specific_unique_identifier>"); Request request = new Request( Session.getActiveSession(), "me/og.likes", params, HttpMethod.POST ); Response response = request.executeAndWait(); // handle the response 
+6
source

Finally, Facebook and launched Like Button for Android

Steps:

1 - Add Facebook Library to the project

2 - Create an application on Facebook 3 - Update the 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); } 

Exit enter image description here

+3
source

You can use facebook as a button in an Android application using special permission from the facebook developer account https://developers.facebook.com . Add your application here and send the special permission of the application. Go to the app overview and submit your content for approval. click on the start of the submission and after that select the LIKE native button and send all the details that they want, for example, why you want permission, how your application will use this permission for everything. If Facebook approves your request, you can use facebook as a button inside the application. enter code here

  <com.facebook.share.widget.LikeView android:id="@+id/facebooklike" android:layout_width="wrap_content" android:layout_height="wrap_content"> </com.facebook.share.widget.LikeView> 

After that you need to make java code.

 likeView = (LikeView) findViewById(R.id.facebooklike); likeView.setLikeViewStyle(LikeView.Style.STANDARD); likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE); likeView.setHorizontalAlignment(LikeView.HorizontalAlignment.CENTER); likeView.setObjectIdAndType("url of like page", LikeView.ObjectType.PAGE); 

how the function is automatically called when you click on the button you like.

now you need to get a response from the same page as the user who is similar to this page, unlike this page.

 enter code here 

Public class FbLikes extends AppCompatActivity {

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fb_likes); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); try { if (resultCode == RESULT_OK) { // verify we're returning from like action // get action results bundle = data.getExtras().getBundle("com.facebook.platform.protocol.RESULT_ARGS"); if (bundle != null) { like = bundle.getBoolean("object_is_liked");// liked/unliked bundle.getInt("didComplete"); bundle.getInt("like_count"); // object like count bundle.getString("like_count_string"); bundle.getString("social_sentence"); bundle.getString("completionGesture"); // liked/cancel/unliked Log.e(TAG, bundle.getString("social_sentence") + ""); Log.e(TAG, "likeornot" + bundle.getBoolean("object_is_liked") + ""); Log.e(TAG, "lcomplete" + bundle.getString("completionGesture") + ""); Log.e(TAG, "count" + bundle.getInt("like_count") + ""); Log.e(TAG, "countstr" + bundle.getString("like_count_string") + ""); Log.e(TAG, "did" + bundle.getInt("didComplete") + ""); } } } catch (Exception e) { } } 

} this code will return everything you need from similar functions.

+1
source

Try to do it, I made some changes

 String url = "http://www.facebook.com/plugins/like.php?layout=standard&show_faces=true&width=80&height=50&action=like&colorscheme=light&href=http://beta.demo.dy/web/service/304.htm"; // webview = (WebView) findViewById(R.id.webview); webView.loadUrl(url); webView.setWebViewClient(new WebViewClient()); class LikeWebviewClient extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } 
0
source

Facebook recently introduced the likebutton feature on facebook sdk 3.21.1. You can use these links to download sdk and the tutorial to implement the like button.

Download SDK: http://developers.facebook.com/docs/android

Tutorial http://developers.facebook.com/docs/android/like-button

I hope this can solve your problem.

0
source

All Articles