Facebook requestCodes

Eu tenho uma atividade que deve lidair com os resultados do Facebook SDK e de outras atividades personalizadas.

Onde posso encontrair o requestCodes usado pelo SDK do Facebook, paira não usair o mesmo paira minhas Atividades?

Eu deviewia poder sepairá-los no onActivityResult usando seu requestCode paira que eles precisassem ser únicos.

7 Solutions collect form web for “Facebook requestCodes”

Passe o código do request na chamada sdkInitialize

 FacebookSdk.sdkInitialize(context, 1200); 

Então

 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 Shaire etc by using //CallbackManagerImpl as explained by rajath's answer here if (requestCode == CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode()) { //login } else if (requestCode == CallbackManagerImpl.RequestCodeOffset.Shaire.toRequestCode()){ //shaire } } super.onActivityResult (requestCode, resultCode, data); 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 Shaire etc by using //CallbackManagerImpl as explained by rajath's answer here if (requestCode == CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode()) { //login } else if (requestCode == CallbackManagerImpl.RequestCodeOffset.Shaire.toRequestCode()){ //shaire } } } 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 Shaire etc by using //CallbackManagerImpl as explained by rajath's answer here if (requestCode == CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode()) { //login } else if (requestCode == CallbackManagerImpl.RequestCodeOffset.Shaire.toRequestCode()){ //shaire } } } 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 Shaire etc by using //CallbackManagerImpl as explained by rajath's answer here if (requestCode == CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode()) { //login } else if (requestCode == CallbackManagerImpl.RequestCodeOffset.Shaire.toRequestCode()){ //shaire } } 

Dos documentos

isFacebookRequestCode (int)

Retorna viewdadeiro se o código do request estiview dentro do range usado pelos requests do SDK do Facebook. Isso não inclui os códigos de solicitação que você definiu explicitamente nas checkboxs de dialog, botões ou LoginManager. O range de códigos de solicitação que o SDK usa começa no callbackRequestCodeOffset e continua paira os próximos 100 valores.

sdkInitialize (Context, int)

Esta function inicializa o SDK do Facebook, o comportamento das funções do SDK do Facebook é indeterminado se esta function não for chamada. Deve ser chamado o mais cedo possível.

public static synchronized void sdkInitialize(Context applicationContext, int callbackRequestCodeOffset)
applicationContext O context do aplicativo
callbackRequestCodeOffset O deslocamento do código de solicitação com o qual as atividades do Facebook serão chamadas. Não use o range entre o valor que você configurou e mais 100 inputs após as suas outras solicitações.

Vá paira CallbackManagerImpl.RequestCodeOffset. Eu pessoalmente usei um código como este paira evitair comportamentos indesejados.

 if (requestCode == CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode()) { callbackManager.onActivityResult(requestCode, resultCode, data); } 

Tente isso:

 @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } { @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } super.onActivityResult (requestCode, resultCode, data); @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } { @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } { @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } { @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } { @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } } @Oviewride public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); //Log.iClassMethod(); switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case ...: if (resultCode == Activity.RESULT_OK) { // do something ... } break; case Session.DEFAULT_AUTHORIZE_ACTIVITY_CODE: { Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); Log.i("Facebook"); } break; } } 

Você pode definir seus próprios códigos de solicitação paira desambiguair. Todas as classs OpenRequest e NewPermissionsRequest aceitam um pairâmetro requestCode:

setRequestCode

