I'm trying to send a message using The "Sendsms"plugin for phone gap on Android.
But when I call the function, I get this error:
Uncaught TypeError: Cannot call method 'send' of undefined at file
This is the JS code I'm using :
function onDeviceReady () {
$('#send').bind('click', function () {
alert('Phone: ' + $('#friendName').val() + ' Message: ' + $('#MessageContent').val());
window.plugins.sms.send($('#friendName').val(),
$('#MessageContent').val(),
function () {
alert('Message sent successfully');
},
function (e) {
alert('Message Failed:' + e);
}
);
});
}
document.addEventListener("deviceready", onDeviceReady, false);
I got the java code from here & added the permission:
<uses-permission android:name="android.permission.SEND_SMS"/>
And added the plugin to Plugins.xml.
Do you know what's the problem ?
Depending on what version of PhoneGap you are using you may just have to go into the smsplugin.js and replace the instances of "PhoneGap" with "cordova".
Related
I am developing Angularjs app in vs2015.
I want to open database in websql through factory function. While testing app in ripple emulator it works perfectly(also works perfectly in android OS version 4.4 and higher) but while testing app in android OS version 4.2 and lower it throws security_err dom exception 18.
One more strange is that when same database, I open in simple java script file it works perfectly in ripple and in all devices also.
Here is my factory code :
angular.module('InnkeyAlert.services', ['InnkeyAlert.config'])
// DB wrapper
.factory('DB', function ($q, DB_CONFIG) {
try {
var self = this;
self.db = null;
self.init = function () {
alert("DB init start!");
// Use self.db = window.sqlitePlugin.openDatabase({name: DB_CONFIG.name}); in production
self.db = window.openDatabase(DB_CONFIG.name, '1.0', 'database', -1);
alert("DB open!");
angular.forEach(DB_CONFIG.tables, function (table) {
var columns = [];
angular.forEach(table.columns, function (column) {
columns.push(column.name + ' ' + column.type);
});
var query = 'CREATE TABLE IF NOT EXISTS ' + table.name + ' (' + columns.join(',') + ')';
self.query(query);
//console.log('Table ' + table.name + ' initialized');
});
alert("table created !");
};
return self;
} catch (e) {
//alert("Db factory: "+e.message);
}
})
Here is my index.js file code :
var app = {
// Application Constructor
initialize: function () {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function () {
alert("hi");
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function () {
app.receivedEvent('deviceready');
alert("Device ready end...");
try {
angular.injector(['InnkeyAlert']).get('DB').init();
alert("inti db called...");
} catch (e) {
alert("index 101: " + e.message);
}
},
// Update DOM on a Received Event
receivedEvent: function (id) {
}
};
That's a problem in Android versions lower than 4.4. It has been answered here:
You can use Web SQL from a file:// URL in WebView. The Cordova folks managed to do it. There are just three things you must do:
1) Call setDatabaseEnabled() (duh):
2) Set the database file path. Yes, this is deprecated in Android 4.4, but it is required if you want to avoid the DOM Exception 18 in pre-Kitkat:
3) Set the onExceededDatabaseQuota handler. Yes, it's deprecated in Android 4.4, blah blah blah.
I am building a hybrid mobile app based out of JavaScript, CSS and HTML. I am using the Intel XDK to develop and deploy the app.
For Facebook integration I am using the following third party plugin to work it out.
My aim is to get it to work both on iOS and Android. I have done the followings:
<button onclick="fblogin()"> Login </button>
Script:
<script>
function fblogin() {
var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
}
facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure);
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
}
</script>
The issues:
I have already enabled the plugin with my javascript api on the intel xdk.
fblogin() not defined at the following line:
facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure);
I have read through the guide but is still confused. I would appreciate if someone could give me a step by step guide on making this work.
I would suggest to look at the sample code on the README (https://github.com/Wizcorp/phonegap-facebook-plugin#sample-code)
You can write your function like this:
function fblogin() {
var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
}
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
}
i.e remove the
facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure)
line.
I'm trying to create an app that allows the user to record audio. I'm using the cordova-plugin-media for this.
Using the sample from the documentation I can record sound on iOS (specifying a *.wav file), Android (*.amr), Windows Phone 8 (*.aac), but Windows Phone 8.1 doesn't work. I've tried it with *.mp3, *.wma, and *.m4a, but in every case I get this error:
No suitable transform was found to encode or decode the content.
Here's part of the code:
var that = this;
try {
this._media = new Media('recording.mp3', function () {
that._log('Audio success');
}, function (e) {
that._log('Error: ' + e.code + ': ' + e.message);
});
// Bind buttons
document.querySelector('#recordStart').addEventListener('click', function () {
// Record
that._log('Recording...');
that._media.startRecord();
});
document.querySelector('#recordStop').addEventListener('click', function () {
that._log('Recording stopped');
that._media.stopRecord();
});
}
catch (e) {
this._log('An error occurred!');
this._log(e.message);
}
I am following the howto in this blog post: http://www.pubnub.com/blog/sending-android-push-notifications-via-gcm-javascript-using-phonegap/
Up til now I have done the following:
Created a new project in Google Dev Console
Turned on Google Cloud Messaging for Android
Got the sender ID (project number) and a server
key
Then added push plugin to existing project:
$ cordova plugin add https://github.com/phonegap-build/PushPlugin.git
Then copied PushNotification.js from the plugin to my js lib folder.
I am loading both this js file and the pubnub cdn with requirejs, which seems to work fine.
I created a module with the scripts from 2.2 in the howto.
define(['env-config','datastore/localstore','jquery','push','pubnub'],function (EnvConfig,Store) {
var pushNotification = window.plugins.pushNotification;
function register() {
pushNotification.register(
successHandler,
errorHandler,
{ 'senderID':EnvConfig.push.senderid, 'ecb':'onNotificationGCM'}
);
}
function successHandler(result) {
console.log('Success: '+ result);
}
function errorHandler(error) {
//** The following line throws:
//** java.lang.Long cannot be cast to java.lang.String
console.log('Error:' + error);
}
function onNotificationGCM(e) {
switch(e.event){
case 'registered':
console.log("Device registered with id "+e.regid);
Store.set("pushid"+e.regid);
/*if (e.regid.length > 0) {
deviceRegistered(e.regid);
} */
break;
case 'message':
if (e.foreground){
//What needs to be done when app is in the foreground
//while receiving a notification
console.log('A notification has been received');
}
break;
case 'error':
console.log('Error: ' + e.msg);
break;
default: console.log('An unknown event was received');
break;
}
}
var module = {
init: function() {
register();
}
};
return module;
});
When device is ready, I call the init function of this module.
At the moment register() fails and executes the errorHandler callback. But console.log fails with: java.lang.Long cannot be cast to java.lang.String. Therefore I have no idea what to do next...
Any pointers is much appreciated.
Samsung Galaxy S5
Android 4.4.2
Chrome 30.0 (in webview)
Cordova 3.6.3-0.2.13
Ah, I think I know what's going on-
Your sender ID has to be in string! You are probably using it as a number.
BTW, thanks for trying out the tutorial I wrote :-)
I am using custome.js,PIE.js and jquery1_7_2.js file in my jsp
This is my custome.js and nothing more.
jQuery(document).ready(function(){
jQuery(function() {
if (window.PIE) {
jQuery('#login-box, .sign-button, .new-user-btn, .grey-btn, .code-btn, #contact-email, #contact-email .continue, #contact-email .cancel').each(function() {
PIE.attach(this);
});
}
});
})
everything working fine in all browser. But in Firefox it is showing me this error
Error: TypeError: PIE.attach is not a function
Source File: http://localhost:8080/MyApp/js/custom.js
Line: 6
Please guide me to solve this issue.
Edited:
It showing me error in this line of PIE.js
window.attachEvent("onunload",a);f.K.sa=function(b,c,d){b.attachEvent(c,d);this.ba(function(){b.detachEvent(c,d)})}})();f.Qa=new
f.ea;f.K.sa(window,"onresize",function(){f.Qa.wa()});(function(){function
a(){f.mb.wa()}f.mb=new
f.ea;f.K.sa(window,"onscroll",a);f.Qa.ba(a)})();(function(){function
a(){c=f.kb.md()}function b(){if(c){for(var
d=0,e=c.length;d
and custome.js in this line
PIE.attach(this);
When attaching events in order to make it cross browser perform the following:
if (target.addEventListener) {
target.addEventListener(eventName, handlerName, false);
} else if (target.attachEvent) {
target.attachEvent("on" + eventName, handlerName);
} else {
target["on" + eventName] = handlerName;
}