Cordova deviceReady not called on Android platform - android

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.

Related

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 social sharing plugin didnt work in 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

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 ;)

Close android hybrid app that was builded by IntelXDK android build

I'm creating java script hybrid app with IntelXDK android build for android platform.
I'm unable to exit from my app using following code:
<html>
<head>
<title></title>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript"">
function onLoad()
{
document.addEventListener("deviceready", onDeviceReady, true);
}
function exitFromApp()
{
navigator.app.exitApp();
}
</script>
</head>
<body onload="onLoad();">
<button name="buttonClick" onclick="exitFromApp()">Click Me!</button>
</body>
</html>
The same code works well with IntelXDK crosswalk build.
How to close an app using android build?
I checked and it does not work in the android build. There will be an update late March that updates the android build to a newer cordova. I verified that it works here. Maybe you can continue to use crosswalk build until then?

JQTouch error with phonegap

I'm trying to get jqtouch zepto to work with phonegap. I'm using android to test. I have the project set up and both js frameworks loading but I get this error when setting up jqtouch
TypeError: Result of expression 'a' [undefined] is not an object. at file:///android_asset/www/jqtouch.min.js:7
And this is the error for the non min js jqtouch.
TypeError: Result of expression 'hash' [undefined] is not an object. at file:///android_asset/www/jqtouch.js:420
Here is what my header and initialization of jqtouch looks like
<script src="zepto.min.js" type="text/javascript" charset="utf-8"></script>
<script src="jqtouch.js" type="text/javascript" charset="utf-8"></script>
<script src="phonegap.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
$.jQTouch({
icon: 'jqtouch.png',
statusBar: 'black-translucent',
preloadImages: []
});
</script>
As I understand your question this is before you even have compiled your project. If you have just imported jqtouch.min.js and jqtouch.js and Eclipse is saying there is an error in them you can set Eclipse to ignore the file for errors.
Go to : Project->Properties->JavaScript->Include Path->Source-> Excluded Groups
ignore specific files by adding **/jqtouch*.js
This will make Eclipse ignore the supposed errors in jqtouch.js and jqtouch.min.js and make you able to compile your project.

Categories

Resources