Phonegap Plugin Error during initialization - android

Hey guys i'm workin on an app, which check whether a user has logged in the app before or not. I use phonegap in combination with jquery-mobile. But if i test my app with ripple with the following code:
var SaveUserStatus = function() {
}
SaveUserStatus.prototype.check = function(succes,fail) {
return PhoneGap.exec(function(args) {
success(args);
}, function(args) {
fail(args);
}, 'SaveUserStatus', 'getUserStatus', '');
}
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin('saveUserStatus', new SaveUserStatus());
PluginManager.addService("SaveUserStatus","net.testing.plugins.SaveUserStatus");
});
I get always following error messages:
"Uncaught TypeError: Object [object Object] has no method 'hasResource' - phonegap-1.0.0.js:936" and "Uncaught TypeError: Object [object Object] has no method 'addConstructor' - plugin.js:17
"
Has anyone the same error or see the error, this would be nice because i going crazy with that!

Comment out
<script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
in your HTML-File.
For further informations read the comment by Dan Silivestru http://ripple.tinyhippos.com/forums/6/topics/50

Related

Ionic + Cordova + Facebook login: 51 F02 FacebookConnectPlugin sClass not found

I am trying to add facebook login to my application. I followed the same process as mentioned in this blog of ionic "https://ionicthemes.com/tutorials/about/native-facebook-login-with-ionic-framework"
But somehow its not working.
Its failing at $cordovaFacebook.login. Its not going inside.
$scope.fbLogin = function(){
$cordovaFacebook.login(["public_profile", "email", "user_friends"]) //Failing in this step
.then(function(success) {
$cordovaFacebook.api("me?fields=id,name,picture", [])
.then(function(result){
var userData = {
id: result.id,
name: result.name,
pic: result.picture.data.url
}
//Do what you wish to do with user data. Here we are just displaying it in the view
$scope.fbData = JSON.stringify(userData, null, 4);
}, function(error){
// Error message
console.log(error);
})
}, function (error) {
console.log(error); // error comes as "Class not found"
});
}
What i am missing here. After debugging i found it says
51 F02 FacebookConnectPlugin sClass not found
See attached image. What is wrong here.
Damm...Issue is with cordova 5.4.1. I degraded to version 5.3.3 and it started working.

How can I get device Locale or Language with PhoneGap Build?

