I am working on cordova email composer to send emails. But I am getting the error "email plugin not available" when I tried to execute the app.
When I add
< gap:plugin name="de.appplant.cordova.plugin.email-composer" version="0.8.2" />
to the config file I am getting errors. Here is my code.
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
// specify contact search criteria
var options = new ContactFindOptions();
options.filter=""; // empty search string returns all contacts
options.multiple=true; // return multiple results
filter = ["displayName"]; // return contact.displayName field
// find contacts
navigator.contacts.pickContact(function(contact){
console.log("The following contact has been selected:" + JSON.stringify(contact));
},function(err){
console.log("Error: " + err);
});
}
// onSuccess: Get a snapshot of the current contacts
//
function onSuccess(contacts) {
for (var i=0; i<contacts.length; i++) {
alert(contacts[i].displayName);
}
};
// onError: Failed to get the contacts
//
function onError(contactError) {
alert("onError!");
};
document.addEventListener("deviceready", draftEmail, false);
function draftEmail(subject, message) {
if (!cordova.plugin){
//non-mobile - plugins are not present.
alert("Email plugin is not available");
return;
}
if (!isAvailable){
//mobile, but no email installed
alert("Email is not available")
return;
}
cordova.plugins.email.addAlias('gmail', 'com.google.android.gm');
cordova.plugins.email.open({
app: 'gmail',
subject: 'Sent from Gmail',
body: 'How are you?',
isHtml: true
})
}
</script>
</head>
<body>
</body>
</html>
Config file:
<feature name="EmailComposer"> <param name="android-package" value="de.appplant.cordova.plugin.emailComposer.EmailComposer" /> </feature>
<feature><gap:plugin name="de.appplant.cordova.plugin.email-composer" version="0.8.0" /></feature>
</widget>
In draftEmail, you are checking for cordova.plugin but not cordova.plugins, hence you are getting the error alert.
Cross-answering your cross-post :)
Related
I am able to retrieve information from the current user in Parse, however, I would like to be able to retrieve information from anyone but the current user.
For example, this is how I retrieve and display information about the current user:
Parse.initialize("ID", "ID");
angular.module('AuthApp', [])
.run(['$rootScope', function($scope) {
$scope.currentUser = Parse.User.current();
than in the html I refer to it as such:
{{currentUser.get('username')}}
I do not want pull information from the current user but another user as determined by their objectID.Hence, my question is how would pull information of lets say a user with objectid 17845
Update:
<script type="text/javascript">
$(document).ready(function() {
// ***************************************************
// NOTE: Replace the following your own keys
// ***************************************************
var userID = document.getElementById("txtUserID").value;
Parse.initialize("ID", "ID");
var userInfo = Parse.Object.extend("User");
var query = new Parse.Query(userInfo);
query.get(userID, {
success: function(userInfo) {
// The object was retrieved successfully.
var score = userInfo.get("Address");
var message = 'Address: ' + score;
document.getElementById('address').innerHTML = message;
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
});
</script>
</head>
<body ng-app="AuthApp">
<div ng-show="currentUser">
<input name="txtUserIDName" id="txtUserID" type="text" value="Please enter your user ID">
</div>
</div>
</body>
</html>
Update 2:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
<script src="http://www.parsecdn.com/js/parse-1.2.12.min.js"></script>
<link href="css/bootstrap.min.css" rel="stylesheet">
<!--======================================================================-->
<!--Custom website css file is linked here-->
<link href="css/style1.css" rel="stylesheet">
<!--Font Awesome CSS link-->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!--=================================================-->
<!--Javascript file linked here-->
<script src="js/bootstrap.min.js"></script>
<script src="js/personal.js"></script>
<script src="js/functions.js"></script>
<meta charset=utf-8 />
<title>Admin Panel</title>
<script type="text/javascript">
$(document).ready(function() {
// ***************************************************
// NOTE: Replace the following your own keys
// ***************************************************
Parse.initialize("ID", "ID");
app.controller('MainCtrl', function($scope) {
$scope.userIdChanged = function () {
var query = new Parse.Query(Parse.User);
query.get($scope.userId, {
success: function(userInfo) {
// The object was retrieved successfully.
var address = userInfo.get("Address");
$scope.address = 'Address: ' + address;
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
};
});
</script>
</head>
<body ng-Controller="MainCtrl">
userId: <input type="text" ng-model="userId" ng-blur="userIdChanged()"/>
<div>{{address}}</div>
</body>
</html>
var query = new Parse.Query(Parse.User);
query.get('17845', {
success: function(userInfo) {
// The object was retrieved successfully.
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
Update answer:
Instead of using dom manipulation javascript such as document.getElementById and jquery $(document).ready, you should use angular databinding. There is no need to use var userInfo = Parse.Object.extend("User"); as that is already available in Parse.User.
app.controller('MainCtrl', function($scope) {
$scope.userIdChanged = function () {
var query = new Parse.Query(Parse.User);
query.get($scope.userId, {
success: function(userInfo) {
// The object was retrieved successfully.
var address = userInfo.get("Address");
$scope.address = 'Address: ' + address;
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
};
});
Html:
I'm using ng-blur here which will call userIdChanged method on scope when value is changed and textbox has lost focus. You could also have a button and use ng-click.
<body ng-Controller="MainCtrl">
userId: <input type="text" ng-model="userId" ng-blur="userIdChanged()"/>
<div>{{address}}</div>
</body>
This question already has an answer here:
Email plugin not available
(1 answer)
Closed 8 years ago.
how to send e-mail in android using cordova. i've been trying since two days but i'm getting an error like e-mail plugin not available. been trying with this code but cannot get my desired result. dont know were the problem is...
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady(){
var options = new ContactFindOptions();
navigator.contacts.pickContact(onSuccess, function(contact){
console.log('The following contact has been selected:' + JSON.stringify(contact));
},function(err){
console.log('Error: ' + err);
});
}
document.addEventListener("deviceready", draftEmail, false);
function draftEmail(subject, message) {
if (!cordova.plugin){
//non-mobile - plugins are not present.
alert("Email plugin is not available");
return;
}
if (!isAvailable){
//mobile, but no email installed
alert("Email is not available")
return;
}
cordova.plugins.email.addAlias('gmail', 'com.google.android.gm');
cordova.plugins.email.open({
app: 'gmail',
to: 'abcd#gmail.com',
subject: 'Sent from Gmail',
body: 'How are you?',
isHtml: true
})
}
</script>
</head>
<body>
</body>
</html>
In draftEmail, you are checking for cordova.plugin but not cordova.plugins, hence you are getting the error alert.
Contact Example
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
var myContact = navigator.contacts.create({"displayName": "Test User"});
myContact.note = "This contact has a note.";
console.log("The contact, " + myContact.displayName + ", note: " + myContact.note);
}
</script> </head> <body>
<h1>Example</h1>
<p>Create Contact</p> </body> </html>
I Compiled this code and tried on my android contacts not creating Test user"
Add save() after you create the contact and populate the properties...
function onDeviceReady() {
var myContact = navigator.contacts.create({"displayName": "Test User"});
myContact.note = "This contact has a note.";
myContact.save(function() {
console.log("contact saved");
},
function() {
console.log("could not save contact");
});
console.log("The contact, " + myContact.displayName + ", note: " + myContact.note);
}
i am creating an phonegap application where user will capture some pictures and attach it to predefined mail id. Iam able to capture image but unable to attach all picture in app folder i.e "/mnt/sdcard/Android/data/pacakgename/cache/".
I tried to implement as in this for dynamic attachment.
My codes are below:
<html>
<head>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="emailcomposer.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", deviceready, true);
function deviceready() {
console.log("Device ready");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, onFail);
}
function gotFS(fileSystem) {
var reader = fileSystem.root.createReader();
reader.readEntries(gotList, onFail);
}
function gotList(entries) {
var i;
var fullPath = "/mnt/sdcard/Android/data/packagename/cache/";
for (i=0; i<entries.length; i++) {
if (entries[i].name.indexOf(".jpg") != -1) {
console(entries[i].fullPath);
}
}
}
function composeText(){
var message1 = document.getElementById('message_body').value;
console.log(message1);
window.plugins.emailComposer.showEmailComposer(
"Get an Estimate",
message1,
["sth#mail.com"],
[],
[],
true,
[attachment link]
);
//exit the app after clicking this button
navigator.app.exitApp();
// navigator.camera.cleanup(onSuccess,fail);
// function onSuccess(){
// }
// function fail(){
// }
}
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
<style type="text/css">
li{
list-style: none;
float:left;
padding: 0 5 5 0 ;
}
</style>
</head>
<body>
<h1>Get a Repair Estimate</h1>
<div style="clear:both;"></div>
Provide any details you want us to know(Optional):
<ul>
<li>
<textarea style="width:250px;height:250px;" name="message_body" id = 'message_body' placeholder="Add Notes here(if any)"></textarea>
</li>
<div style="clear:both;"></div>
<li>
<button onclick="composeText();">Get Your Estimate</button>
</li>
</body>
</html>
Any Help.
I got the solution for this. I was unable to understand fileDirectory api of phonegap that caused problem for me.
I solved my problem with following code:
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem) {
fileSystem.root.getDirectory("MyAppFolder", {
create: true
},
function(directory) {
console.log("Final 63" + directory.fullPath);
attachPaths = directory.fullPath;
var attachPath=attachPaths.slice(7,attachPaths.length);
var directoryReader = directory.createReader();
directoryReader.readEntries(function(entries) {
var i;
for (i=0; i<entries.length; i++) {
console.log(entries[i].name);
attachFile[i] =attachPath + "/" + entries[i].name;
}
console.log(attachFile);
},
function (error) {
alert(error.code);
});
});
}, function(error) {
alert("can't even get the file system: " + error.code);
});
Now, we can pass attachFile to emailcomposer plugin:
window.plugins.emailComposer.showEmailComposerWithCallback(null,
"Get an Estimate",
"Here is the mail body"
["to"],
[cc],
[bcc],
true,
attachFile
);
I have solved it Please go through this link regarding my full answer. I posted my answer as i didn't wanted it to unsolved question.
I used this emailcomposer plugin
Hope, it may help someone.
I am creating a phonegap app to fetch contacts and save them in the database. I have created two empty global arrays at the top that will save the phone number and display name of a person which will be later stored in a database table. To check that the contacts are successfully saved in the array, I have created a test_data() function.
Now my problem is that the test_data() code is not working and no values are displayed in the log. Now if I move that code from test_data() function to onSuccess() it works fine. Here is the code. Isn't it the proper way to declare global a array in JS.
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8">
var gcont = []; var gphon = [];
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
// find all contacts with 'Bob' in any name field
var options = new ContactFindOptions();
options.filter="";
options.multiple=true;
var fields = ["displayName", "phoneNumbers"];
navigator.contacts.find(fields, onSuccess, onError, options);
test_data();
}
// onSuccess: Get a snapshot of the current contacts
//
function onSuccess(contacts) {
for(var index=0;index<contacts.length;index++){
gcont[index] = contacts[index].displayName;
gphon[index] = contacts[index].phoneNumbers[0].value;
}
}
function test_data(){
for (z=0;z<gcont.length;z++){
console.log(gcont[z]);}
}
// onError: Failed to get the contacts
//
function onError(contactError) {
alert('Error With Contacts!');
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Find Contacts</p>
</body>
</html>
The call to test_data() doesn't work in onDeviceReady() because the onSuccess callback to contacts.find is asynchronous and the arrays have not been populated when test_data() is executed.