1

我已经使用片段和 viewpager 实现了选项卡布局。但是,在我的第五个选项卡上,我想在第三个选项卡上分享用户在谷歌地图上的位置。这是我的“在 Facebook 上分享”标签的代码。

TabFour.java

public class TabFour extends Fragment {
private UiLifecycleHelper uiHelper;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.activity_tab_four, container, false);

    return rootView;
}

public void onActivityCreated(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     uiHelper = new UiLifecycleHelper(this, callback);
        uiHelper.onCreate(savedInstanceState);

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
        @Override
        public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
            Log.e("Activity", String.format("Error: %s", error.toString()));
        }

        @Override
        public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
            Log.i("Activity", "Success!");
        }
    });
}



@Override
public void onResume() {
    super.onResume();
    uiHelper.onResume();
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}

@Override
public void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}
private Session.StatusCallback callback = new Session.StatusCallback() {


    @Override
    public void call(Session session, SessionState state,
            Exception exception) {
        // TODO Auto-generated method stub

    }
};

}

但是,这一行有一个错误:

 uiHelper = new UiLifecycleHelper(this, callback);

错误说:

 The constructor UiLifecycleHelper(TabFour, Session.StatusCallback) is undefined

可能是什么问题?Facebook Developers 上没有其他用于 UiLifecycleHelper 的方法。请帮忙。谢谢!

4

4 回答 4

0

我知道我回复晚了,但我希望这会帮助所有其他人..在你的片段类中调用这个..

FragmentActivity activity=getActivity();

现在在 UiLifeCycleHelper 构造函数中,传递活动而不是“this”

uiHelper=new UiLifeCycleHelper(activity, CallBack);
于 2014-08-02T07:47:04.713 回答
0

那是因为this您使用的是 Fragment,而不是 Activity,这是构造函数所需要的。尝试替换thisgetActivity(或者如果您使用的是 ABS,getSherlockActivity

于 2014-03-18T01:20:02.613 回答
0

文件说:

public UiLifecycleHelper(Activity activity, Session.StatusCallback callback)

创建一个新的 UiLifecycleHelper。参数

活动:与助手关联的活动。如果从 Fragment 调用,使用 Fragment.getActivity() 回调:Session 状态变化的回调,可以为 null

有关更多信息,您可以查看此链接:

https://developers.facebook.com/docs/reference/android/current/UiLifecycleHelper

于 2013-12-09T05:09:32.183 回答
0

在 Facebook SDK 4.x 上,UiLifecycleHelper 被 CallbackManager 取代。现在在片段中实现 Facebook 分享对话框更容易:

1) OnCreateView 在您的片段类中:

 CallbackManager mCallbackManagerFacebook;

// Facebook Share
mCallbackManagerFacebook = CallbackManager.Factory.create();

2)在您的应用程序类中:

// Facebook
FacebookSdk.sdkInitialize(getApplicationContext());

3)在您的片段类中覆盖 onActivityResult :

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);

            mCallbackManagerFacebook.onActivityResult(requestCode, resultCode, data);
 }

4)例如,您有一个按钮,用户可以通过 OnClickListener 分享照片:

ImageButton fbBtn = (ImageButton) v.findViewById(R.id.facebookHomeDetailButton);
        fbBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                mProgressBar.setSpinSpeed(10);
                mProgressBar.setVisibility(View.VISIBLE);
                mProgressBar.spin();

                if (ShareDialog.canShow(ShareLinkContent.class)) {

                    ParseFile fileObject = (ParseFile)mParseObjectsList.get(mPosition).get("thumbnail");

                    fileObject.getDataInBackground(new GetDataCallback() {
                        public void done(byte[] data, ParseException e) {
                            if (e == null) {
                                Log.d("test", "We've got data in data.");

                                Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                                SharePhoto photo = new SharePhoto.Builder()
                                        .setBitmap(bitmap)
                                        .build();

                                SharePhotoContent content = new SharePhotoContent.Builder()
                                        .addPhoto(photo)
                                        .build();

                                mShareDialogFacebook.show(getActivity(), content);

                                mProgressBar.stopSpinning();
                                mProgressBar.setVisibility(View.INVISIBLE);


                            } else {

                                Log.d("test", "There was a problem downloading the data.");

                            }

                        }

                    });


                } else {

                    showDialogWithOk("¡Ooops!\nParece que no tienes Facebook instalado en tu dispositivo. Para compartir tendrías que instalar esta aplicación en tu dispositivo.\n¡Gracias!");

                }






            }
        });

5) 仅此而已。我希望这段代码可以提供帮助。

于 2015-07-03T09:42:38.863 回答