Question

I got a problem with Google cloud print on Nexus 7 2th edition with Android 4.3. I using the example code in my app and it work fine on a lot of android devices except Nexus 7 and maybe some an others devices with android 4.3.

All work fine until I get this page.

enter image description here

I choose 'print to google drive' before. And then, if click on print button nothing happens... no any messages about starting new job or something else.

Maybe somebody can give some advices. Thanks a lot.

Was it helpful?

Solution

According to this we need to modify example code by add @JavascriptInterface annotation for all methods in PrintDialogJavaScriptInterface and change Properties>Android>Project Build Target to API 17+

final class PrintDialogJavaScriptInterface {
    @JavascriptInterface
    public String getType() {
        return cloudPrintIntent.getType();
    }

    @JavascriptInterface
    public String getTitle() {
        return cloudPrintIntent.getExtras().getString(TITLE);
    }

    @JavascriptInterface
    public String getContent() {
        try {
            ContentResolver contentResolver = getContentResolver();
            InputStream is = contentResolver.openInputStream(cloudPrintIntent.getData());
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            byte[] buffer = new byte[4096];
            int n = is.read(buffer);
            while (n >= 0) {
                baos.write(buffer, 0, n);
                n = is.read(buffer);
            }
            is.close();
            baos.flush();

            return Base64.encodeToString(baos.toByteArray(), Base64.DEFAULT);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

    @JavascriptInterface
    public String getEncoding() {
        return CONTENT_TRANSFER_ENCODING;
    }

    @JavascriptInterface
    public void onPostMessage(String message) {
        if (message.startsWith(CLOSE_POST_MESSAGE_NAME)) {
            finish();
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top