我正在开发一个 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/