| 101 | } |
| 102 | |
| 103 | export function pickFile() { |
| 104 | if (!global.isAndroid) { |
| 105 | return; |
| 106 | } |
| 107 | Application.android.on('activityResult', (args) => { |
| 108 | if (args.requestCode === 1000) { |
| 109 | const file = args.intent.getData().toString(); |
| 110 | //const file = File.fromPath(args.intent.getData().toString()); |
| 111 | //console.log(file); |
| 112 | //readFile(file); |
| 113 | //copyFile(file); |
| 114 | console.time('fromPath: copy'); |
| 115 | const f = File.fromPath(file, true); |
| 116 | console.timeEnd('fromPath: copy'); |
| 117 | console.log('old path: ', file); |
| 118 | console.log('new path: ', f.path, f.extension, f.size); |
| 119 | } |
| 120 | }); |
| 121 | const Intent = android.content.Intent; |
| 122 | const picker = new Intent(Intent.ACTION_OPEN_DOCUMENT); |
| 123 | picker.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION); |
| 124 | picker.addCategory(Intent.CATEGORY_OPENABLE); |
| 125 | picker.setType('*/*'); |
| 126 | Application.android.foregroundActivity.startActivityForResult(picker, 1000); |
| 127 | } |
| 128 | |
| 129 | function readFile(selected: string) { |
| 130 | let applicationContext = Utils.android.getApplicationContext(); |