| 220 | |
| 221 | let lastDownload: File; |
| 222 | export function createFileInDownloads() { |
| 223 | if (!global.isAndroid) { |
| 224 | return; |
| 225 | } |
| 226 | const width = Screen.mainScreen.widthPixels; |
| 227 | const height = Screen.mainScreen.heightPixels; |
| 228 | const randomImageUrl = `https://picsum.photos/${width}/${height}.jpg?random=${Date.now()}`; |
| 229 | |
| 230 | Http.getFile(randomImageUrl).then((result: File) => { |
| 231 | let file = File.android.createFile({ |
| 232 | directory: AndroidDirectory.DOWNLOADS, |
| 233 | name: `${Date.now()}.jpg`, |
| 234 | mime: 'image/jpeg', |
| 235 | relativePath: `NativeScript`, |
| 236 | }); |
| 237 | result |
| 238 | .copy(file.path) |
| 239 | .then((done) => { |
| 240 | lastDownload = file; |
| 241 | console.log('done: ' + done + '\n' + 'Original path: ' + result.path + '\n' + 'Copied to: ' + file.path + '\n' + 'Original size: ' + result.size + '\n' + 'Copy size: ' + file.size + '\n'); |
| 242 | alert(`File saved in ${AndroidDirectory.DOWNLOADS}/NativeScript`); |
| 243 | }) |
| 244 | .catch((error) => { |
| 245 | console.error(error); |
| 246 | }); |
| 247 | }); |
| 248 | } |
| 249 | |
| 250 | export function createFileInGallery() { |
| 251 | if (!global.isAndroid) { |