Facebook SDK for Android - set Application ID programmatically

后端 未结 5 1165
逝去的感伤
逝去的感伤 2020-12-29 10:56

I have a native Android app that needs to connect to a different Facebook app (different Application ID) based on an app setting that can be changed at runtime.

Ima

5条回答
  •  不思量自难忘°
    2020-12-29 11:32

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

    And you're good to go. No need to create a session manually with the Builder and set it as the active session!

    Details of the Flaw:

    The facebookID you set in the settings class will be used by getMetadataApplicationId method of com.facebook.internal.Utility

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

    Which in turn will be used by all the 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");
    .
    .
    .
    }
    

    Cheers.

提交回复
热议问题