【问题标题】:Load Content in Application using inbuilt chrome web browser than Default System Webview使用内置 chrome Web 浏览器在应用程序中加载内容,而不是使用默认系统 Webview
【发布时间】:2017-02-07 09:06:34
【问题描述】:

我目前正在我的应用程序中实现某些功能,因为事实证明默认 Web 视图不支持这些功能。 那么,有没有可能我可以在我的应用程序内的内置 chrome web view 中呈现我的应用程序内容,而不是 android 默认 web view 或重定向它打开 chrome 浏览器。 我现在在吃棉花糖。我开始了解在 NOUGAT 版本中实现的此功能。但是,我在 API 上需要它。

下面是我的代码:

webView = (WebView) findViewById(R.id.fullscreen_content);
           // webView.setWebViewClient();

            //you can also link to a website. Example:
            //webView.loadUrl("www.google.com");
            //I have included web permissions in the AndroidManifest.xml
            //
            WebSettings webSettings = webView.getSettings();
            webSettings.setJavaScriptEnabled(true);
            webSettings.setDomStorageEnabled(true);

            //loads the WebView completely zoomed out
            webView.getSettings().setLoadWithOverviewMode(true);

            //true makes the Webview have a normal viewport such as a normal desktop browser
            //when false the webview will have a viewport constrained to it's own dimensions
            webView.getSettings().setUseWideViewPort(true);

            //override the web client to open all links in the same webview
            webView.setWebViewClient(new MyWebViewClient());
            webView.setWebChromeClient(new MyWebChromeClient());

            webView.loadUrl(URL);

【问题讨论】:

    标签: android webview google-chrome-app


    【解决方案1】:

    试试这个我从Building Web Apps in WebView派生但使用WebChromeClient的示例代码:

    public class MainActivity extends AppCompatActivity {
    
        WebView webView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            webView=(WebView)findViewById(R.id.webview);
            webView.setWebChromeClient(new WebChromeClient());
    
            String urlString="https://www.youtube.com/watch?v=miomuSGoPzIe";
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlString));
    
            intent.setPackage("com.android.chrome");
    
            try {
                startActivity(intent);
            } catch (ActivityNotFoundException ex) {
    
                Log.v("MainActivity", "NO CHROME APP INSTALLED");
                intent.setPackage(null);
                startActivity(intent);
            }
        }
    }
    

    这是 activity_main.xml 中的 WebView

    <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
    

    我在 Nexus 手机中有 Firefox 和 Chrome,它在 Chrome 中打开了 WebView,所以我认为它可以工作。

    【讨论】:

      猜你喜欢
      • 2016-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多