3

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.

Community
  • 1
  • 1
SAR622
  • 617
  • 1
  • 7
  • 17
  • possible duplicate of [Facebook SDK 3.0 with old Facebook app version redirects to browser and gets stuck](http://stackoverflow.com/questions/17131868/facebook-sdk-3-0-with-old-facebook-app-version-redirects-to-browser-and-gets-stu) – thepoosh Jun 30 '13 at 11:55

1 Answers1

3
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

cowlinator
  • 7,195
  • 6
  • 41
  • 61
  • 2
    If you're not using the depecated `Facebook.java`, then you should modify the `validateSignature` method in `NativeProtocol.java`. – Egor Neliuba Aug 09 '13 at 10:08