Send sms in Cordova 3.4 - java

I am new in cordova 3.4. I want to write send sms app. I get SMSPlugin from github but i want to write this myself. I write a html file like this and copy in root/www and i write a java script file in root/www/js. but when i run the app, i don't see button in the page! Why? What is problem? How can i write this app?
And i change name of java file(Activity) from AndroidManifest manually to my class, this is not a problem, Yes? and i changed 'id' in widget tag from config.xml to my package manually.
index.html:
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
<script type="text/javascript">
var txtMSG = "";
function onDeviceReady(){
document.getElementById("deviceName").innerHTML= device.model;
document.getElementById("version").innerHTML= device.cordova;
document.getElementById("mobilePlatform").innerHTML= device.platform;
document.getElementById("platformVersion").innerHTML= device.version;
document.getElementById("uuid").innerHTML= device.uuid;
document.getElementById("sendSMS").style.display="block";
}
function displayTextMessage(msg){
alert(msg);
$('#text-messages').prepend('<div>' + msg + '</div>');
}
function sendConsole(){
var message = "This_is_a_test"
DeviceInfo.SendConsole({text: message}, function(){
alert("success");
}, function(){
alert("fail");
});
}
function SendSMS(){
console.log("-------------------Start----------------------");
DeviceInfo.SendSMS({phoneNumber:[document.getElementById('cellNumber').value], text: document.getElementById('textMessage').value}, function(){
alert("success");
}, function(){
alert("fail");
});
console.log("---------------------End--------------------");
}
/** Called when browser load this page*/
function init(){
document.addEventListener("deviceready", onDeviceReady, false);
}
</script>
</head>
<body>
<input id="sendSMS" style="display:none" type="button" ontouchend="SendSMS()" onclick="SendSMS()" value="Send SMS To:" />
<!-- <button onClick="SendSMS();">Send SMS</button> <br> -->
<input id="cellNumber" type="text" style="width:100%" value="9126012134" onclick="this.select()" ontouchend="this.select()" />
<textarea id="textMessage" style="width:100%; height:100px">Plugin Example</textarea>
<input id="sendConsole" style="display:none" type="button" ontouchend="sendConsole()" onclick="sendConsole()" value="Send Console Log" />
<div id="text-messages" style="border:solid 1px #efefef; padding 10px"></div>
</body>
</html>
DeviceInfo.js:
var DeviceInfo = function () { };
DeviceInfo.callMethod = function (methodName, content, success, fail) {
return PhoneGap.exec(function (args) {
success(args);
}, function (args) {
fail(args);
}, 'DeviceInfo', methodName, [content]);
}
DeviceInfo.GetPhoneNumber = function (content, success, fail) {
return DeviceInfo.callMethod('getPhoneNumber', content, success, fail);
};
DeviceInfo.SendSMS = function (content, success, fail) {
return DeviceInfo.callMethod('SendSMS', content, success, fail);
};
DeviceInfo.SendConsole = function (content, success, fail) {
return DeviceInfo.callMethod('SendConsole', content, success, fail);
};
Thanks for advises

There is a plugin on ghithub developed by javatechig here but only work with old cordova/phonegap version. This fork https://github.com/aharris88/phonegap-sms-plugin works with recent version of cordova and is updated frequently. Read the "readme.md" for example and more informations.
This Android Phonegap plugin allows you to easily send SMS in android using both native SMS Manager or by invoking the default android SMS app

Related

steps for share on LinkedIn using API

