如何使用带有URL白名单的显式应用程序在基于Xwalkview的信息亭浏览器中打开Web PDF文件?

时间:2018-11-18 18:04:11

标签: pdf android-intent xwalkview

我尝试使用另一个App在Xwalkview中打开Web PDF,但是该文件将被下载。

用例是用于Kiosk设备的WebApp,用于显示具有URL白名单的Intranet内容(HTML和PDF)。

非常感谢。

这是我的代码:

public class MainActivity extends Activity {
XWalkView mXwalkView;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mXwalkView = (XWalkView) findViewById(R.id.mybrowser);
    mXwalkView.setResourceClient(new MyResourceClient(mXwalkView){

        @Override
        public XWalkWebResourceResponse shouldInterceptLoadRequest(
                XWalkView view, XWalkWebResourceRequest request) {
            if(request.getUrl().getHost().endsWith("example.company.com")) return null;
            if(request.getUrl().getHost().startsWith("data://")) return null;
            if(request.getUrl().getHost().startsWith("javascript")) return null;
            if(request.getUrl().getHost().endsWith(".pdf"))


                {Intent pdfintent = new Intent(Intent.ACTION_VIEW);
                pdfintent.setComponent(new ComponentName("org.ninthfloor.copperpdf", "co.copperhead.pdfviewer.PdfViewer"));
                startActivity(pdfintent);}

            else;
            {
                ByteArrayInputStream bis =
                        new ByteArrayInputStream(
                                "Website not allowed!".getBytes());
                return createXWalkWebResourceResponse("text/plain", "UTF-8", bis);
            }
        }


    });
    mXwalkView.setUIClient(new MyUIClient(mXwalkView));
    mXwalkView.load("http://example.company.com", null);
    mXwalkView.setUserAgentString("Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML,"
            + " like Gecko) Chrome/41.0.2228.0 Safari/537.36");
    mXwalkView.getSettings().setUseWideViewPort(false);
    mXwalkView.getSettings().setCacheMode(2);
    mXwalkView.setInitialScale(100);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    SystemClock.sleep(5000);



}

0 个答案:

没有答案