MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / createRandom

Function createRandom

apps/toolbox/src/pages/fs-helper.ts:9–43  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

7}
8
9export function createRandom(args) {
10 if (global.isAndroid) {
11 try {
12 const activity = Application.android.foregroundActivity as androidx.appcompat.app.AppCompatActivity;
13 const selection = [android.provider.MediaStore.MediaColumns.DISPLAY_NAME, android.provider.MediaStore.MediaColumns._ID];
14 // testing with downloads as rename only works with a well know collection downloads/audio/photos/videos API 29+
15 let cursor = activity.getContentResolver().query(android.provider.MediaStore.Downloads.getContentUri('external'), selection, null, null);
16
17 let uri;
18
19 while (cursor.moveToNext()) {
20 const index = cursor.getColumnIndex(selection[0]);
21 const name = cursor.getString(index);
22 if (name === 'ns_tmp.txt') {
23 const idIndex = cursor.getColumnIndex(selection[1]);
24 const id = cursor.getLong(idIndex);
25 uri = android.net.Uri.parse(`${android.provider.MediaStore.Downloads.getContentUri('external').toString()}/${id}`);
26 cursor.close();
27 break;
28 }
29 }
30
31 if (!uri) {
32 const values = new android.content.ContentValues();
33 values.put(android.provider.MediaStore.MediaColumns.DISPLAY_NAME, 'ns_tmp.txt');
34 values.put(android.provider.MediaStore.MediaColumns.MIME_TYPE, 'text/plain');
35 uri = activity.getContentResolver().insert(android.provider.MediaStore.Downloads.getContentUri('external'), values);
36 }
37
38 doWork(uri.toString());
39 } catch (e) {
40 console.error(e);
41 }
42 }
43}
44
45function doWork(path: string) {
46 try {

Callers

nothing calls this directly

Calls 8

doWorkFunction · 0.85
errorMethod · 0.80
parseMethod · 0.65
queryMethod · 0.45
getColumnIndexMethod · 0.45
getStringMethod · 0.45
toStringMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected