How can I open a web PDF file in a Xwalkview based kiosk browser with an explicit App with url white-list?

45 views Asked by At

I try to open web PDFs in a Xwalkview with another App but the file will just be downloaded.

Use case is a WebApp for Kiosk-Devices to show intranet content (HTML & PDF) with URL white-list.

Here is my code:

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

There are 0 answers