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)); } // }); } }