I am having difficulty getting a share on LinkedIn. I am trying to post a LinkedIn share update via its Share on LinkedIn API. Does anyone can tell me how to post on linked share update and give me steps to manage it.
First you have to sign into LinkedIn Developers and create an app to get the API code specific to your application: Login Here
Then, the quickest way for you to learn is to look at some examples. Here is a working version of what you are trying to code: http://datopstech.com/linkedin-share-tool/
The only thing you NEED to change to get this code running for yourself is the API_Key found in the HTML snippet.
The source for this can be found here or, I copied and pasted relevant pieces below for reference:
$(document).ready(function(){
$("#submit_button").click(function organizeinput(){
if (IN.User.isAuthorized() == true){
var values = new Array();
//comment, title, description, image-content, image-url
// Get the parameters as an array
values = $(":input").serializeArray();
// Find and replace `content` if there
var countinput=0;
for (index = 0; index < values.length; ++index)
{
if (values[index].name == "comment" && values[index].value != "")
{
var comment;
comment = values[index].value;
countinput=countinput+1;
}
if (values[index].name == "title" && values[index].value != "")
{
var title;
title = values[index].value;
countinput=countinput+1;
}
if (values[index].name == "description" && values[index].value != "")
{
var description;
description = values[index].value;
countinput=countinput+1;
}
if (values[index].name == "image-content" && values[index].value != "")
{
var imagecontent;
imagecontent = values[index].value;
countinput=countinput+1;
}
if (values[index].name == "image-url" && values[index].value != "")
{
var imageurl;
imageurl = values[index].value;
countinput=countinput+1;
}
}
if (countinput == 5){
var postcontent = new Array();
postcontent = {"comment": comment, "content": {"title": title,"description": description,"submitted-url": imagecontent,"submitted-image-url": imageurl},"visibility": {"code": "anyone"} };
postcontent = JSON.stringify(postcontent);
shareContent(postcontent);
}
else alert("All the fields are required.");
}
else alert("You have to login to linkedin before you can post content.");
});
function onLinkedInLoad() {
IN.Event.on(IN, "auth", organizeinput);
}
// Handle the successful return from the API call
function onSuccess(data) {
console.log(data);
alert("Post Successful!");
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
alert("Oh no, something went wrong. Check the console for an error log.");
}
// Use the API call wrapper to share content on LinkedIn
function shareContent(pcontent) {
IN.API.Raw("/people/~/shares?format=json")
.method("POST")
.body(pcontent)
.result(onSuccess)
.error(onError);
}
//function executepost (pcontent)
//{
//$.post("https://api.linkedin.com/v1/people/~/shares?format=json", postcontent, function() {return null;});
// Setup an event listener to make an API call once auth is complete
//}
});
/*
$.ajax({
url: "https://api.linkedin.com/v1/people/~/shares?format=json",
type: 'post',
data: postcontent,
headers: {
'Content-Type': 'application/json',
'x-li-format': 'json'
},
dataType: 'json',
success: function (data) {
console.info(data);
}
});*/
// Convert to URL-encoded string
//values = jQuery.param(values);
/*
if (crflag ==1)
{
$.post("index.php", values, function(response) {processdata(response); return response;});
}
else
{
alert("Sorry, looks like we are missing some input");
}
//$.post("db_insert.php", $(":input").serializeArray(), function(tabledata){$("#result").html(tabledata);});
*/
Status API Training Shop Blog About Pricing
© 2016 GitHub, Inc. Terms Privacy Security Contact Help
<DOCTYPE html>
<html lang="en">
<head>
<title>Linkedin Share Link With Image, Choose Picture for Hyperlink Thumbnail, JSON Post Developer, Web Tool, Without Meta Property og: tag Online</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- add jQuery -->
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<!-- add bootstrap -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!-- user typed js for form -->
<script src="postscript.js"></script>
<!-- initialize LinkedIn JS SDK -->
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: //YOUR API KEY HERE
authorize: true
//onLoad: onLinkedInLoad
</script>
</head>
<body>
<div class="wrap">
<h1 align="center">Create An Advanced LinkedIn Post</h1>
<p align="center">Configure a share post for Linkedin. First, authorize through LinkedIn by logging in.</br> Then, fill out all of the fields below and click submit to share the content.</br></br><script type="in/Login"></script></p> <br><br>
<div class="col-md-4"><!--quick spacer :)--></div>
<div class="col-md-5">
<form name="post_content" action="" method="post">
<label for="comment">Comment: </label>
<input type="text" class="form-control" name="comment" placeholder="Comment" required></input><br>
<label for="title">Title: </label>
<input type="text" class="form-control" name="title" placeholder="Title" required></input><br>
<label for="description">Description: </label>
<input type="text" class="form-control" name="description" placeholder="Description" required></input><br>
<label for="image-content">Link to Content: </label>
<input type="text" class="form-control" name="image-content" placeholder="http://example.com/content" required></input><br>
<label for="image-location">Image Location: </label>
<input type="text" class="form-control" name="image-url" placeholder="http://example.com/images/example.jpg" required></input><br><br>
<input type="button" id="submit_button" value="Submit" class="btn btn-default"></input>
</form>
</div>
</div>
</div>
<div id="VINoutput"></div>
</body>
</html>
Just use a URL like this...
https://www.linkedin.com/sharing/share-offsite/?url={url}
Source: Microsoft LinkedIn Share URL Documentation.
For example, this works for me:
https://www.linkedin.com/sharing/share-offsite/?url=http://www.wikipedia.org/
Demonstration:

Cannot call Play Framework static method from view

