相机插件杀死APK离子

时间:2019-12-12 19:04:52

标签: ionic-framework android-camera cordova-plugins ionic4

当我们使用ionic 4 camera plugin时,它会在拍照后杀死该应用程序,该应用程序因为已关闭而不再可用。在使用foregroud时,是否有某种方法可以将应用放入camera中,而无需更改手机的配置?

private takePicture(sourceType: PictureSourceType): Promise<any> {
 return new Promise((resolve, reject) => {
  const options: CameraOptions = {
    quality: 80,
    sourceType: sourceType,
    saveToPhotoAlbum: false,
    correctOrientation: false
  };
  this.camera.getPicture(options).then((imagePath) => {
    let correctPath: string;
    let currentName: string;
    // Manejo especial para la biblioteca de Android
    if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
      // filePath solo funciona en android
      this.filePath.resolveNativePath(imagePath).then((filePath) => {
        correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
        currentName = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.length);
        this.file.readAsDataURL(correctPath, currentName).then((imageBase64) => {
          resolve({url: imageBase64,alt:currentName});
        });
      });
    } else {

      currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
      correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
      this.file.readAsDataURL(correctPath, currentName).then((imageBase64) => {
        //const array = {url: imageBase64,alt:currentName};
        //const Json = JSON.stringify(array);
        resolve({url: imageBase64,alt:currentName});
      });
    }
  }, (error) => {
    console.log('[transfer-img-file-171]', JSON.stringify(error));
    reject(this.translate.instant('ERRORS.CAMERA_ERROR'));
  });
 });
}

0 个答案:

没有答案
相关问题