Cordova social sharing plugin didnt work in android - android

I have installed this Cordova social sharing plugin via command line tool.
Everything is added correctly to my current project foleder,but the share option is didn't work
Here is my code
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.plugins.socialsharing.share('Message and link', null, null, 'http://www.x-services.nl');
}
I will get this error in my console
"TypeError: Cannot read property 'share' of undefined
My Cordova version is 5.1.1
EDIT
I've crated a blank Cordova project and added the plugin its works fine for me
there is no need of manual configuration.
But my project developed using Angularjs and Onsenui,may this was the problem?.

Did you include socialsharing.js in your project and load it like this?
<script type="text/javascript" src="js/socialsharing.js"></script>
Make sure the S are not upper case in the file name too...

you are getting error in console in google chrome console ?? in any browser not supported cordova plugin so you have to test in device and you have to also include file in hader
<script charset="utf-8" src="cordova.js" type="text/javascript">
</script>
<script type="text/javascript" src="js/SocialSharing.js">
</script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
onclick="window.plugins.socialsharing.share('Message only')"
}
and if you have any further confusion then message me

Related

Cordova Insomnia plugin not working

I'm developing an app using Cordova, and the Insomnia plugin is perfect for what I need.
But I can't make it work. To make everything as simple as possible, I created a new Cordova project, installed the plugin automatically (using the CLI) and add the following lines in the original Cordova index.html file to call the KeepAwake command:
<script type="text/javascript" src="js/Insomnia.js"></script>
<script>
window.plugins.insomnia.keepAwake()
</script>
But it's not working. The phone still auto-lock after 30s. I'm using an iPhone 5s running iOS 10.3.3 and Cordova iOS version 4.4.0.
What's wrong???
Thank you very much!
Code from comment below:
<script>
function onLoad() { document.addEventListener("deviceready", onDeviceReady, false); }
// Cordova is loaded and it is now safe to make calls Cordova methods //
function onDeviceReady() { window.plugins.insomnia.keepAwake() }
</script>
Did you referred the documentation? Here
You have to Copy Insomnia.h and Insomnia.m to platforms/ios/{ProjectName}/Plugins folder.

console.log not working when running an Android app in Cordova

I have a basic Cordova application with a simple console.log() function at the end.
My index.html file looks as follows:
<!DOCTYPE html>
<html>
<head>
...
</head>
<body>
...
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("Device is ready!");
}
</script>
</body>
</html>
As you can see it's basically the same as the automatically generated file with some console.log script at the bottom.
Unfortunately when I run the app on Android using cordova emulate android, I cannot seem to find the output from console.log(..) anywhere. However, it works fine on browsers.
console.log(..)only works on browser console, not on command line.
To get log that appears on your app use alert(...);.
Anyway if you wanted to see your logs by consol.log() you should use an IDE like Android Studio or use ddms located where your adb is installed. (run ddms.bat)
Use
cordova plugin add cordova-plugin-console
This plugin will enable console logging.
It has various methods for console printing
console.log
console.error
console.exception
console.warn
console.info
console.debug
console.assert
console.dir
console.dirxml
console.time
console.timeEnd
console.table
By default plugin is not installed so you will have to add it manually.
Reference.
Regards.

Cordova deviceReady not called on Android platform

I am trying to build a simple cordova app on iOS and Android. It worked fine on iOS. However it fails to execute on android. I am using Android Studio.
The html file still runs in android, but the addEventListener for deviceReady is not working.
This piece of code works fine in iOS but not in android:
<p id="ready" style="text-align: center">deviceready not called yet</p>
<script type="text/javascript" src="cordova-2.4.0.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", function() {
console.log("cordova ready");
var readyElement = document.getElementById("ready");
readyElement.innerHTML = "deviceready called but not finished";
readyElement.innerHTML = "Ready";
console.log('Ready');
}, false);
</script>
I have included the both cordova-2.4.0.js and cordova.js in the project folder, but I have no idea why it doesnt connect properly.
After the page loads, the label 'device ready not called yet should be changed to device ready' , but it doesnt change in android. Can anyone suggest me the right way to do it ?
Note: 'cordova.js' is generated by the cordova in android , and 'cordova-2.4.0.js' is the one generated in iOS.
Even though I copied the iOS cordova-2.4.0.js file, it didnt worked.
Looks like I have to include only one cordova.js file generated by the cordova .
I removed the line:
<script type="text/javascript" src="cordova-2.4.0.js"></script>
and I used only:
<script type="text/javascript" src="cordova.js"></script>
and it worked.