I have server and I should make request on button pressed also I have to call this method and when it is works I should parse json but my doesn't see controller method only main method is available
How to call
<input type="submit" onclick="#routes.Login.resp()" value="LOGIN" >
because it is not worrking Cannot resolve symbol
GET /login controllers.Login.main()
My controller:
package controllers;
import play.libs.F;
import play.libs.WS;
import play.mvc.Controller;
import play.mvc.Result;
public class Login extends Controller {
public static Result main() {
return ok(views.html.login.render());
}
public static F.Promise<Result> resp() {
String feedUrl="http://validate.jsontest.com/?json=%7B%22key%22:%22value%22%7D";
final F.Promise<Result> resultPromise = WS.url(feedUrl).get().flatMap(
new F.Function<WS.Response, F.Promise<Result>>() {
public F.Promise<Result> apply(WS.Response response) {
return WS.url(response.asJson().findPath("empty").asText()).get().map(
new F.Function<WS.Response, Result>() {
public Result apply(WS.Response response) {
return ok("size" + response.asJson().findPath("count").asInt());
}
}
);
}
}
);
return resultPromise;
}
}
view:
<!--
Author: W3layouts
Author URL: http://w3layouts.com
License: Creative Commons Attribution 3.0 Unported
License URL: http://creativecommons.org/licenses/by/3.0/
-->
<!DOCTYPE html>
<html>
<head>
<title>LOGIN</title>
<meta charset="utf-8">
<link rel="stylesheet" media="screen" href="#routes.Assets.at("stylesheets/stylelogin.css")">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!--webfonts-->
<link href='http://fonts.googleapis.com/css?family=Open+Sans:600italic,400,300,600,700' rel='stylesheet' type='text/css'>
<!--//webfonts-->
</head>
<body>
<!-----start-main---->
<div class="main">
<div class="login-form">
<h1>Member Login</h1>
<div class="head">
<img src="#routes.Assets.at("images/user.png")" alt=""/>
</div>
<form>
<input type="text" class="text" value="USERNAME" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'USERNAME';}" >
<input type="password" value="Password" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Password';}">
<div class="submit">
<input type="submit" onclick="#routes.Login.main()" value="LOGIN" >
</div>
</form>
</div>
<!--//End-login-form-->
<!-----start-copyright---->
<!-----//end-copyright---->
</div>
<!-----//end-main---->
</body>
</html>
I am not sure if I also parse json properly,how to make proper GET,POST requests and parse it
As far as I know with the onclick attribute you always call a function in your JavaScript. If you want to specify an URL you need to put it into your form tag with an action attribute like <form action="#routes.Login.main()">.
The default for the HTML form tag is to send a GET. If you want to send a POST you have to specify it via an additional method="post" like <form action="#routes.Login.main()" method="post">. But then you have to change your routing too: POST /login controllers.Login.main(). If you want to post login data I'd strongly recommend to use POST because with GET your data including the password turns up in the query string of your URL.
Additionally your #routes.Login.main() method just returns the login view return ok(views.html.login.render());. Instead it should evaluate the form data you are sending.

how to use jquery ajax in jsp ?

i have written a small code which inclued 2 jsp pages and
1) test2.jsp --> i have made a dropdown in this page
2) test3.jsp --> displays a welcome message when the person selects an option from the dropdown ,
he will migrate to this page without refreshing test2.jsp
for this i have used ajax jquery
when i click on the submit button nothing happens , please help me with this
i have also put the org.json.jar file in the libraries
test2.jsp code
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//malsup.github.com/jquery.form.js"></script>
<script>
function check()
{
$.ajax({
url: "test3.jsp",
type: "GET",
success: function() {
alert("succes");
},
error: function() {
alert( "Sorry, there was a problem!" );
}
});
}
</script>
</head>
<body>
<h1>Hello World!</h1>
<br>
<form method="post" action="test2.jsp">
<select name="city">
<option value="dropdown">select city</option>
<option value="jal">Jalandhar</option>
<option value="ggn">Gurgaon</option>
<option value="noida">Noida</option>
<option value="amrtsr">Amritsar</option>
<option value="bombay">Bombay</option>
</select>
<input type="submit" value="Submit" onclick="check()">
</form>
test3.jsp code
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>welcome</h1>
</body>
</html>
The function should return false to prevent form submittion
<script>
function check() {
$.ajax({
url: "test3.jsp",
type: "GET",
success: function() {
alert("succes");
},
error: function() {
alert( "Sorry, there was a problem!" );
}
});
return false;
}
</script>
It should be
<input type="button" value="Submit" onclick="check()">
instead of
<input type="submit" value="Submit" onclick="check()">
because submit input type call form's action that is test2.jsp.
call your javascript function on change event of drop down
onchange="check()"
and navigate through firebug and check your consol it will show you your whole ajax request

Unable to initiate ajax call from jquery

