gpt4 book ai didi

android - Facebook 请求代码

转载 作者:IT王子 更新时间:2023-10-28 23:27:09 25 4
gpt4 key购买 nike

我有一个 Activity 应该处理来自 Facebook SDK 和其他自定义 Activity 的结果。

我在哪里可以找到 Facebook SDK 使用的 requestCodes,以免将其用于我的 Activity ?

我应该能够使用它们的 requestCode 在 onActivityResult 中区分它们,因此它们需要是唯一的。

最佳答案

sdkInitialize调用中传递请求代码

FacebookSdk.sdkInitialize(context, 1200);

然后

public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (FacebookSdk.isFacebookRequestCode(requestCode)) {
//Facebook activity result
//Do your stuff here
//Further you can also check if it's login or Share etc by using
//CallbackManagerImpl as explained by rajath's answer here
if (requestCode == CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode()) {
//login
}
else if (requestCode == CallbackManagerImpl.RequestCodeOffset.Share.toRequestCode()){
//share
}
}

来自 the docs

isFacebookRequestCode(int)

Returns true if the request code is within the range used by Facebook SDK requests. This does not include request codes that you explicitly set on the dialogs, buttons or LoginManager. The range of request codes that the SDK uses starts at the callbackRequestCodeOffset and continues for the next 100 values.

sdkInitialize(Context, int)

This function initializes the Facebook SDK, the behavior of Facebook SDK functions are undetermined if this function is not called. It should be called as early as possible.

public static synchronized void sdkInitialize(Context applicationContext, int callbackRequestCodeOffset)
applicationContext The application context
callbackRequestCodeOffset The request code offset that Facebook activities will be called with. Please do not use the range between the value you set and another 100 entries after it in your other requests.

关于android - Facebook 请求代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17772806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com