I am using cordova barcodescanner for my hybrid app development and i am very concern about the default message of the barcode scanner which says: "Place a barcode inside the viewfinder rectangle to scan it."
How could i change the default message? I am expecting similar to this:
NgCordova:
$cordovaBarcodeScanner
.scan()
.title('Please scan here') //something like this
.then(function(barcodeData) {
// Success! Barcode data is here
}, function(error) {
// An error occurred
});
From cordova plugins: But i dunno how to use it in cordovaBarcodeScanner
cordova.plugins.barcodeScanner.scan(
function (result) {
},
function (error) {
alert("Scanning failed: " + error);
},
{
// how can i use this in above?
"prompt" : "Place a barcode inside the scan area",
}
);
To implement barcode-scanner follow this steps.
step 1: install this cordova plugin add https://github.com/phonegap/phonegap-plugin-barcodescanner.git into your project.
step 2: Implement this code in you js file
$cordovaBarcodeScanner
.scan()
.then(function(barcodeData) {
// Success! Barcode data is here
}, function(error) {
// An error occurred
});
// NOTE: encoding not functioning yet
$cordovaBarcodeScanner
.encode(BarcodeScanner.Encode.TEXT_TYPE, "http://www.nytimes.com")
.then(function(success) {
// Success!
}, function(error) {
// An error occurred
});
},
To know more about ngCordova barcodescanner look this website.
Here is a tutorial for more information nicrobay barcode scanner.
and the message you revive as alert is what are receiving from the back end.
Related
I'm using ngCordova cordova-plugin-file to try to read an image that I then want to convert to bytes. I actually want to read it as dataURL and I'm getting an error.
/* The image is located at file:///data/data/com.xxx.housekeeping/cache/tmp_Screenshot_2017-04-27-09-30-42-1816635709.png on an Android device */
$cordovaFile.readAsText(cordova.file.cache, "tmp_Screenshot_2017-04-27-09-30-421403920141.png")
.then(function (success) {
// success
console.log(success);
}, function (error) {
// error
console.log(error);
});
I tried using both readAsText and readAsDataURL but I get
Wrong type for parameter "uri" of resolveLocalFileSystemURI: Expected String, but got Undefined.
as an error. This is on an Android device.
Is there something I'm missing or doing wrong?
Should be cacheDirectory, was accessing the wrong location
$cordovaFile.readAsText(cordova.file.cacheDirectory, "tmp_Screenshot_2017-04-27-09-30-421403920141.png")
.then(function (success) {
// success
console.log(success);
}, function (error) {
// error
console.log(error);
});
i implemented the deploy service to my ionic app (i am using ionic 1) and it is working fine, now i want to show the users the time remaining for the download or maybe a progress bar so they do not think that the app is freezing.
below is the function of the deploy
var deployFunction = function() {
$ionicDeploy.check().then(function(snapshotAvailable){
if (snapshotAvailable) {
// When snapshotAvailable is true, you can apply the snapshot
MainService.startSpinner("Downloading Updates");//this shows a loading image indicating that the download started
//applying the snapshot
$ionicDeploy.download()
.then(
function() {
MainService.stopSpinner();
MainService.startSpinner("Extracting");
$ionicDeploy.extract()
.then(
function(){
MainService.stopSpinner();
$ionicDeploy.load();
}, function(error) {
console.log("ERROR EXTRACT "+error);
// Error extracting
}, function(progress) {
// progress of extracting
console.log('extraction progress '+progress);
}
);
}, function(error){
//download error
console.log("ERROR Downloading "+error);
}, function(progress) {
//download progress
console.log('download progress '+progress);
}
);
}
});
}
i've read somewhere that the progress function should return an integer...
but it is not and i have no idea how to get information about the download beside that it is started or it is finished.
any help would be appreciated
for future references this was solved based on this documentation, the code will be
$ionicDeploy.download({
onProgress: function(p) {
console.log(p);
}
})
.then(
function() {...
i tried it and the console logged numbers from 1 to 100 indicating the download progress.
I am making an app using Ionic framework. I have used ngcordova angular library.
I have a zip folder which we are unzipping and then reading / writing the file.
When I am updating (write operation) on any file in "non rooted" phones, we are getting NO_MODIFICATION_ALLOWED_ERR. But this works fine in a "rooted" phone.
This issue is with write operation only. It is working fine while reading any file.
Please have a look at the code.
UpdateConfiguration: function (appconfig) {
var defer = $q.defer();
$cordovaFile.checkFile(cordova.file.dataDirectory, "Stock/database/appconfig.json").then(function (success) {
$cordovaFile.writeFile(cordova.file.dataDirectory, 'Stock/database/appconfig.json', JSON.stringify(appconfig), true)
.then(function (success) {
defer.resolve(true);
}, function (err) {
alert(JSON.stringify(err));
defer.reject(false);
});
}, function (error) {
alert('Error finding app config file');
});
return defer.promise;
}
Please help.
Thanks in advance.
I am trying to set up a push notification with parse to handle received notifications.
I used phonegap-parse-plugin plugin and was able to set it up correctly.
My problem with it is that I cannot handle the received notifications. I would like to redirect a user to a the page for the notification based on the notification json params.
So, I decided to switch to parse-push-plugin, but my problem with it is that I cannot even get it to show the alert registered box; it cannot even find the ParsePushPlugin method.
I followed the tutorial which is simple enough and added this to my app.js file
ParsePushPlugin.register(
{ appId:"xxx", clientKey:"xxx", eventKey:"myEventKey" }, //will trigger receivePN[pnObj.myEventKey]
function() {
alert('successfully registered device!');
},
function(e) {
alert('error registering device: ' + e);
});
ParsePushPlugin.on('receivePN', function(pn){
alert('yo i got this push notification:' + JSON.stringify(pn));
});
The alert success just failed to show so I guess it is not working or I am not doing the right thing.
Use phonegap-plugin-push. It is easy to implement and use.
Config :
var push = PushNotification.init({
"android": {
"senderID": "Your-sender-ID",
"forceShow": true, // To show notifications on screen as well
"iconColor": "#403782",
"badge": "true",
"clearBadge": "true" // To clear app badge
},
"ios": {
"alert": "true",
"badge": "true",
"clearBadge": "true",
"sound": "true",
"forceShow": "true"
},
"windows": {}
});
Device Registration :
push.on('registration', function(data) {
localStorage.setItem('pushToken', data.registrationId); // Save registration ID
});
Handle Notifications
push.on('notification', function(data) {
console.log(data);
// Handle all requests here
if (data.additionalData.$state == "mystate") {
$state.go('app.conversations');
}
})
What is the way to save a canvas to your phone album (camera roll, etc.) using Phonegap?
And when saved, how do I get the image URL using Cordova? Which plugins should I consider for this?
Method 1: Canvas2Image Plugin
With this plugin, you can save a canvas to your phone library using:
<canvas id="myCanvas" width="165px" height="145px"></canvas>
function onDeviceReady()
{
window.canvas2ImagePlugin.saveImageDataToLibrary(
function(msg){
console.log(msg);
},
function(err){
console.log(err);
},
document.getElementById('myCanvas')
);
}
However, it is not clear how the imageURI is passed or returned after saving?
UPDATE 23/02. I tried the following, but it never reaches my successcallback:
$scope.done = function() {
// todo: iterate over cloaks
$ionicLoading.show({
template: 'Saving images...'
});
// #issue: callback is not called
saveCanvasToPhone().then(successCallback, errorCallback);
var successCallback = function(output) {
$ionicLoading.hide();
window.alert("success call back: " + output) // never reached
$scope.addNewImage(output);
$state.go('tab.dash', {}, {reload: true}); // does not work
$state.go('tab.dash') // does not work
$scope.refreshLocalstorage();
}
// #issue4-nl: not working
var errorCallback = function(error) {
$ionicLoading.hide();
console.log("error cb: "+ error)
window.alert("error cb: " + error)
}
function saveCanvasToPhone() {
var defer = $q.defer();
try {
window.canvas2ImagePlugin.saveImageDataToLibrary(
function(output){
$scope.addNewImage(output); // does not work to save imagepath on localstorage
$scope.debugEntryOther = output // works fine
defer.resolve(output)
$ionicLoading.hide()
},
function(error){
defer.reject(error)
$ionicLoading.hide()
window.alert(error)
},
document.getElementById('canvas')
);
} catch(error) {
defer.reject(error)
$ionicLoading.hide()
console.log("saveCanvasToPhone: trycatch: error: " + error)
}
return defer.promise;
} // save canvas to phone
} // done
Unfortunatly Canvas2Image plugin was originally designed to save the canvas to the gallery, not to save to a file and deal with the file later on.
I have not found alternatives to this plugin (nor have I really searched), but you can manage to get the file path where the file was saved.
It depends on wich platform you are targeting :
For android, the path to the file is passed in the parameter 'msg' of the success function
For Windows Phone, the 'msg' parameter returns the string 'Image saved :' followed with the path of the file. So you have to split the string.
For IOS, it is actually not possible with the original plugin, but there are several forks allowing to do it.
I was informed that the author will soon take some time to improve his plugin so I'm sure it will soon be possible to get the file path with the 'official' plugin even for IOS.
In the meantime, you could use my fork. In that case, for IOS the path is returned in the 'msg' parameter, just like for android.