Print Report From Application using WiFi Printer.

edited May 13 in Projects

Below Code causing PrintSpooler Crash and Not Printing at All.

private void createWebPrintJob(WebView webView) {

    // Get a PrintManager instance
    PrintManager printManager = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        printManager = (PrintManager) getBaseContext()
                .getSystemService(Context.PRINT_SERVICE);
    }

    String jobName = getString(R.string.app_name) + " Document";

    // Get a print adapter instance
    PrintDocumentAdapter printAdapter = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        printAdapter = webView.createPrintDocumentAdapter(jobName);
    }

    // Create a print job with name and adapter instance
    PrintJob printJob = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        printJob = printManager.print(jobName, printAdapter,
                new PrintAttributes.Builder().build());
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        printJob.restart();
    }
    // Save the job object for later status checking
    //mPrintJobs.add(printJob);
}


private WebView mWebView;

private void doWebViewPrint() {
    // Create a WebView object specifically for printing
    WebView webView = new WebView(getApplicationContext());
    webView.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            createWebPrintJob(view);
            mWebView = null;
        }
    });

    // Generate an HTML document on the fly:
    String htmlDocument = "<html><body><h1>Test Content</h1><p>Testing, " +
            "testing, testing...</p></body></html>";
    webView.loadDataWithBaseURL(null, HtmlEmail, "text/HTML", "UTF-8", null);

    // Keep a reference to WebView object until you pass the PrintDocumentAdapter
    // to the PrintManager
    mWebView = webView;
}

Comments

  • After some debugging, it looks like Android can't find one resource. However, this resource is included into the build, so I am quite confused right now. Could you create a full demo application (as APK file) for our tests?

  • Hi,
    Please download APK From below Link and After Splash Screen click on Start andAbove code will execute and get crashed.
    Please test and provide the solution to me.

  • Hi when can i get solution for above Issue.

  • @kalkov said:
    After some debugging, it looks like Android can't find one resource. However, this resource is included into the build, so I am quite confused right now. Could you create a full demo application (as APK file) for our tests?

    HI
    https://we.tl/t-uliH00RGbi Please download APK from given link and please provide solution

  • I got your file, thank you. The problem seems to be caused by some low-level components, so it will take some time for us to fix it. I can't provide any OTA for now.

  • when can i expect solution for this problem?

Sign In or Register to comment.