【问题标题】:Android Webview "Sandboxing is not allowed" when loading iframe stream加载iframe流时Android Webview“不允许沙箱”
【发布时间】:2021-05-31 15:17:43
【问题描述】:

我正在尝试通过 webview 将另一个网站的 iframe 加载到我的 android 应用程序中。我能够正确加载其他网站,但是当我从为您提供 iframe 嵌入代码 sn-p 的 sportsbay.org 加载流时,流变黑并打印“不允许沙盒”。我已经通过其他几个问题来找到答案。我的android项目如下。

我作为 video_url 传入的特定 url 是 https://sportsbay.org/embed/45629/1/btn-big-ten-network-live.html。 Sportsbay 提供的 iframe sn-p 是<iframe allow='encrypted-media' width='640' height='360' marginwidth='0' marginheight='0' scrolling='no' frameborder='0' allowfullscreen='yes' src='//sportsbay.org/embed/45629/1/btn-big-ten-network-live.html'></iframe>。这个 url 加载两个 url 1) https://lowend.xyz/stream/45629.html 这是实际的流和稍后加载 2) https://sportsbay.org/live-streams 将您重定向到sportsbay的主页。我在 MyWebViewClient 中有代码阻止加载主 sportsbay 页面,这会中断我想播放的流(这是我收到沙盒消息的地方)。我已经尝试用 loadData 和其他在 iframe html 字符串中传递的变体以及 mimeType 替换 loadUrl,但我目前所拥有的是最接近我加载流的方式(其他人没有足够远来发布沙盒消息) .

public void onCreate(Bundle savedInstanceState)
    {

        super.onCreate(savedInstanceState);
        // Bring Linear layout into view.
        setContentView(R.layout.webview);
        // Grab current intent & pull out video url.
        Intent i = getIntent();
        String video_url = i.getStringExtra("video_url");
        // Removes app name banner at top. Allows for orientation changes without reload.
        getSupportActionBar().hide();
        // Creates webview object.
        WebView web = findViewById(R.id.webView);
        // Configure settings for webview.
        WebSettings webSettings = web.getSettings();
        // Allows use of the phones file storage.
        webSettings.setDomStorageEnabled(true);
        // Sets encoding standard for urls.
        webSettings.setDefaultTextEncodingName("utf-8");
        // Able to zoom.
        webSettings.setSupportZoom(true);
        // Needed for websites to load javascript enabled content (most videos/streams).
        webSettings.setJavaScriptEnabled(true);
        // Attached webview to java class MyWebViewClient that vets the incoming urls before loading.
        // Blocks Ads / viruses / popups.
        // Also keeps url from launch in a browser.
        web.setWebViewClient(new MyWebViewClient());

        // Checks if channel is sourced from sportsbay.org.
        if(video_url.contains("sportsbay.org"))
        {
            // Changes the browser user agent since chrome user agent returns 403 Forbidden message.
            webSettings.setUserAgentString("Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion");
        }
        web.loadUrl(video_url);
    }
public class MyWebViewClient extends WebViewClient {
    public boolean shouldOverrideKeyEvent (WebView view, KeyEvent event) {

        return true;
    }

    @SuppressWarnings("deprecation")
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        final Uri uri = Uri.parse(url);
        return handleUri(uri);
    }

    @TargetApi(Build.VERSION_CODES.N)
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        final Uri uri = request.getUrl();
        return handleUri(uri);
    }

    private boolean handleUri(final Uri uri) {
        Log.i(TAG, "Uri =" + uri);
        final String host = uri.getHost();
        final String scheme = uri.getScheme();
        // Check requested URL to known good
        if (host.equals("s1-tv.blogspot.com") ||
            host.equals("reddit-tv-streams.blogspot.com") ||
            host.equals("newdmn.icu") ||
            host.equals("lowend.xyz"))
        {
            // Returning false means that you are going to load this url in the webView itself
            return false;
        } else {
            // Do not load the requested URL
            return true;
        }
    }
}

【问题讨论】:

    标签: java android html iframe webview


    【解决方案1】:

    好消息!我想到了。沙盒消息不是因为服务器与我的应用程序交互不正确,而是因为我的应用程序无权使用 android 应用程序(应用程序沙箱)之外的文件存储。已通过以下方式修复:

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    

    需要放在Android Manifest.xml中权限区(顶层包下)。

    【讨论】:

      猜你喜欢
      • 2019-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-08
      • 2015-09-19
      • 2019-11-08
      • 1970-01-01
      相关资源
      最近更新 更多