【问题标题】:android webview call use chrome Browserandroid webview调用使用chrome浏览器
【发布时间】:2014-12-27 18:55:30
【问题描述】:

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

我找不到任何方法来做到这一点。 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 意图打开 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);
         }


     }

【问题讨论】:

  • 您无法保证设备已安装 chrome,因为它不是默认浏览器。即使你有这个保证,你仍然会选择用户应该决定的东西。我个人认为这是一个坏主意。您可以在描述中添加 DESIGNED FOR CHROME 或其他内容。
  • 我不关心它,只会显示错误它很好,因为大多数新平板电脑或安卓都安装了 chrome,我该怎么做,请指导?

标签: android html google-chrome webview chromium


【解决方案1】:

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

它是和你的APK一起打包的,所以它是独立的;您不需要安装 chrome。

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

这是hello world to get you started

【讨论】:

  • 如果我想用 chrome 打包 Android 设备我会更喜欢要求用户安装 chrome 如果他们没有它
  • 查看我的第二个代码,我尝试使用 crome 意图打开它,但用户退出应用程序并打开 chrome,我希望与 webview 相同的外观未打开浏览器
  • @mour 所以你想使用 chrome 浏览器作为 webview 吗?它是一个浏览器,而不是 webview,不确定这是否可行。如果您启动 chrome 意图,它将最终打开 chrome 应用程序,这是一个完整的浏览器。考虑一下 Crosswalk,它为您提供了一个 web 视图。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-17
  • 2011-12-06
  • 2012-06-25
  • 2021-12-03
  • 1970-01-01
相关资源
最近更新 更多