android webview调用使用chrome浏览器

标签 android html google-chrome webview chromium

我制作了一个 web 应用程序,它在移动 chrome 中运行良好,但在 chrome 中我发现了一些问题,所以是否可以从应用程序而不是应用程序中的 webview 调用 android chrome。

我找不到任何方法来做到这一点。 1:我不关心是否安装了chrome 2:我在 webview 下面写了打开本地 html webview 但我看到拖放很少有 js 问题这在 android 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 View 吗。

 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);
         }


     }

最佳答案

您可以考虑使用 Crosswalk android webview ,它基于与 Chrome / Chrome 相同的底层引擎。

它与您的 APK 打包在一起,因此是独立的;您不需要安装 chrome。

它的 supposed to give you better performance than standard webview, with more built-in features .

这是一个hello world to get you started

关于android webview调用使用chrome浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26674926/

相关文章:

javascript - Chrome 控制台中 ES6 解构的奇怪行为

android - Android 虚拟设备中的 OMAPI

android - 有没有办法使用 ARCore SDK 录制手机屏幕?

python - 如何将 Django 表单嵌入到我的 CSS 设计中?

html - 将 div 向下移动到固定标题下方

javascript - Bootstrap 模式在 Laravel 中不起作用

javascript - 不明白如何在使用 PhoneGap 时将数据从 Android Activity 传递到 HTML UI

android - 使 DialogFragment 适合图像大小

html - 屏蔽元素 : issue in Chrome 的 SVG 剪辑路径

google-chrome - 无法读取 master_preferences 文件 - Watir