Created
December 16, 2013 10:33
-
-
Save necronet/7985063 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class PrintDialogJavaScriptInterface { | |
public String getType() { | |
return cloudPrintIntent.getType(); | |
} | |
public String getTitle() { | |
return cloudPrintIntent.getExtras().getString("title"); | |
} | |
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 ""; | |
} | |
public String getEncoding() { | |
return CONTENT_TRANSFER_ENCODING; | |
} | |
public void onPostMessage(String message) { | |
if (message.startsWith(CLOSE_POST_MESSAGE_NAME)) { | |
finish(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment