【问题标题】:Cordova - Get array of images from device? (Custom image gallery picker)Cordova - 从设备获取图像数组? (自定义图片库选择器)
【发布时间】:2017-10-02 13:54:33
【问题描述】:

我正在开发一个需要构建自定义图片库选择器的 Cordova 应用程序。我在 Instagram 和 Twitter(如下图所示)应用程序中看到了类似的东西,它们允许用户从他们的相机胶卷中选择图像,而无需打开操作系统提供的默认图像选择器。我搜索了插件,只找到了使用默认图库选择器的东西。

我认为解决方案是以某种方式从操作系统获取某种图像数组,然后您可以构建您的图像库选择器,但我不确定如何去做。

有人有任何想法或解决方案吗?

谢谢!

PS。这是 iOS 上 Twitter 应用程序的屏幕截图。撰写推文时,它允许您滚动浏览从最新到最旧排序的图像列表,而无需打开默认的 iOS 图像选择对话框。

【问题讨论】:

    标签: cordova cordova-plugins ngcordova


    【解决方案1】:

    你可以通过cordova文件插件(https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/)来实现

    但是我使用的是 Ionic Native(cordova 文件插件的包装器),步骤必须相同。

    import { File } from '@ionic-native/file'
    
    class MyFiles {
    
        constructor(private file: File ){
           this.getFiles("WhatsApp/Media") // Here I am trying to get the photos from WhatsApp application. You may provide any other folder or root folder.
        }
    
    
        getFiles(dir: string): void {
    
            this.file.listDir(this.file.externalRootDirectory, dir).then(
              (files) => {
    
                for (let file of files) {
                  if (file.isDirectory && file.name != '.' && file.name != '..') {
                    this.getFiles(dir + "/" + file.name) // recursively scan sub dirs
                  } else {
                    if (file.nativeURL.endsWith("jpg") || file.nativeURL.endsWith("jpeg") || file.nativeURL.endsWith("gif")) {
                      // Do your stuff with file
                      }
                    }
                  }
                }
              }
            ).catch((err) => {
              console.log(err.toString())
            });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-19
      • 1970-01-01
      • 2017-12-14
      相关资源
      最近更新 更多