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);
}
Related
I have a problem please help me,
I have a sound recording page without interface, but I can not know which audio track was recorded,
Is there a way to know the track of a recorded sound or not?
I just want the audio track to play the audio track
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
recordAudio();
}
// Record audio
//
function recordAudio() {
var srcd = "myrecording" + Math.random() + ".wav";
var mediaRec = new Media(srcd, onSuccess, onError);
// Record audio
mediaRec.startRecord();
// Stop recording after 10 sec
var recTime = 0;
var recInterval = setInterval(function () {
recTime = recTime + 1;
setAudioPosition(recTime + " sec");
if (recTime >= 10) {
clearInterval(recInterval);
mediaRec.stopRecord();
}
}, 1000);
}
function onSuccess() {
alert('Uploaded Successfully');
}
// onError Callback
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
// Set audio position
//
function setAudioPosition(position) {
document.getElementById('audio_position').innerHTML = position;
}
</script>
</head>
<body>
<button onclick="recordAudio()">Record Audio</button>
<p id="media">Recording audio...</p>
<p id="audio_position"></p>
<br>
</body>
</html>
Hello i try to get myTasks for the current User from sharepoint 2013. I tried it with the Rest-API and with JSON but i always get an error. Acording to the debugger ExecuteOrDelayUntilScriptLoaded is undefined.
Here is my little Javascript i got so far:
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.0/jquery-ui.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/knockout/knockout-2.1.0.js"></script>
<script type="text/javascript" src="/sps10/EDV/jquery.js"></script>
<script type="text/javascript">
var context, userSessionManager ,userSession , query , myTasks ;
$(document).ready(function () {
ExecuteOrDelayUntilScriptLoaded(function () {
context = SP.ClientContext.get_current();
ExecuteOrDelayUntilScriptLoaded(function () {
userSessionManager = new SP.WorkManagement.OM.UserOrderedSessionManager(context);
userSession = userSessionManager.createSession();
query = new SP.WorkManagement.OM.TaskQuery(context);
myTasks = userSession.readTasks(query);
}, "sp.workmanagement.js");
getMyTasks();
}, "sp.js");
});
function getMyTasks() {
context.load(myTasks);
context.executeQueryAsync(onGetMyTasksSuccess, onGetMyTasksFail);
}
// This function is executed if the above call is successful
function onGetMyTasksSuccess() {
console.log("Successfully retrieved tasks...");
var taskEnumerator = myTasks.getEnumerator();
while (taskEnumerator.moveNext()) {
var task = taskEnumerator.current;
console.log("Task: " + task.get_id() + " - " + task.get_name());
}
}
// This function is executed if the above call fails
function onGetMyTasksFail(sender, args) {
console.log('Failed to get tasks. Error:' + args.get_message());
}
</script>
So any help or advise would be great. If you want i can post my Code with the rest-api too but the error stays the same.
Thanks for your help and time.
Here is now the way to query the tasks from my site in a html file with javascript. The most important thing is to load the src file in the right order and to use only the jquery-min file not the normal jQuery file.
<script src="/_layouts/15/init.js" type="text/javascript"></script>
<script src="/_layouts/15/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.core.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.runtime.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.js" type="text/javascript"></script>
<script src="/_layouts/15/sp.workmanagement.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
'use strict';
var context = new SP.ClientContext.get_current();
var userSessionManager = new SP.WorkManagement.OM.UserOrderedSessionManager(context);
var userSession = userSessionManager.createSession();
var query = new SP.WorkManagement.OM.TaskQuery(context);
var myTasks = userSession.readTasks(query);
var tasks = [];
getMyTasks();
function getMyTasks() {
context.load(myTasks);
context.executeQueryAsync(onGetMyTasksSuccess, onGetMyTasksFail);
}
function onGetMyTasksSuccess() {
console.log("Successfully retrieved tasks...");
var taskEnumerator = myTasks.getEnumerator();
while (taskEnumerator.moveNext()) {
var task = taskEnumerator.current;
console.log("Task: " + task.get_id() + " - Taskname: " + task.get_name() + " - Beschreibung: " + task.get_description() + " - dueDatum: " + task.get_dueDate() + " - Startdatum: " + task.get_startDate() + " - Persönlich: " + task.get_isPersonal() + " - Fertiggestellt: " + task.get_isCompleted());
tasks.push({
taskName: task.get_name(),
description: task.get_description(),
dueDate: task.get_dueDate(),
startDate: task.get_startDate(),
personally: task.get_isPersonal(),
complete: task.get_isCompleted()
});
}
console.log(tasks);
}
// This function is executed if the above call fails
function onGetMyTasksFail(sender, args) {
console.log('Failed to get tasks. Error:' + args.get_message());
}
And here is a nice little blog post with all the possibilities:
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 :)
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 trying to get this particular piece of code working.
It works fine in the developer console, but fails when try it on my computer in a html file. It gives me a error in the pop up which says [object Object]. Could really use some help here. I don't know why is code entering into the error handler while it works fine in the developer console of LinkedIn.
Thanks!
<html>
<head>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: my_actual_key
authorize: false
credentials_cookie: true
credentials_cookie_crc: true
onLoad: onLinkedInLoad
</script>
</head>
<body>
<p>This example demonstrates the use of a login button to control what's displayed. It also demonstrates how to use the LinkedIn auth events in a user flow.</p>
<div id="loginbadge">
<p>Login badge renders here if the current user is authorized.</p>
</div>
<!-- NOTE: be sure to set onLoad: onLinkedInLoad -->
<script type="text/javascript">
function onLinkedInLoad() {
IN.Event.on(IN, "auth", function() {onLinkedInLogin();});
IN.Event.on(IN, "logout", function() {onLinkedInLogout();});
}
function onLinkedInLogout() {
setLoginBadge(false);
}
function onLinkedInLogin() {
// we pass field selectors as a single parameter (array of strings)
IN.API.Connections("me")
.fields(["id", "firstName", "lastName", "pictureUrl", "publicProfileUrl"])
.result(function(result) {
setLoginBadge(result.values[0]);
})
.error(function(err) {
alert(err);
});
}
function setLoginBadge(profile) {
if (!profile) {
profHTML = "<p>You are not logged in</p>";
}
else {
var pictureUrl = profile.pictureUrl || "http://static02.linkedin.com/scds/common/u/img/icon/icon_no_photo_80x80.png";
profHTML = "<p><a href=\"" + profile.publicProfileUrl + "\">";
profHTML = profHTML + "<img align=\"baseline\" src=\"" + pictureUrl + "\"></a>";
profHTML = profHTML + " Welcome <a href=\"" + profile.publicProfileUrl + "\">";
profHTML = profHTML + profile.firstName + " " + profile.lastName + "</a>! logout</p>";
}
document.getElementById("loginbadge").innerHTML = profHTML;
}
</script>
<!-- need to be logged in to use; if not, offer a login button -->
<script type="IN/Login"></script>
</body>
</html>
Try replacing
IN.API.Connections("me")
with
IN.API.Profile("me")