I'm using Phonegap Build to develop an application for iOS and Android.
I'd like to determine the locale (e.g. 'en-US') for the device, though I'd settle for the current language setting, or even the app store my app was installed from (it's been a long day).
Following the instructions here for the Globalization plugin I think I have everything right, but nothing seems to work on either the iPhone 6 or Samsung Galaxy Nexus I'm using for testing.
The relevant part of my config.xml looks like this:
<gap:plugin name="org.apache.cordova.globalization" />
My function for getting locale from the plugin looks like this:
var getPhoneGapLocaleName = function() {
var loc = 'unknown';
if (navigator.globalization !== undefined) {
navigator.globalization.getLocaleName(
function (locale) {
if (locale !== undefined) {
loc = locale.value;
}
},
function () {
// nothing
}
);
}
return loc;
};
Note: on both devices navigator.globalization.getLocaleName is present and appears correct, evaluating to a function resembling what I'd expect based on the documentation.
The problem here was that the variable 'loc' was declared outside the scope of the success or failure callbacks, which of course happen after a few brief moments.
I fixed this by changing the function thus:
var refreshPhoneGapLocaleName = function() {
if (navigator.globalization !== undefined) {
navigator.globalization.getLocaleName(
function (locale) {
if (locale !== undefined) {
localStorage['pg.locale'] = locale.value;
}
},
function () {
// nothing
}
);
}
};
Now calling it in onDeviceReady in order to refresh the values when the app starts.
A few moments later (not immediately) the following function can be used to retrieve the locale value:
var getLocale = function() {
return localStorage['pg.locale']();
};
The greatest thing about StackOverflow is how often it helps one to resolve one's own silly mistakes. :)
Although previous answers are returning the desired result, and giving an option to retrieve the current phonegap locale name, they did not explain the topic starter why his function did not work, and how to adjust his function to work in the way he intended (i.e. not using localStorage and not showing the locale in the console but giving the answer in real-time as a result)
I am posting this answer since I was looking for a quick function to get the device locale, and this post was my first result. While the opening post gave me everything I needed, I would like to answer this question for future visitors with the same purpose I had. Sorry for posting to a topic this old, but I hope I can help others with my answer.
The reason the function of topic starter does not work is the following: the plugin returns the locale in an asynchronous way. Therefore, the loc =locale.value line is only executed after the function's return statement. To fix this, we can write a wrapper function to simplify the plugins output as follows. Keep in mind that we need to use this function asynchronously, since the plugin result is also asynchronous.
The function:
var getPhoneGapLocaleName = function ( callback ) {
var unknownLocation = 'unknown'; //Default value
if ( navigator.globalization !== undefined ) {
navigator.globalization.getLocaleName(
function ( locale ) {
if ( locale !== undefined ) {
callback( locale.value );
} else {
callback( unknownLocation );
}
},
function () {
callback( unknownLocation );
}
);
} else {
callback( unknownLocation );
}
};
Use the function like this:
getPhoneGapLocaleName( function( loc ){ console.log( 'The locale was set as follows: ' + loc ); } );
Try this code
When the browser is set to the en_US locale, this should display a popup dialog with the text language: English:
navigator.globalization.getPreferredLanguage(
function (language) {alert('language: ' + language.value + '\n');},
function () {alert('Error getting language\n');}
);
Full Example
<!DOCTYPE HTML>
<html>
<head>
<title>getPreferredLanguage Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
function checkLanguage() {
navigator.globalization.getPreferredLanguage(
function (language) {alert('language: ' + language.value + '\n');},
function () {alert('Error getting language\n');}
);
}
</script>
</head>
<body>
<button onclick="checkLanguage()">Click for language</button>
</body>
</html>

Android Browser Issue with jQuery Ajax and when appcache is used

we are having a problem with the built in browser on Android 4.0, 4.1 and 4.2 (we haven't got anything lower to test on).
The problem is that the ajax call will work perfectly on first load, you can press the run Ajax button as many times as you like and it will be fine. You can disconnect from the internet and it will work properly.
But if you exit (FULLY, make sure its not just running in the background) the browser then relaunch it, it will fail on load and on button press. It doesn't matter if you are on-line or off-line.
The error that is been returned from the ajax call is "Error" with status = 0 and readyState = 0.
When its successful you get a message back says "respose from Ajax Call" with a status = 200 and a readyState = 4.
The code works find on every other browser we have tested on Android Chrome, Firefox and Opera. on IOS 5 and 6 it works and every desktop browser we can find.
Is there something that I missing or have we found a bug in the built in browser. Any help on this would be appreciate especially if it just something stupid I have done.
We have created a test script that demonstrates this problem well I have attached it to the bottom of this message.
Thanks
Tim
test.php
<?php
function displayPage() {
?>
<!DOCTYPE html>
<html manifest="test.manifest" debug="true">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" >
<title>test</title>
<script type="text/javascript" src="jquery-1.9.0.min.js"></script>
<script type="text/javascript">
function runAjaxGet() {
var XMLHttpRequest = $.ajax({
url: "test.php",
dataType: "json",
data: "test=test",
traditional: "true",
success: function( responseData ) {
alert('good\n responseData: '+responseData+ '\n res:' + XMLHttpRequest.responseText +'\n readyState: '+ XMLHttpRequest.readyState + '\n Status: '+XMLHttpRequest.status );
console.log(XMLHttpRequest);
},
error: function (xhr, ajaxOptions, thrownError, responseData) {
alert('bad\n responseData: '+responseData+ '\n res:' + XMLHttpRequest.responseText +'\n readyState: '+ XMLHttpRequest.readyState + '\n Status: '+XMLHttpRequest.status);
console.log(XMLHttpRequest);
}
});
}
$(document).ready(function() {
runAjaxGet();
});
</script>
</head>
<body>
<button Name="Run Ajax" onclick="runAjaxGet();">Run Ajax</button>
</body>
</html>
<?php
}
function processRequests() {
header("Content-Type: application/json; charset=UTF-8" );
echo (json_encode("respose from Ajax Call"));
}
date_default_timezone_set ( "UTC" );
if (isset($_REQUEST['test'])) {
$which = $_REQUEST['test'];
} else {
$which = '';
}
switch ($which) {
case "test":
processRequests();
break;
default :
displayPage();
break;
}
?>
test.manifest
CACHE MANIFEST
test.php
jquery-1.9.0.min.js
test.php?test=test
Just add NETWORK section with asterisk and it will work
CACHE MANIFEST
test.php
jquery-1.9.0.min.js
test.php?test=test
NETWORK:
*
I hit this same problem and determined that when retrieved from the cache, 0 indicates success. This is likely because there is no actual http request involved since the request is resolved entirely locally.
Appcache manifest file:
CACHE MANIFEST
CACHE:
/config
Javascript:
var request = new XMLHttpRequest();
request.open('GET', '/config', false); // async=false is ok because this file will always come from AppCache
request.send(null);
// Older versions of android return 0 when ajax request retrieved from appcache
if (request.status == 200 || request.status == 0) {
return JSON.parse(request.responseText);
} else {
console.log("ERROR: config not retrievable");
throw "Attempt to retrieve config return http status " + request.status;
}

android/phonegap Uncaught TypeError: Cannot read property 'downloader' of undefined at file

$(document).ready(function() {
window.plugins.downloader.downloadFile("http://some_path/images/image1.jpg", {overwrite: true},
function(res) {
alert(JSON.stringify(result));
}, function(error) {
alert(error);
}
); });
Error:-
Uncaught TypeError: Cannot read property 'downloader' of undefined at file:///android_asset/www/index.html:11
i have included the correct js files and in proper order still i am getting this error...
I even tried replacing all calls to PhoneGap by cordova... still it gives the same error eg
cordova.addConstructor(function() {
cordova.addPlugin("Downloader", new Downloader());
//window.plugins.Downloader = new Downloader();
//PluginManager.addService("Downloader", "com.phonegap.plugins.downloader.Downloader");
});
If you closely observe the LogCat log, you will notice that there is an error in "downloader.js" file. It is made for older version of phonegap. I was searching a lot how to fix the same problem as yours but I only found your question posted here. So, the bottom line is that we'll have to fix the syntax in the script file. Those morons changed whole syntax without care of backward compatibility :(
In order to make the code working, replace the downloader.js code with this:
/* downloader.js */
function Downloader() {}
Downloader.prototype.downloadFile = function(fileUrl, params, win, fail) {
//Make params hash optional.
if (!fail) win = params;
cordova.exec(win, fail, "Downloader", "downloadFile", [fileUrl, params]);
};
if(!window.plugins) {
window.plugins = {};
}
if (!window.plugins.Downloader) {
window.plugins.Downloader = new Downloader();
}
And next, the call should be:
window.plugins.Downloader.downloadFile(url, {dirName: contentDirectory, fileName: someFileName, overwrite: true},
function(data){
if(data=="exist"){
/// alert("File already exist");
console.log("File allready exist!");
}
else{
console.log("Status: " + data.status);
}
},
function(data){
console.log("error: "+data);
}
);
I know this is an old question, but it is actual since the phonegap implementation of download doesn't work well...
#Marjan: I tried to work with the phonegap implementation on PhoneGap 2.8.1. The best result I got was a working download, but all downloaded files had only 6 kilobyte and there was no error at all.
So... If anybody has an idea on the downloader plugin to get it to work (as described above), please let us know.

Error VideoCapture in Phonegap Android App

I am trying to capture video in android app using phonegap, but facing problem
TypeError: Result of expression 'navigator.device.capture.captureVideo' [undefined] is not a function.
Here bellow is my code
I included following in head
<script type="text/javascript" src="js/phonegap-1.2.0.js"></script>
<script src="js/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
function recordVideo(){
var capture = navigator.device.capture;
var options1 = { limit: 1 };
navigator.device.capture.captureVideo(captureSuccess, captureError, options1);
alert("Record");
}
function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
alert(mediaFiles[i].name);
}
}
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
alert(msg);
}
</script>
And code for capturing on a button click Capture Video
But I getting this error on console
TypeError: Result of expression 'navigator.device.capture.captureVideo' [undefined] is not a function.
Please help me.
Thanks in advance.
Timir
You should add the required plugin (https://github.com/apache/cordova-plugin-media-capture/blob/master/doc/index.md)
If you are using intel xdk go to project -> plugins and permissions

Categories

Resources