Print Report From Application using WiFi Printer.

edited June 2019 in User 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;
}
Tagged:

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?

  • Have You tried https://we.tl/t-uliH00RGbi this APK.
    That APK Works with Any Android Phone also able to print using wifi but not With Emteria OS. when can i expect this solution?

  • is there any update on WiFi Printing currently print spooler getting crashed again and again

  • Sorry, we currently have no free resources to take care of this. As I said before, I can't provide any OTA.

  • @Vinayak, your link is expired, we cannot download your sample application for testing.

  • Since we cannot download your file, we took the standard ApiDemo application (e.g. https://github.com/kesenhoo/AndroidApiDemo/blob/master/app/src/main/java/com/example/android/apis/app/PrintHtmlFromScreen.java) and tested how printing works with it. To our surprise, it worked just fine - we could print a page off the built-in webview without any crashes.

  • edited June 2019
    2019-06-20 12:36:38.141 28657-28657/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.android.printspooler, PID: 28657
    android.view.InflateException: Binary XML file line #113: Binary XML file line #273: Error inflating class android.widget.ImageView
    [...]
    android.graphics.drawable.BitmapDrawable.updateStateFromTypedArray(BitmapDrawable.java:787)
    at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:747)
    at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:130)
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227)
    2019-06-20 12:36:38.387 474-510/system_process E/InputDispatcher: channel '6e0b8cc com.android.printspooler/com.android.printspooler.ui.PrintActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
    2019-06-20 12:36:44.124 28624-28643/? E/bt_hci: startup_timer_expired
    2019-06-20 12:36:44.124 28624-28640/? E/bt_core_module: module_start_up Failed to start up module "hci_module"
  • Yes, I saw your report. But since the official example is working, you must debug your application.
  • dear I have tested this api demo apk and its not working and getting crashed.
    https://github.com/kesenhoo/AndroidApiDemo/
    same crashes same errors so as per your saying" since the official example is working, you must debug your application." i would like to know on which Emteria Version you have tested .
    I have installed latest 0.7.1 but still it shows RPi3 v0.6.4 in Settings Emteria Version.
    Please provide proper solution for WiFi Priting .I ll share you screenshot of AndroidApiDemo Official Getting Crashed.
  • Sure, here is a full video of the print application working: https://streamable.com/312ud
    It is the application from the GitHub project I referenced above

  • https://streamable.com/312ud is not working also tell me on which emteria version you tested the application.

  • What do you mean it is not working? You can see in the video it is the OS version 0.7.1 and the printing application does not crash.

  • i mean link is not working its showing This site can’t be reached The webpage at https://streamable.com/312ud might be temporarily down or it may have moved permanently to a new web address.
    ERR_TUNNEL_CONNECTION_FAILED

  • can you share video using wetransfer or anyother medium

  • 1st Above video works only when we keep Display size as Default (Small Not Working ).
    Then I made it as default it shows save as pdf which works fine but when i select add printer it shows Add printer->Recommendded Service Samsung Install to Discover but when i click on it It says no such app found.
    Please tell me what needs to be done to invoke wifi printer dynamically.

  • Sorry, I don't understand. Please explain in full detail.

Sign In or Register to comment.