我做了一个网络应用程序,它在移动版chrome浏览器中运行良好,但在chromium浏览器中却出现了一些问题,所以有没有可能从应用程序中调用安卓chrome浏览器而不是应用程序中的webview呢?
我找不到任何方法来实现。 1:我不关心是否安装了chrome浏览器 2:我写了下面的webview来打开本地html文件,但我发现拖放功能存在一些js问题,在安卓chrome浏览器中却能正常工作。
以下是我的代码:
public class MainActivity extends Activity {
private static final String URL = "file:///android_asset/index.html";
private WebView mWebView;
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.setWebViewClient(new WebViewClient());
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.getSettings().setRenderPriority(RenderPriority.HIGH);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
final Activity activity = this;
mWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress) {
activity.setProgress(progress * 1000);
}
});
mWebView.loadUrl(URL);
}
@Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
}
}
我编写了一段代码,使用Chrome Intent打开URL。我可以使用这种功能来将Chrome用作Web视图。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main);
String url = "http://www.google.com";
String packageName = "com.android.chrome";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
browserIntent.setPackage(packageName);
browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//Activity context = null;
List<ResolveInfo> activitiesList = getPackageManager().queryIntentActivities(
browserIntent, -1);
if(activitiesList.size() > 0) {
// Found the browser on the device, launch it
startActivity(browserIntent);
} else {
// The browser isn't installed, so we should prompt the user to get
Intent playStoreIntent = new Intent(Intent.ACTION_VIEW);
playStoreIntent.setData(Uri.parse("market://details?id="+packageName));
playStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(playStoreIntent);
}
}