summaryrefslogtreecommitdiff
path: root/mobile-ns/app/gallery-view-model.ts
blob: f48fe6f4672420d550fd585101c1e36e9ed1863f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { AndroidActivityRequestPermissionsEventData, Application, Observable, Utils } from '@nativescript/core';

export class GalleryModel extends Observable {
  constructor() {
    super();
  }

  peng() {
    // const check = function () {
      /* return new Promise((resolve, reject) => {
        (Application.android.foregroundActivity || Application.android.startActivity).requestPermissions([
          android.Manifest.permission.READ_EXTERNAL_STORAGE,
          android.Manifest.permission.READ_CONTACTS,
        ], 3766);
        function onActivityResult(args) {
          if (args.requestCode === 3766) {
            Application.android.off(Application.android.activityRequestPermissionsEvent, onActivityResult);
            console.log(args);
            console.log(args.grantResults);
            resolve(args);
          }
        }
        Application.android.on(Application.android.activityRequestPermissionsEvent, onActivityResult);
      });
    } */

        (Application.android.foregroundActivity || Application.android.startActivity).requestPermissions([
          android.Manifest.permission.READ_MEDIA_IMAGES,
        ], 3765);
    console.log(Application.android.foregroundActivity, Application.android.startActivity);
    return;

    // check().then(() => {
      console.log('query');
      const cursor = Utils.android.getApplicationContext().getContentResolver().query(
        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
        [
          android.provider.MediaStore.Images.ImageColumns._ID,
          android.provider.MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME,
          android.provider.MediaStore.Images.ImageColumns.DATE_TAKEN,
        ],
        null,
        null,
      );

      const contacts = Utils.android.getApplicationContext().getContentResolver().query(
        android.provider.Contacts.Phones.CONTENT_URI,
        [
          android.provider.Contacts.PhonesColumns.LABEL,
          android.provider.Contacts.PhonesColumns.TYPE,
        ],
        null,
        null
      );
      console.log(contacts, contacts.getCount());

      console.log(cursor, cursor.getCount());
      if (cursor && cursor.moveToFirst()) {
        const bucketColumn = cursor.getColumnIndex(android.provider.MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME);
        console.log(bucketColumn);
        // console.log(cursor.getString(bucketColumn));
      }
    // });
  }
}