我需要在我的小部件应用程序中实现 Facebook Like 功能。为此,我正在尝试从 SDK 实现 Facebook LikeView compile 'com.facebook.android:facebook-android-sdk:4.0.1'
。但不幸的是,我无法使用此视图,因为小部件使用 RemoteViews。因此,我完全坚持使用我应该遵循的方法来实现Facebook Like,Graph api
因为缺少用于此目的的文档。我正在发布我用于 Facebook 的代码,如下所示
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LikeView likeView = (LikeView) findViewById(R.id.likeView);
likeView.setLikeViewStyle(LikeView.Style.STANDARD);
likeView.setAuxiliaryViewPosition(LikeView.AuxiliaryViewPosition.INLINE);
likeView.setObjectIdAndType(
"https://www.facebook.com/JavaDigest/",
LikeView.ObjectType.OPEN_GRAPH);
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.facebooklike.MainActivity">
<com.facebook.share.widget.LikeView
android:id="@+id/likeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
AndroidManifest.xml
<meta-data
android:name="com.facebook.sdk.ApplicationName"
android:value="@string/app_name" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider2XXXXXXXXXXX85"
android:exported="true" />
任何对我很有帮助的帮助和替代解决方案。提前致谢。