我可以运行在Chrome 39的Web视图中的Andr​​oid应用程序? [英] Can I make an Android app that runs a web view in Chrome 39?

查看:219
本文介绍了我可以运行在Chrome 39的Web视图中的Andr​​oid应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款Android应用,嵌入式Web视图里面的网页。该网页使用了网络音频API的。它看起来像的Chrome 39,Android支持的API,但没有版本基本的Andr​​oid浏览器的作用: HTTP ://caniuse.com/#search=web%20audio%20api

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, but no version of the basic Android browser does: http://caniuse.com/#search=web%20audio%20api

我可以在Android设备上检测为Chrome 39支持?并使用Chrome 39打开网页?

Can I detect support for Chrome 39 on an Android device? And open the web page using Chrome 39?

和要求用户下载,如果他/她没有呢?

And ask the user to download it if he/she does not have it?

推荐答案

您可以使用软件包管理系统如果安装了镀铬(com.android.chrome)查询,然后检索版本信息。

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
}

这篇关于我可以运行在Chrome 39的Web视图中的Andr​​oid应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