Skip to content

Instantly share code, notes, and snippets.

@r2DoesInc
Created March 19, 2014 14:23
Show Gist options
  • Save r2DoesInc/9642647 to your computer and use it in GitHub Desktop.
Save r2DoesInc/9642647 to your computer and use it in GitHub Desktop.
Set Facebook app id based on signature
In the Facebook SDK, find Utility.java and modify the method getMetadataApplicationId as follows, where TESTING_KEY is the signature of the Android DEBUG key on your machine that Eclipse uses when you select the "Run" option.
If the code detects youre using that DEBUG key, it uses one of the sample Facebook SDK app ids, otherwise it uses the value defined in the manifest. Useful to avoid having to change the app id when compiling a release candidate vs an internal testing build generated by Eclipse.
public static String getMetadataApplicationId(Context context) {
Validate.notNull(context, "context");
Signature[] appSigs;
try {
appSigs = context.getPackageManager().getPackageInfo(
context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
for (Signature sig : appSigs) {
if (sig.hashCode() == TESTING_SIG) {
return "380615018626574";
}
}
ApplicationInfo ai = context.getPackageManager()
.getApplicationInfo(context.getPackageName(),
PackageManager.GET_META_DATA);
if (ai.metaData != null) {
return ai.metaData.getString(Session.APPLICATION_ID_PROPERTY);
}
} catch (Exception e) {
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment