My app uses app a FB AuthButton. If there is no FB app installed on the device, the user goes to m.facebook on a browser and logs in. If a current FB app is installed, the fb custom URL (fbconnect) lets the user log in with the FB app.
Older versions of the FB app do not recognize the custom URL and kick it over to a browser. (This problem: Facebook SDK 3.0 with old Facebook app version redirects to browser and gets stuck)
How can I check what version of the FB app is installed on the device? If I can do this then for older versions of the FB app I'll send to browser or use a webdialoug.
The closest I've found would be using getPackageManager().getApplicationInfo("com.example.name", 0) but I'm unsure if I can get it to return apk version.
context.getPackageManager().getPackageInfo(packageName,
PackageManager.GET_SIGNATURES).versionCode
does indeed return the facebook version code (which is different from the version name). After some digging around, we've found that Facebook version 1.9.8+ works, which is version code version code 40477+.
As we are using the deprecated Facebook.java class, we modified validateAppSignatureForPackage(), and it seems to work!
private boolean validateAppSignatureForPackage(Context context, String packageName)
{
PackageInfo packageInfo;
try
{
packageInfo = context.getPackageManager().getPackageInfo(packageName,
PackageManager.GET_SIGNATURES);
if(packageInfo.versionCode<40477)
{
Log.i("validateAppSignatureForPackage",
"Your facebook app version is prior to 1.9.8. Update your facebook app");
return false;
}
}
catch (NameNotFoundException e)
{
Log.i("validateAppSignatureForPackage", e.getMessage());
return false;
}
catch(Exception e)
{
Log.i("validateAppSignatureForPackage", e.getMessage());
return false;
}
for (Signature signature : packageInfo.signatures) {
if (signature.toCharsString().equals(FB_APP_SIGNATURE)) {
return true;
}
}
return false;
}
If you want to test this yourself, you can find previous versions of the facebook app here: http://www.androiddrawer.com/2274/download-facebook-for-android-1-9-7-app-apk/#.Uctn6Zwaux4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With