I had this same problem until I found the solution on the Android developer website: http://developer.android.com/guide/webapps/webview.html.
The targetSdkVersion
in your app's AndroidManifest.xml is probably set to 17 or higher. In that case, you need to make a small change to the PrintDialogActivity
that you got from the Google Developer website. You need to add the annotation, @JavascriptInterface
to the public methods in the PrintDialogJavaScriptInterface
class.
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();
}
}
}