I am trying to get the mobile device contact number using Cordova Phonegap application . While I was searching in google I got this URL LINK which is the exact one that I required .I followed every step of the post and following to which i wrote this snippet to get the device phone number..
var telephoneNumber = cordova.require("cordova/plugin/telephonenumber");
telephoneNumber.get(function(result) {
console.log("result = " + result);
alert('result : '+result);
}, function(error) {
console.log("error = " + error.code);
alert('Error: '+error);
});
I have put alert inside the error function to see the error message .Now i am trying to execute this on the mobile device but not getting any alert message too.In the above snippet i am missing one line to understand i.e
var telephoneNumber = cordova.require("cordova/plugin/telephonenumber");
In the above line i am not getting what is this cordova/plugin/telephonenumber .Is this some refrence file because i have no directory available with me like this ..Do i need to create a folder by name Cordova and plugin and put telephonenumber.js file inside to it..
Please help me with this ..Thanks..
Related
I'm trying to move a image stored in "temp files" directory to a directory created in file system, but nothing happens, the promise doesn't return error and success, absolutely nothing happens.
The cordova file plugin was added in my app:
I debugged the app in my device with Android Studio, and I saw an error in log cat:
"Error in Success callbackId: File285873816 : TypeError: fileSystem.getFile is not a function" in source: file:///android_asset/www/cordova.js
I gave an alert to display the fileSystem object in the callback function in ng-cordova.js, and this object don't contains the getFile() function:
$window.resolveLocalFileSystemURL(path, function (fileSystem) {
alert("fileSystem " + JSON.stringify(fileSystem));
Someone can help me?
You JSON file is not well-formed. Check all of them.
In my case I saw an meaningless text ("asd") at the end of Json file after last "}"
So I added console log for and detected which JSON is wrong. And removed wrong text in it.
Make sure you actually installed the plugin in your project. In my experience ng-cordova helps with the integration but you still need to add the plugin.
It was my mistake, in the function moveFile, I was sending the directory with the name of the file, in the moveFrom parameter in my service. The correct way is set only the directory:
$cordovaFile.moveFile(moveFrom, currentFileName, cordova.file.dataDirectory + moveTo, newFileName)
.then(function (success) {
alert("Yeah Success " + JSON.stringify(success));
}, function (error) {
alert("Fucking error " + JSON.stringify(error));
});
Cordova file could return an invalid directory error.
Thanks for your attention.
I am using this plugin and trying to trigger local notification for my Cordova iOS app with Local notifications plugin.
I dd following steps:
Installed plugin: cordova plugin add de.appplant.cordova.plugin.local-notification#0.7.7
Updated config.xml: gap:plugin name="de.appplant.cordova.plugin.local-notification"
Added the following JavaScript in head tag for
index.html
plugin.notification.local.promptForPermission(function (granted) {
alert("promptForPermission: "+granted);
});
plugin.notification.local.hasPermission(function (granted) {
alert("hasPermission: "+granted);
});
Have a button in index.html to create a local notification after 5 secs.
Code for that looks like this:
function setLocalNotification()
{
alert("from setLocalNotification");
var t = new Date();
t.setSeconds(t.getSeconds() + 3);
window.plugin.notification.local.add({
title: 'Scheduled with delay',
message: 'Test Message ',
date: t
});
alert("alert set");
};
I do see a prompt for user's permission and the alert from hasPermission method shows the value as true. But I am still not able to get the actual local notification I am trying to set by clicking a button. I have already updated the APPLocalNotification.m file for the this issue by copying this fix.
I don't see any more errors in the console log but I am still not able to trigger a local notification.
You should check if the device is ready ( document.addEventListener('deviceready', function () {
) and also check if the plugin is correctly added $ cordova plugin ls.
Make sure you have "< script type="text/javascript" src="cordova.js">
" in your html .
Good luck!
I'm trying to implement a Google+ Signin on a website, following instructions from here for a hybrid login system. I prefer to have my own button for login, so I chose to implement the G+ signin through plain JavaScript method gapi.auth.signIn, following instructions from here.
Here's the button I have on my main page that initiates the login -
<a id="gplogin" href="#">
<img src="{% static 'images/gp.png' %}"/>
</a>
Here's the corresponding JQuery piece that picks up the click, this is running fine too -
$('#gplogin').click(
function() {
GPLogin();
return false;
});
Here's the GPLogin() part, which is probably where it's throwing Javascript exception -
function GPLogin() {
// Define all the login params
var additionalParams = {
'clientid' : 'xxxxxxxx.apps.googleusercontent.com',
'scope' : 'https://www.googleapis.com/auth/plus.login',
'redirecturi' : 'postmessage',
'requestvisibleactions' : 'http://schema.org/AddAction',
'cookiepolicy' : 'single_host_origin',
'accesstype' : 'offline',
// 'approvalprompt' : 'force',
'callback': gpSigninCallback
};
console.log('Logging in to Google Plus with additional params - ');
for(var param in additionalParams)
console.log(param + " : " + additionalParams[param])
gapi.auth.signIn(additionalParams);
}
Here's my gpSigninCallback function which is never getting called, due to exception thrown when I click the 'gplogin' link
function gpSigninCallback(authResult) {
console.log("GP Signin response " + authResult);
for(var res in authResult)
console.log(res + " : " + authResult[res]) }
The exception that is being thrown when I click on the gplogin link is
Uncaught TypeError: Cannot convert object to primitive value at cb=gapi.loaded_0:41
as observed in Chrome.
The user selection popup comes up as expected and I can select the user, but nothing happens anywhere after that. I'm pretty sure it's a small thing I'm overlooking somewhere, but I cannot find it myself. Any help would be appreciated. Thank you !
After quite a bit of searching around, I narrowed it down to simple Javascript error on my part. I started by commenting all the debug statements and printing the objects as-is. That is where I discovered that my callback function was getting an object for authResult[res] in one of the iterations and since I was trying to concatenate it to a String, a TypeError was being thrown.
The Google Plus Login flow was fine all the time, with my JS being the issue. It worked in GPLogin() when trying to log additionalParams[param] because they're all strings and have no problems concatenating with Strings.
I am trying to send a picture from my phonegap app as an attachment using the email composer with attachments phone gap plugin. I cannot get it to work however.
I have tried two separate methods. The first is to use the Phonegap camera api's to pass an imageURI to email composer. The code for this is below:
function camera1()
{
navigator.camera.getPicture(sendEmail, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URI});
function sendEmail(imageURI) {
window.plugins.emailComposer.showEmailComposer("Test","Test","test#gmail.com","","",true,imageURI)
}
function onFail(message) {
alert('Failed because: ' + message);
}
}
This method launches the iphone camera app and allows me to take a picture. However, as soon as I hit the 'use' button I get the following error in my xcode debug console:
2013-01-06 17:57:50.741 Saffron Housing Mobile App[1203:907] -[_NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1dd9d6a0
2013-01-06 17:57:50.906 Saffron Housing Mobile App[1203:907] EmailComposer - Cannot set TO recipients; error: -[_NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1dd9d6a0
2013-01-06 17:57:50.914 Saffron Housing Mobile App[1203:907] -[_NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1dd1abf0
2013-01-06 17:57:50.916 Saffron Housing Mobile App[1203:907] EmailComposer - Cannot set attachments; error: -[_NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x1dd1abf0
2013-01-06 17:57:51.524 Saffron Housing Mobile App[1203:907] Warning: Attempt to present on while a presentation is in progress!
The second method I have tried to use is to save the image to local storage and then pass it as a variable to email composer. I also implemented a notification event in this method as the previous error message made me think that the email composer plugin was trying to open too quickly after the camera event (pure guess based on 'Warning: Attempt to present on while a presentation is in progress!') The code is as follows:
function camera1()
{
navigator.camera.getPicture(sendAlert, onFail, { quality: 20,
destinationType: Camera.DestinationType.FILE_URI});
localStorage.setItem('photo', imageURI);
function sendAlert()
navigator.notification.confirm('Send Picture?',sendEmail,'Send Picture?','Yes,No')
function sendEmail(1) {
var photo = localStorage.getItem('photo')
window.plugins.emailComposer.showEmailComposer("Test","Test","test#gmail.com","","",true,photo);
}
function onFail(message) {
alert('Failed because: ' + message);
}
}
The problem with this code is that the camera doesn't launch at all. Nothing happens when I click the button. Not even anything in the debug console.
To further complicate matters I tried just opening a basic email composer event to see that I had implemented the plugin properly. When not trying to attach a picture the email composer at least opens with my subject and body filled in. It doesn't fill in any recipients though. The code is:
function camera()
{
window.plugins.emailComposer.showEmailComposer("Test","Test","test#gmail.com","","",true,"")
}
My question is what am I doing wrong?
toRecipients, ccRecipients, bccRecipients, and attachments parameters should be arrays, but you're passing them as strings.
window.plugins.emailComposer.showEmailComposer("Test", "Test", ["test#gmail.com"], [], [], true, [imageURI]);
do it like this and try again.
i don't know if this is the cause of your error but the path of your attachment shoud be somewhat like ["/var/mobile/Applications/351............F3/yourapp.app/www/images/yourimage.png"]
I've decided that there are some errors which I don't want to go to the browser error handler. But I still want to know about them. In my actual code I have a function which stores the errors in a hidden element and ajax submits them to a database. Following is a simplified version of my try block:
try
{
newValueEvaled = eval(newValue);
}catch(err)
{
alert("Error caught: Line " + err.lineNumber + ((err.columnNumber != undefined)?', Column:' + err.columnNumber:"") + '\n' + err.message);
}
I'd like the columnNumber too. Currently it is never there, but somehow the browser error console has access to it. Can anyone tell me how I can get access to it as well?
I'm almost certain it's not possible to get the error column number from JavaScript running in the page. Firebug/WebKit console/IE console has access to internal browser objects that provide more information about the call stack than is available to code running inside the page.
You can access the error line and possibly column using a custom error handler function:
function dumpErrors(error, file, line, column)
{
alert('Error: ' + error + ', occurred in file: ' + file + ', on line: ' + line + ', at column: ' + (column || 'unknown'));
}
onerror = dumpErrors;
The «line» is available for all browsers. For the «column», it seems it's available on latest Chrome (release 30.0+), but not on Firefox (release 17, running on my Linux).