I am new to ajax and jquery and trying to place an ajax call in my code. But below are the error messages I get when placing alerts:
jqxhr.status = 404
thrown error = Not Found
jqxhr.statusText = Not Found
request = undefined
error = undefined
What I want to do:
Open a modal dialog with just a Fancy text box (Tinymce) on click of an "Edit gif". After the contents are edited in the textbox, and the "Save" button in the modal dialog is clicked, initiate an ajax call to save the contents in the Database.
What is happening:
The modal dialog opens correctly, I am able to see that the "data" part for the ajax call is populated correctly (placed alerts to confirm). I believe the url is also correct. If I type the url in a browser, the control does go to my servlet as per web.xml (Sysout in Servlet gets printed). But somehow, the ajax call never goes through to the server after click of "Save" button. Will be really great if one of you can help me out here, will greatly appreciate it. My JSP (copied what I feel is relevant alone):
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="css/sis.css" media="screen" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/jquery-ui-1.10.3.custom">
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-ui.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/tinymce/tinymce.min.js"></script>
<script>
$(function() {
$("#dialog-form2").dialog({
autoOpen: false, width: 500, modal: true,
buttons: {
"Save": function() {
tinymce.get("stChallenge").setContent(tinyMCE.get("edChallenge").getContent());
alert($("#ChalId").val());
alert(tinyMCE.get("edChallenge").getContent());
var xhr =
$.ajax({
url: "/AjaxServlet?method=updateChal&keyword=dummy",
type: "GET",
data: {
CommentId: $("#ChalId").val(),
challenge: tinyMCE.get("edChallenge").getContent()
},
success: function (result) {
alert("Success :" + result);
$(this).dialog("close");
},
error:function (jqxhr, ajaxOptions, thrownError, request, error) {
alert('jqxhr.status = ' + jqxhr.status + '\n' + 'thrown error = ' + thrownError + '\n' + 'jqxhr.statusText = ' + jqxhr.statusText + '\n' +
'request = ' + request + '\n' + 'error = ' + error);
$(this).dialog("close");
}
});
},
Cancel: function() {
$(this).dialog("close");
}
},
close: function() {
}
});
$("#Edit2")
.click(function() {
$("#dialog-form2").dialog("open");
});
});
</script>
<script type="text/javascript">
tinymce.init({
selector: "#edChallenge", theme: "modern",
plugins: [
],
image_advtab: false
});
</script>
<script type="text/javascript">
tinymce.init({
selector: "#stChallenge", theme: "modern", readonly: true, toolbar: "false", menubar: "false",
plugins: [
],
image_advtab: false
});
</script>
</head>
<body>
<c:set var="model" value="${sessionScope.model}" />
<html:form action="managePerf.do?method=showPerf" method="post" styleId="ManagePerfForm">
<html:errors/>
Date: <html:text property="rankDate" styleId="datepicker" name="ManagePerfForm" />
<html:submit value="Go" styleClass="input button"/>
<fieldset>
<table border="0">
<tr>
<td>
<div id="dialog-form2" title="Edit Challenges">
<form>
<textarea cols="75" rows="50" id="edChallenge">${comments}</textarea>
</form>
</div>
<label>Challenges</label>
<a href="javascript:void(0);" id="Edit2">
<img src='${pageContext.request.contextPath}/img/Edit.gif' height="32" width="32"/>
</a>
<div id="dTextBox" class="ui-widget">
<textarea cols="75" rows="15" id="stChallenge" readonly="true">${comments}</textarea>
</div>
<input type="hidden" id="ChalId" value=${CommentId} />
</td>
</tr>
</table>
</fieldset>
</html:form>
</body>

how can get response from <form target="IFrame">

There is a simple web page which sends request, handles & manipulated by a servlet class and send back the response text.while i want ajax type handleing the request at client side that is why i am giving the response target to a invsible iframe. *but i want to print success on the page after iframe gets the response *
<html> <body>
<form action="test" method="post" target="IFrame"> /*response target is iframe*/
<input type="text" name="logic" />
<input type="submit" value="Submit" />
</form>
<iframe name="IFrame" style="width:0; height:0"> </iframe>
</body> </html>
i think this can be done using javascript or jquery, please guid me if you have any idea.
In the page which loads in the iframe, you will need to invoke a parent function.
<!-- This is the Parent. Call it JSTest1.html -->
<html>
<head>
</head>
<body>
<script type="text/javascript">
function parentAlert() {
alert('hey there from the parent');
}
</script>
I'm the parent
<iframe src="/JSTest2.html"></iframe>
</body>
<!-- this is the iframe html loaded. Call it JSTest2.html-->
<html>
<head>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready( function() {
window.parent.parentAlert();
});
</script>
In the Iframe.
</body>
To send a message from Iframe to Parent window page:
<script type="text/javascript">
$(document).ready( function() {
//Message part is two parts Event name and Data you want to send
// Example message = "my_action,my_data"
message = "my_action,my_data"
parent.postMessage(message, "*");
});
</script>
At the parent window you can do the following to listen to this message and capture it:
var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
var eventer = window[eventMethod];
var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
eventer(messageEvent,function(e) {
// Youe message which you send is captured here in e.data will split it on ',' to get the event and the data
message = e.data.split(',')[0]
value = e.data.split(',')[1]
if ( message === "my_action" ) {
myParentFunction(value)
}
},false);

Categories