FileDocCategorySizeDatePackage
SharedLibraryMain.javaAPI DocAndroid 5.1 API3032Thu Mar 12 22:22:44 GMT 2015com.google.android.test.shared_library

SharedLibraryMain

public class SharedLibraryMain extends Object

Fields Summary
static String
LIBRARY_PACKAGE
public static int
VERSION_BASE
Base version of the library.
public static int
VERSION_SECOND
The second version of the library.
Constructors Summary
Methods Summary
public static booleanensureVersion(android.app.Activity activity, int minVersion)
Check that the library's version is at least the given minimum version, displaying a dialog to have the user install an update if that is not true. The dialog is displayed as a DialogFragment in your activity if a newer version is needed. If a newer version is needed, false is returned.

        final FragmentManager fm = activity.getFragmentManager();
        final String dialogTag = LIBRARY_PACKAGE + ":version";
        Fragment curDialog = fm.findFragmentByTag(dialogTag);

        if (getVersion(activity) >= minVersion) {
            // Library version is sufficient.  Make sure any version dialog
            // we had shown is removed before returning.
            if (curDialog != null) {
                fm.beginTransaction().remove(curDialog).commitAllowingStateLoss();
            }
            return true;
        }

        // The current version of the library does not meet the required version.
        // If we don't already have a version dialog displayed, display it now.
        if (curDialog == null) {
            curDialog = new VersionDialog();
            fm.beginTransaction().add(curDialog, dialogTag).commitAllowingStateLoss();
        }

        // Tell the caller that the current version is not sufficient.
        return false;
    
public static intgetVersion(android.content.Context context)
Return the version number of the currently installed library.


                  
         
        PackageInfo pi = null;
        try {
            pi = context.getPackageManager().getPackageInfo(LIBRARY_PACKAGE, 0);
            return pi.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            throw new IllegalStateException("Can't find my package!", e);
        }