我使用WebView将Web应用程序包装在移动应用程序中。我的应用程序使用音频框架和仅在Chrome浏览器中运行的webGL。问题是WebView默认是android系统浏览器。我的音频库和webGL不能在系统浏览器中工作,只需使用chrome。我知道有一种方法可以在Android应用程序中获取基于chrome的WebView,因为它们在这里引用它:
https://developer.chrome.com/multidevice/webview/overview
有谁知道如何让WebView基于chrome?下面是我的mainActivity.java代码。
public class MainActivity extends ActionBarActivity {
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String url = "http://www.cs.stolaf.edu/users/lipson/MusicVisualization/musicVis.html";
mWebView = (WebView) findViewById(R.id.webView1);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl(url);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
答案 0 :(得分:1)
从您引用的链接中,您想要的功能位于WebView v36中,该版本仅在L-preview中可用,并且在Android Developer website announcement for Android 5.0 Lollipop中公布的WebView v37 / Chromium M37中可用。
由于您正在播放音频,因此模拟器可能无法正常工作,因此您最好选择在设备上进行测试。将您的最低SDK设置为API 21,然后在装有Android 5.0的设备上试用您的应用。