Skip to content Skip to sidebar Skip to footer

Can I Make An Android App That Runs A Web View In Chrome 39?

I'm developing an Android app that's a web page embedded inside of a web view. The web page makes use of the web audio API. It looks like Chrome 39 for Android supports that API, b

Solution 1:

You can use the PackageManager to query if chrome (com.android.chrome) is installed and then retrieve the version info.

try {
    // Get installed Chrome package info
    String chromePackageName = "com.android.chrome";
    PackageInfo info = getPackageManager().getPackageInfo(chromePackageName, 0);

    // Check the version number
    int versionMajor = Integer.parseInt(info.versionName.subString(0, 2));
    if(versionMajor < 39) {
        // Chrome is installed but not updated, prompt user to update it
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + chromePackageName)));
    } else {
        // Chrome is installed and at or above version 39, launch the page
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://YourURLHere")));
    }
} catch (NameNotFoundException e) {
    // Chrome isn't installed, prompt the user to download it.
    startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + chromePackageName)));

} catch (NumberFormatException e) {
    // Something funky happened since the first two chars aren't a number
}

Post a Comment for "Can I Make An Android App That Runs A Web View In Chrome 39?"