Ionic 4 Select Multiple Image From Gallery with Image-picker Not Working

痴心易碎 提交于 2020-12-15 06:58:21

问题


I Use Image-Picker for select multiple Image From Gallery But I Get The "Plugin_not_installed"

I Use From link To Install plugin ionic image picker

ionic cordova plugin add cordova-plugin-telerik-imagepicker
npm install @ionic-native/image-picker

after install cordova plugin and telerik image picker in my package.json :

{
  "name": "sheedo",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~8.1.2",
    "@angular/compiler": "~8.1.2",
    "@angular/core": "~8.1.2",
    "@angular/forms": "~8.1.2",
    "@angular/platform-browser": "~8.1.2",
    "@angular/platform-browser-dynamic": "~8.1.2",
    "@angular/router": "~8.1.2",
    "@ionic-native/camera": "^5.14.0",
    "@ionic-native/core": "^5.14.0",
    "@ionic-native/file": "^5.14.0",
    "@ionic-native/image-picker": "^5.14.0",
    "@ionic-native/screen-orientation": "^5.14.0",
    "@ionic-native/splash-screen": "^5.0.0",
    "@ionic-native/status-bar": "^5.0.0",
    "@ionic/angular": "^4.7.1",
    "cordova-android": "8.1.0",
    "cordova-ios": "^5.0.1",
    "cordova-plugin-camera": "^4.1.0",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-screen-orientation": "^3.0.2",
    "cordova-plugin-telerik-imagepicker": "^2.3.3",
    "core-js": "^2.5.4",
    "es6-promise-plugin": "^4.2.2",
    "ionic4-hidenav": "^0.1.2",
    "jalali-moment": "^3.3.3",
    "rxjs": "~6.5.1",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.801.2",
    "@angular-devkit/build-angular": "~0.801.2",
    "@angular-devkit/core": "~8.1.2",
    "@angular-devkit/schematics": "~8.1.2",
    "@angular/cli": "~8.1.2",
    "@angular/compiler": "~8.1.2",
    "@angular/compiler-cli": "~8.1.2",
    "@angular/language-service": "~8.1.2",
    "@ionic/angular-toolkit": "~2.0.0",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.0.0",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-ionic-keyboard": "^2.1.3",
    "cordova-plugin-ionic-webview": "^4.1.1",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-screen-orientation": {},
      "cordova-plugin-camera": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      },
      "cordova-plugin-file": {},
      "cordova-plugin-telerik-imagepicker": {
        "PHOTO_LIBRARY_USAGE_DESCRIPTION": " "
      }
    },
    "platforms": [
      "ios"
    ]
  }
}

and for use image picker

 let options: ImagePickerOptions = {
      maximumImagesCount: 8
    };`enter code here`
if( !this.imagePicker.hasReadPermission) this.imagePicker.requestReadPermission();

    this.imagePicker.getPictures(options).then((results) => {
      for (var i = 0; i < results.length; i++) {
          console.log('Image URI: ' + results[i]);
      }
    }, (err) => {alert(err) });

and for run use ionic serve --devapp

and when click on getImage i use alert for get error

"Plugin_not_installed"

and in vsCode Console

`[ng] [console.warn]: "Native: tried calling ImagePicker.getPictures, but the ImagePicker plugin is not installed."
[ng] [console.warn]: "Install the ImagePicker plugin: 'ionic cordova plugin add cordova-plugin-telerik-imagepicker'"`

All the examples on the Internet have done this

also i test command

npm install @ionic-native/image-picker@4

for install version 4 but app not build.

my ionic version is 4 and i run android platform


回答1:


You can use

https://ionicframework.com/docs/native/image-picker

ionic cordova plugin add cordova-plugin-telerik-imagepicker
npm install @ionic-native/image-picker

 * `cordova plugin add cordova-android-support-gradle-release`
 * `ioinc cordova platform rm android`
 * `ionic cordova platform add android`
 * `ionic cordova build android --prod`


import { ImagePicker, ImagePickerOptions } from '@ionic-native/image-picker/ngx';


constructor(private imagePicker: ImagePicker) { }




getPictures() {
    let options: ImagePickerOptions = {  
          //here Quality of images, defaults to 100  
          quality: 100,  
          //here Width of an Image  
          width: 600,  
          //here Height of an Image  
          height: 600,  
          /** Output type, defaults to 0 (FILE_URI). 
    
          * FILE_URI :0 (number) it returns a actual path for an image 
    
          */  
          
          outputType: 1  
          //here Maximum image count for selection, defaults to 15.  
          //while setting a number 15 we can load 15 images in one selection.
    
          maximumImagesCount: 8
          // max images to be selected, defaults to 15. If this is set to 1  
        }; 
    
     this.imagePicker.getPictures(options)
          .then(selectedImg => { })
    }



回答2:


try using the plugin in a non-native way. In your component declare a window variable and then use it to call the plugin. You need to test it from a device, it's not working on browsers, neither on --devapp serve. It will work fine, but it isn't taking the options object... I need it to return base64 (outputType: 1), but always returns fileURI

/*Imports section*/

declare const window: any;

@Component({...})

export class HomePage implements OnInit {

 constructor(){}

 yourMethod() {
  window.imagePicker.getPictures(
    async function(results) {
      for (var i = 0; i < results.length; i++) {
        const currentPicture = results[i];
        files.push(currentPicture);
      }
      console.log(files);
    }, function (error) {
      console.log('Error: ' + error);
    },
    {
      outputType: 1,
      maximumImagesCount: 30,
      quality: 100
    }
  );
 }
}


来源:https://stackoverflow.com/questions/58153236/ionic-4-select-multiple-image-from-gallery-with-image-picker-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!