【问题标题】:Google cloud print doesn't work in Nexus 7 2th (Android 4.3)Google 云打印在 Nexus 7 2th (Android 4.3) 中不起作用
【发布时间】:2013-09-23 01:08:06
【问题描述】:

我在使用 Android 4.3 的 Nexus 7 第 2 版上遇到了 Google 云打印问题。我在我的应用程序中使用了example code,它可以在除 Nexus 7 之外的许多 android 设备上正常工作,也许还有其他一些具有 android 4.3 的设备。

在我得到这个页面之前一切正常。

我之前选择了“打印到谷歌驱动器”。然后,如果点击打印按钮没有任何反应......没有任何关于开始新工作或其他事情的消息。

也许有人可以提供一些建议。非常感谢。

【问题讨论】:

标签: android android-4.3-jelly-bean google-cloud-print


【解决方案1】:

根据this,我们需要修改示例代码,为 PrintDialogJavaScriptInterface 中的所有方法添加 @JavascriptInterface 注释,并将 Properties>Android>Project Build Target 更改为 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();
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 1970-01-01
    • 2012-04-07
    • 2013-02-09
    相关资源
    最近更新 更多