Reputation: 51
I have simple ionic app where it takes picture from cordova camera function.It goes no where from there..
Really need the help to solve this..I stuck with this from few weeks..now..
const cameraOptions: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
// encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: this.camera.PictureSourceType.CAMERA,
saveToPhotoAlbum : true
}
try {
let obj = this.camera.getPicture(cameraOptions).then((imageData) => {
// never entered here
console.log('getPicture Success ');
// let base64Image = 'data:image/jpeg;base64,' + imageData;
let base64Image = imageData;
this.capturedSnapURL = base64Image;
alert(this.capturedSnapURL);
}, (err) => {
alert('error=' + err); // never entered
console.log(err);
});
alert('no error but no picture:' + obj); // always print this [object Promise]
} catch (error) {
alert('exception error' + error); //never entered here
}
I have been trying above code from quite sometime, it never entered success block nor in error block of then() of getPicture. Never printed 'getPicture Success' or error.
It only shows "no error but no picture:[object Promise]" message.
I tried debug this also using remotedevice option in emulator. It comes in till getPicture function call and then get lost. No error or exception.
I have tried many solutions as suggested but no luck..I have upgraded ionic, angular ,cordova,nodejs to latest version to resolve this issue but no luck. Here the version details
Ionic:
ionic (Ionic CLI) : 4.12.0 (/usr/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 5.2.3
@angular-devkit/build-angular : 0.1000.3
@angular-devkit/schematics : 10.0.3
@angular/cli : 10.0.3
@ionic/angular-toolkit : 2.2.0
Cordova:
cordova (Cordova CLI) : 9.0.0 ([email protected])
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 11 other plugins)
System:
Android SDK Tools : 26.1.1 (...~/Android/Sdk)
NodeJS : v12.18.2 (~/node-v12.18.2-linux-x64/bin/node)
npm : 6.13.4
OS : Linux 3.10
Note that i have been trying this on android emulator. here is my package.json.
{
"name": "mygrd",
"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": "^10.0.4",
"@angular/core": "^10.0.4",
"@angular/forms": "^10.0.4",
"@angular/http": "^7.2.16",
"@angular/platform-browser": "^10.0.4",
"@angular/platform-browser-dynamic": "^10.0.4",
"@angular/router": "^10.0.4",
"@ionic-native/android-permissions": "^5.27.0",
"@ionic-native/camera": "^5.27.0",
"@ionic-native/core": "^5.26.0",
"@ionic-native/http": "^5.27.0",
"@ionic-native/splash-screen": "^5.26.0",
"@ionic-native/status-bar": "^5.26.0",
"@ionic-native/uid": "^5.26.0",
"@ionic-native/unique-device-id": "^5.26.0",
"@ionic/angular": "^5.2.3",
"@ionic/angular-toolkit": "^2.2.0",
"@ionic/pro": "2.0.4",
"cordova-android": "^8.1.0",
"cordova-hot-code-push-plugin": "1.5.3",
"cordova-plugin-android-permissions": "1.0.2",
"cordova-plugin-camera": "4.1.0",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-file": "6.0.2",
"cordova-plugin-filepath": "1.5.8",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^3.1.2",
"cordova-plugin-splashscreen": "^5.0.4",
"cordova-plugin-statusbar": "^2.4.3",
"cordova-plugin-unique-device-id2": "2.0.0",
"cordova-plugin-uniquedeviceid": "1.3.2",
"cordova-plugin-whitelist": "^1.3.4",
"cordova-sqlite-storage": "5.0.0",
"core-js": "^2.6.11",
"rxjs": "~6.6.0",
"zone.js": "~0.10.3"
},
"devDependencies": {
"@angular-devkit/architect": "^0.1000.3",
"@angular-devkit/build-angular": "^0.1000.3",
"@angular-devkit/core": "^10.0.3",
"@angular-devkit/schematics": "^10.0.3",
"@angular/cli": "^10.0.3",
"@angular/compiler": "^10.0.4",
"@angular/compiler-cli": "^10.0.4",
"@angular/language-service": "^10.0.4",
"@ionic/app-scripts": "^3.2.4",
"@types/jasmine": "^2.8.17",
"@types/jasminewd2": "^2.0.8",
"@types/node": "^10.12.30",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.4",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^2.0.6",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^5.4.4",
"ts-node": "^8.0.3",
"tslint": "~5.12.0",
"typescript": "~3.9.7"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-whitelist": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-ionic-keyboard": {},
"cordova-hot-code-push-plugin": {},
"cordova-plugin-file": {},
"cordova-sqlite-storage": {},
"cordova-plugin-filepath": {},
"cordova-plugin-android-permissions": {},
"cordova-plugin-camera": {
"ANDROID_SUPPORT_V4_VERSION": "27.+"
}
},
"platforms": []
}
}
Upvotes: 4
Views: 1455
Reputation: 51
Any inputs are really appreciated reg this issue...? Unfortunately, I am unable to use camera on ionic/cordova framework due to this error and may have to migrate to android studio if not worked..
Upvotes: 1
Reputation: 606
try something like bellow, I used this code to get a picture (file path) from the camera in an ionic app, work both in ios and android. for the camera option details, you can look here
constructor(
private camera : Camera,
private platform : Platform,
private imagePicker : ImagePicker,
private filePath : FilePath,
) {}
takePicture() {
var options: CameraOptions =
{
quality : 100,
sourceType : this.camera.PictureSourceType.CAMERA,
saveToPhotoAlbum : true,
correctOrientation : true,
encodingType : this.camera.EncodingType.JPEG,
targetHeight : 1000,
targetWidth : 1000,
};
this.camera.getPicture(options).then(imagePath => {
if (this.platform.is('android') && sourceType === this.camera.PictureSourceType.PHOTOLIBRARY) {
this.filePath.resolveNativePath(imagePath).then(filePath => {
let correctPath = filePath.substr(0, filePath.lastIndexOf('/') + 1);
let currentName = imagePath.substring(imagePath.lastIndexOf('/') + 1, imagePath.lastIndexOf('?'));
console.log('filePath 1', filePath);
console.log('current 1', currentName);
console.log('correct 1', correctPath);
});
} else {
let currentName = imagePath.substr(imagePath.lastIndexOf('/') + 1);
let correctPath = imagePath.substr(0, imagePath.lastIndexOf('/') + 1);
console.log('filePath 2', filePath);
console.log('current 2', currentName);
console.log('correct 2', correctPath);
}
}, err1 => {
console.log('something wrong 1 -> ', err1);
}).catch(err2 => {
console.log('something wrong 2 -> ', err2)
});
}
Upvotes: 0