android - 我可以制作一个在 Chrome 39 中运行 WebView 的 Android 应用吗?

标签 android google-chrome

我正在开发一个 Android 应用程序,它是嵌入在 Web View 中的网页。该网页使用网络音频 API。看起来 Android 版 Chrome 39 支持该 API,但没有任何版本的基本 Android 浏览器支持:http://caniuse.com/#search=web%20audio%20api

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

如果用户没有的话要求他/她下载?

最佳答案

您可以使用PackageManager查询是否安装了 chrome (com.android.chrome),然后检索版本信息。

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
}

关于android - 我可以制作一个在 Chrome 39 中运行 WebView 的 Android 应用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27873566/

相关文章:

android - 如何在 Android 中创建日期和时间选择器?

android - 有没有更好的方法在 UGUI(Unity 新 UI)中使用透明图像来阻止光线转换?

android - 如何在运行时检测布局的横向版本的存在?

javascript - 如何在 chrome 扩展中获取选项卡通知,以便该扩展可以在每次新通知到达时显示桌面警报

javascript - chrome.storage.sync.set 变量键

java - 用户表、评级表和位置表之间的关系是什么?

安卓应用 : How to create a new window?

google-chrome - 在 google chrome 开发人员中重播 HTTP POST

css - 为什么 chrome 显示的渲染字体与计算字体系列不同?

javascript - 全局变量 Chrome 扩展内容脚本