Facebook SDK for Android - application software identifier

I have my own Android application that needs to be connected to another Facebook application (another application identifier) ​​based on the application settings that can be changed at runtime.

Imagine an application can be configured to DEV, TEST or PROD. When pointing to DEV, the FB application identifier must be "1". When pointing to TEST, the FB application identifier must be "2". and etc.

The problem is that the UiLifecycleHelper from the Facebook SDK automatically reads "com.facebook.sdk.ApplicationId" from AndroidManifest.xml during the onCreate phase. There seems to be no way to install this programmatically.

Can I use the UiLifecycleHelper and point to a different application identifier at runtime, or do I need to return to manual session management?

+8
android facebook-android-sdk
source share
6 answers

I decided to develop the facebook-android-sdk project on GitHub and make the necessary changes. I sent a transfer request with my changes, if anyone is interested, https://github.com/facebook/facebook-android-sdk/pull/294 .

+3
source share

Hi everyone I know above is suitable for older sdk version , but facebook sdk 4 does not have Session class

You can simply do this using this code:

 FacebookSdk.setApplicationId(APP_ID); 

Thanks!

+23
source share

Here I used to set the application id programatcally

  private Session.StatusCallback statusCallback = new SessionStatusCallback(); protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String s=""+R.string.app_id; Session session = new Session.Builder(getBaseContext()).setApplicationId(s).build(); Session.setActiveSession(session); if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) { session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback)); } } private class SessionStatusCallback implements Session.StatusCallback { @Override public void call(Session session, SessionState state, Exception exception) { // TODO Auto-generated method stub if(session.isOpened()){ //Do your task } } } 
+13
source share

Yes, you can install it programmatically. Use the Session $ Builder class, which allows you to create a session without using one of the private constructors.

 Session session = new Session.Builder(context).setApplicationId(applicationId).build(); 
+3
source share

I think there is an easier way to do this, just call the static method setApplicationId com.facebook.Settings.setApplicationId(facebookID);

And you are good to go. No need to create a session manually using Builder and set it up as an active session!

Information about the disadvantage:

The facebookID user interface specified in the settings class will be used by the getMetadataApplicationId com.facebook.internal.Utility method

 public static String getMetadataApplicationId(Context context) { Validate.notNull(context, "context"); Settings.loadDefaultsFromMetadata(context); return Settings.getApplicationId(); } 

Which, in turn, will be used by all calls to create a session:

 Session(Context context, String applicationId, TokenCachingStrategy tokenCachingStrategy, boolean loadTokenFromCache) { // if the application ID passed in is null, try to get it from the // meta-data in the manifest. if ((context != null) && (applicationId == null)) { applicationId = Utility.getMetadataApplicationId(context); } Validate.notNull(applicationId, "applicationId"); . . . } 

Greetings.

+2
source share

You can’t just branch out the SDK and add these changes yourself?

0
source share

All Articles