David PHAM-VAN

Save shared pdf in cache on Android

@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 - Improve native code 6 - Improve native code
7 - Add Printing.info() 7 - Add Printing.info()
8 - Use PageTheme in example 8 - Use PageTheme in example
  9 +- Save shared pdf in cache on Android
9 10
10 ## 2.1.9 11 ## 2.1.9
11 12
@@ -155,9 +155,14 @@ public class PrintingJob extends PrintDocumentAdapter { @@ -155,9 +155,14 @@ public class PrintingJob extends PrintDocumentAdapter {
155 assert name != null; 155 assert name != null;
156 156
157 try { 157 try {
158 - final File externalFilesDirectory =  
159 - context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS);  
160 - File shareFile = new File(externalFilesDirectory, name); 158 + final File shareDirectory = new File(context.getCacheDir(), "share");
  159 + if (!shareDirectory.exists()) {
  160 + if (!shareDirectory.mkdirs()) {
  161 + throw new IOException("Unable to create cache directory");
  162 + }
  163 + }
  164 +
  165 + File shareFile = new File(shareDirectory, name);
161 166
162 FileOutputStream stream = new FileOutputStream(shareFile); 167 FileOutputStream stream = new FileOutputStream(shareFile);
163 stream.write(data); 168 stream.write(data);
1 <?xml version="1.0" encoding="utf-8"?> 1 <?xml version="1.0" encoding="utf-8"?>
2 <paths> 2 <paths>
3 - <external-path name="external_files" path="."/>  
4 -</paths>  
  3 + <cache-path name="share" path="/share/"/>
  4 +</paths>