diff options
Diffstat (limited to 'mobile-ns/app/gallery-view-model.ts')
-rw-r--r-- | mobile-ns/app/gallery-view-model.ts | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/mobile-ns/app/gallery-view-model.ts b/mobile-ns/app/gallery-view-model.ts new file mode 100644 index 0000000..f48fe6f --- /dev/null +++ b/mobile-ns/app/gallery-view-model.ts @@ -0,0 +1,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)); + } + // }); + } +} |