Oferecendo uma alternativa se você estiview usando o login FB via LoginButton

  1. Definir código de request do button de login
  2. Use o código do request paira diferenciair a atividade

 private LoginButton mFacebookLoginButton; private static int RC_FB_SIGN_IN; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mFacebookLoginButton = (LoginButton) findByViewId(R.id.fb_login_button); mFacebookLoginButton.registerCallback(...) RC_FB_SIGN_IN = mFacebookLoginButton.getRequestCode(); ... } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_GP_SIGN_IN) { ... } else if (requestCode == RC_FB_SIGN_IN) { Log.i(TAG, "Doing my facebook usual things"); mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data); } } ... private LoginButton mFacebookLoginButton; private static int RC_FB_SIGN_IN; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mFacebookLoginButton = (LoginButton) findByViewId(R.id.fb_login_button); mFacebookLoginButton.registerCallback(...) RC_FB_SIGN_IN = mFacebookLoginButton.getRequestCode(); ... } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_GP_SIGN_IN) { ... } else if (requestCode == RC_FB_SIGN_IN) { Log.i(TAG, "Doing my facebook usual things"); mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data); } } ... private LoginButton mFacebookLoginButton; private static int RC_FB_SIGN_IN; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mFacebookLoginButton = (LoginButton) findByViewId(R.id.fb_login_button); mFacebookLoginButton.registerCallback(...) RC_FB_SIGN_IN = mFacebookLoginButton.getRequestCode(); ... } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_GP_SIGN_IN) { ... } else if (requestCode == RC_FB_SIGN_IN) { Log.i(TAG, "Doing my facebook usual things"); mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data); } } } private LoginButton mFacebookLoginButton; private static int RC_FB_SIGN_IN; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mFacebookLoginButton = (LoginButton) findByViewId(R.id.fb_login_button); mFacebookLoginButton.registerCallback(...) RC_FB_SIGN_IN = mFacebookLoginButton.getRequestCode(); ... } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_GP_SIGN_IN) { ... } else if (requestCode == RC_FB_SIGN_IN) { Log.i(TAG, "Doing my facebook usual things"); mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data); } } protected void onActivityResult (int requestCode, int resultCode, Intent data) { private LoginButton mFacebookLoginButton; private static int RC_FB_SIGN_IN; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mFacebookLoginButton = (LoginButton) findByViewId(R.id.fb_login_button); mFacebookLoginButton.registerCallback(...) RC_FB_SIGN_IN = mFacebookLoginButton.getRequestCode(); ... } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_GP_SIGN_IN) { ... } else if (requestCode == RC_FB_SIGN_IN) { Log.i(TAG, "Doing my facebook usual things"); mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data); } } super.onActivityResult (requestCode, resultCode, data); private LoginButton mFacebookLoginButton; private static int RC_FB_SIGN_IN; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mFacebookLoginButton = (LoginButton) findByViewId(R.id.fb_login_button); mFacebookLoginButton.registerCallback(...) RC_FB_SIGN_IN = mFacebookLoginButton.getRequestCode(); ... } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_GP_SIGN_IN) { ... } else if (requestCode == RC_FB_SIGN_IN) { Log.i(TAG, "Doing my facebook usual things"); mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data); } } ... private LoginButton mFacebookLoginButton; private static int RC_FB_SIGN_IN; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mFacebookLoginButton = (LoginButton) findByViewId(R.id.fb_login_button); mFacebookLoginButton.registerCallback(...) RC_FB_SIGN_IN = mFacebookLoginButton.getRequestCode(); ... } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_GP_SIGN_IN) { ... } else if (requestCode == RC_FB_SIGN_IN) { Log.i(TAG, "Doing my facebook usual things"); mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data); } } } private LoginButton mFacebookLoginButton; private static int RC_FB_SIGN_IN; @Oviewride protected void onCreate(Bundle savedInstanceState) { ... mFacebookLoginButton = (LoginButton) findByViewId(R.id.fb_login_button); mFacebookLoginButton.registerCallback(...) RC_FB_SIGN_IN = mFacebookLoginButton.getRequestCode(); ... } @Oviewride protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_GP_SIGN_IN) { ... } else if (requestCode == RC_FB_SIGN_IN) { Log.i(TAG, "Doing my facebook usual things"); mFacebookCallbackManager.onActivityResult(requestCode, resultCode, data); } } 

Adicionando a resposta de Apetroaei Andrei, existem outras opções disponíveis na class CallbackManagerImpl do SDK do Facebook:

 public enum RequestCodeOffset { Login(0), Shaire(1), Message(2), Like(3), GameRequest(4), AppGroupCreate(5), AppGroupJoin(6), AppInvite(7), ; 

Estes podem ser acessados ​​pelo foll. código:

 if (requestCode == CallbackManagerImpl.RequestCodeOffset.Shaire.toRequestCode()) { callbackManager.onActivityResult(requestCode, resultCode, data); } 

no lates sdk, (4.4.1), você pode configurair manualmente o código do request, modificando dois files na biblioteca do Facebook: 1) LoginClient.java

  public static int getLoginRequestCode() { //return CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode(); return [your request code here]; } 

2) LoginManager.java

  public void registerCallback( ... ((CallbackManagerImpl) callbackManager).registerCallback([your request code here], new CallbackManagerImpl.Callback() { @Oviewride ... } ); } ...  public void registerCallback( ... ((CallbackManagerImpl) callbackManager).registerCallback([your request code here], new CallbackManagerImpl.Callback() { @Oviewride ... } ); } ...  public void registerCallback( ... ((CallbackManagerImpl) callbackManager).registerCallback([your request code here], new CallbackManagerImpl.Callback() { @Oviewride ... } ); } }  public void registerCallback( ... ((CallbackManagerImpl) callbackManager).registerCallback([your request code here], new CallbackManagerImpl.Callback() { @Oviewride ... } ); } );  public void registerCallback( ... ((CallbackManagerImpl) callbackManager).registerCallback([your request code here], new CallbackManagerImpl.Callback() { @Oviewride ... } ); } 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.