Android PhoneGap HTML5video

I am looking for an HTML 5 video plugin for PhoneGap.
I found a plugin at GitHub but there maybe something wrong as I have the following issues:
I don't know where to place the plugin.xml
I don't know how to to link with it <video> tag
and it's not working with PhoneGap
this javascript function now
function start(){
window.plugins.html5video.initialize({"video1" : "movie.mp4"});
window.plugins.html5video.play("video1");
}
04-24 09:52:59.305: E/Web Console(740): Uncaught TypeError: Cannot call method 'initialize' of undefined at file:///android_asset/www/index.html:44
After several attempts I solved this way:
I have installed Git
I have installed the plugin HTML5Video for Cordoba with command cordova plugin add https://github.com/jaeger25/Html5Video.git (with this command, the project has run automatically configured to use the plugin)
I created the folder platforms\androis\res\raw\ where I copied the video splash.mp4
In the html file (in my case \www\splash.html) I insert this code in HEAD:
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="Html5Video.js"></script>
<script>
// Wait for device API libraries to load
//
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
window.plugins.html5Video.initialize({
"splashvideo" : "splash.mp4"
})
window.plugins.html5Video.play("splashvideo");
}
</script>
and this is the BODY code
<body onload="onLoad()">
<video id="splashvideo" autobuffer controls="false"></video>
</body>
It's work for me ;)

Android phonegap SpeechRecognizer issue : Cannot read property 'speechrecognizer'

I am new to cordova-android app development.I am using cordova 3.3.0 to create Android phonegap SpeechRecognizer application. I referred SpeechRecognizer. According to that i have executed below commands to create cordova android platform app.
1) cordova create SpeechrecognizerApp
2) cordova platform add android
3) phonegap local plugin add https://github.com/mayurloved/speechrecognizer.git
Afer that i imported that project in eclipse and it automatically created all required packeges and made all changes in config.xml. Then i copied all html contents of example page to my index.html file. All is done properly, but when i run my app, log shows error:
Uncaught TypeError: Cannot read property 'speechrecognizer' of undefined:20
index.html
<!DOCTYPE html>
<html>
<head>
<title>Speech Recognition plugin demo</title>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="SpeechRecognizer.js"></script>
</head>
<body>
<script type="text/javascript">
function onDeviceReady(){
console.log("Device is ready");
}
function recognizeSpeech() {
var maxMatches = 5;
var promptString = "Speak now"; // optional
var language = "en-US"; // optional
window.plugins.speechrecognizer.startRecognize(function(result){
alert(result);
}, function(errorMessage){
console.log("Error message: " + errorMessage);
}, maxMatches, promptString, language);
}
// Show the list of the supported languages
function getSupportedLanguages() {
window.plugins.speechrecognizer.getSupportedLanguages(function(languages){
// display the json array
alert(languages);
}, function(error){
alert("Could not retrieve the supported languages : " + error);
});
}
document.addEventListener("deviceready", onDeviceReady, true);
</script>
<button onclick="recognizeSpeech();">Start recognition</button>
<button onclick="getSupportedLanguages();">Get Supported Languages</button>
</body>
</html>
I haven't copied SpeechRecognizer.js in www folder as according to above link i don't require to copy it in my app because i am using cordova version >3.0. Please help me to solve this problem.
Thank you.
Did you launch phonegap build android after you add the plugin? When you install plugins, they are installed only in the /plugins folder of the project but not in the platform folder.
You have to run phonegap build or phonegap prepare for any platform to have the plugin fully installed.
And then after you can refresh the project in eclipse and you should see the java part of the plugin in the /src folder and the javascript in /assets/www/plugins
If the folder platforms\android\assets\www\plugins... is not there after the build, that may be because your project got corrupted.
In that case you can try to empty the plugins folder at the root of your project and re-install all plugins.
If that's not enough, you can retry emptying both platforms and plugins folder (think to save any customisation you may have done in platforms folders).

Categories

Resources