我有以下活动连接facebook
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook);
mFacebook = SavvyActivityDelegate.get().getFacebook(this);
if (mFacebook.isSessionValid()) {
// TODO GET FB ACCESS TOKEN
} else {
mFacebook.authorize(this, FacebookConstants.PERMISSIONS, new AppFacebookDialogListener(FacebookActivity.this,mFacebook));
}
public void onActivityResult(int request, int result, Intent data) {
super.onActivityResult(request, result, data);
mFacebook.authorizeCallback(request, result, data);
}
这里使用了对话框监听器
public class AppFacebookDialogListener implements Facebook.DialogListener {
private final Activity activity;
private final Facebook facebook;
public SavvyFacebookDialogListener(Activity activity, Facebook facebook) {
this.activity = activity;
this.facebook = facebook;
Log.d(LogTag.app, "Facebook constructor"); // activity.finish(); }
@Override public void onComplete(Bundle values) {
Log.d(LogTag.app, "Facebook authorization complete!");
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(activity).edit();
editor.putLong("fb_access_expires", facebook.getAccessExpires());
editor.putString("fb_access_token", facebook.getAccessToken());
editor.commit(); }
@Override public void onFacebookError(FacebookError e) {
Log.e(LogTag.app, e.getErrorType() + ": " + e.getMessage() + " (code: " + e.getErrorCode() + ")", e); }
@Override public void onError(DialogError e) {
Log.e(LogTag.app, e.getMessage(), e); }
@Override public void onCancel() {
Log.d(LogTag.app, "Facebook authorization was cancelled"); } }
活动开始时的日志声明
06-06 15:09:19.314:I / ActivityManager(404):从pid 17947开始u0 {cmp = com.biggu.shopsavvy / .FacebookActivity} 06-06 15:09:19.392:D / ShopSavvy(17947):Facebook构造函数 06-06 15:09:19.400:I / ActivityManager(404):从pid 17947开始u0 {cmp = com.facebook.katana / .ProxyAuth(有附加内容)} 06-06 15:09:19.415:I / ActivityManager(404):从pid 15214开始u0 {cmp = com.facebook.katana / .ProxyAuthDialog(有附加内容)}
因此,根据日志调用对话框构造函数,但不会调用任何回调方法。
如果没有安装Facebook应用程序,那么代码工作正常,我完成了回调授权,但代码在有facebook应用程序的设备上表现奇怪,用户已登录。提前谢谢。