在uni-app中提供的封装好的api中没有提供获取手机相册的能力,只能打开相册后由用户选择其中的照片,而插件库中提供的获取相册的插件都是收费的,这里为大家分享一个可以自己获取android相册的代码段:文章来源地址https://www.toymoban.com/news/detail-516764.html
getImageList() {
let imageList = []
let MediaStore = plus.android.importClass('android.provider.MediaStore');
let photoColumns= [
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATA,
MediaStore.Images.Media.DATE_ADDED
]
let main = plus.android.runtimeMainActivity();
let resolver = main.getContentResolver();
plus.android.importClass(resolver);
let cursor=resolver.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, photoColumns, null, null, null)
plus.android.importClass(cursor);
while (cursor.moveToNext()) {
let _id = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID))
let filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA))
let dateAdded = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_ADDED))
imageList.push({
filePath: filePath,
dateAdded: dateAdded
})
}
cursor.close()
return imageList
}
文章来源:https://www.toymoban.com/news/detail-516764.html
到了这里,关于uni-app 获取android相册的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!