当我点击它时,它启动了facebook登录活动,但是当我在facebook登录活动中点击OK时,facebook活动关闭但是从未调用onActivityResult.这是我的代码片段.请告诉我哪里出错了
public class FragmentLoginbuttonFacebook extends Fragment { private static final String LOG_TAG = FragmentLoginbuttonFacebook.class.getSimplename();; CallbackManager callbackManager; public FragmentLoginbuttonFacebook() { // required empty public constructor } @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getActivity().getApplicationContext()); callbackManager = CallbackManager.Factory.create(); LoginManager.getInstance().registerCallback(callbackManager,new FacebookCallback<LoginResult>() { @OverrIDe public voID onSuccess(LoginResult loginResult) { Toast.makeText(getActivity(),"success",Toast.LENGTH_SHORT).show(); } @OverrIDe public voID onCancel() { Toast.makeText(getActivity(),"cancel",Toast.LENGTH_SHORT).show(); } @OverrIDe public voID onError(FacebookException exception) { Toast.makeText(getActivity(),"error",Toast.LENGTH_SHORT).show(); } }); } @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { // Inflate the layout for this fragment VIEw vIEw = inflater.inflate(R.layout.fragment_login_facebook,container,false); button button = (button) vIEw.findVIEwByID(R.ID.facebookLoginbutton); button.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { LoginManager.getInstance().logInWithReadPermissions(getActivity(),Arrays.asList("public_profile","user_frIEnds")); } }); return vIEw; } @OverrIDe public voID onActivityResult(final int requestCode,final int resultCode,final Intent data) { super.onActivityResult(requestCode,resultCode,data); callbackManager.onActivityResult(requestCode,data); }}
>我没有在我的XML中使用Loginbutton.我正在创建自己的button.
>我的LogCat没有错误.
我是androID编程的新手.详细解释将有很大帮助.谢谢.
解决方法 我不确定,但这条线可能是原因 –LoginManager.getInstance().logInWithReadPermissions(getActivity(),Arrays.asList(“public_profile”,“user_frIEnds”));
改成:
LoginManager.getInstance().logInWithReadPermissions(这一点,
Arrays.asList("public_profile","user_frIEnds"));
LoginManager有两个方法–logInWithReadPermissions,一个采用Fragment另一个Activity:
public voID logInWithReadPermissions(Fragment fragment,Collection<String> permissions) { this.valIDateReadPermissions(permissions); Request loginRequest = this.createLoginRequest(permissions); this.startLogin(new LoginManager.FragmentStartActivityDelegate(fragment),loginRequest); } public voID logInWithReadPermissions(Activity activity,Collection<String> permissions) { this.valIDateReadPermissions(permissions); Request loginRequest = this.createLoginRequest(permissions); this.startLogin(new LoginManager.ActivityStartActivityDelegate(activity),loginRequest); }
最后你可以看到一个调用Fragments startActivityForResult和其他活动 –
public voID startActivityForResult(Intent intent,int requestCode) { this.fragment.startActivityForResult(intent,requestCode); }public voID startActivityForResult(Intent intent,int requestCode) { this.activity.startActivityForResult(intent,requestCode); }总结
以上是内存溢出为你收集整理的Android应用中未调用Facebook登录回调全部内容,希望文章能够帮你解决Android应用中未调用Facebook登录回调所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)