Phonegap Android Filetransfer Error Code 3 - android

I am working on mobile application for Android, which uses Dave Johnson's Facebook Connect Plugin (https://github.com/davejohnson/phoneg...), Camera and FileTransfer. Basically the user clicks on a button to Take a Photo ( The Phone Camera Starts, the user takes a photo ), then this photo is uploaded to a server. The problem is that first time everything is fine, but when I hit the button again to shoot a second photo, the photo can't be uploaded to a server and the returned error is from FileTransfer - Error Code 3.
I have set options.chunkedMode = false; This doesn't help.
I know that this is a connection error, I whitelisted the domain that I'm uploading the picture to in the /res/xml/cordova.xml file. I searched the web a lot to find a working solution there are other people complaining about this, but there is no working solution provided. I'm using Cordova 1.8.1 ( I also tested with 1.8.0, 1.7.0, 1.6.1, 1.5.0 ). I tested with newer versions of Phonegap for example 1.9.0 but can't build the project - the facebook plugin doesn't work with this version of Phonegap. I am testing using Emulator Android 4.1 (API 16). I tried different things to make it work while I was looking at the logs in details, but I couldn't make it work. I'm trying to find a solution, because it is very important, please help me solve this issue. Thank you in advance for you answers.

You can try either of these:
Set android:debuggable="true" in the tag of your AndroidManifest.xml file.
Set instead of just the * as it's recommended in the comments section as follows:
<!-- <access origin="https://example.com" /> allow any secure requests to example.com -->
<!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
<!-- <access origin=".*"/> Allow all domains, suggested development use only -->
From; https://stackoverflow.com/a/12011782/610880

This is an unfixed bug in the phonegap library, since there were no bug fixes, i had to get it work by my work around (Basically reupload on every alternate failure):
ft.upload(path,
encodeURI("http://yourdomain.com/upload.php"),
function(result) {
alert("Uploaded");
},
function(error) {
ft.upload(path,
encodeURI("http://yourdomain.com/upload.php"),
function(result) {
alert("Uploaded");
},
function(error) {
alert("Error uploading image");
},
{ fileName: name, fileKey: "file", mimeType: "image/jpeg", chunkedMode: false }, true);
},
{ fileName: name, fileKey: "file", mimeType: "image/jpeg", chunkedMode: false }, true);

Related

how to call external web services in phonegap application

I am new to phonegap. I want to call server side web service from phonegap application to get data. I have tried it on browser it working fine and also on Phonegap developer app for Android. Both are working fine. But if i make .APK from PhonegapBuild console and installed on android device, it doesn't work anymore.
I have used AJAX to call web service. I also tried other solutions related this but all are fail.
Solution 1:
Changed in config.xml
< access origin="*"/> with
< access origin="http://mywebserviceipaddress"/>
Solution 2: Changed AJAX call with .get() method. For this added image where i have added two methods for code.
Solution 3: Added
$.ajax({
...
crossDomain: true,
async: false,
cache : false,
...
});
in AJAX call
Here is my both code. Please tell me if missing any parameters.
enter image description here

Phonegap can't load remote content

I've built an application in PhoneGap. I hand-code the application and upload it to phonegap build.
I am currently testing it only on Android.
My app uses Jquery Ajax to load some content from my server. This has worked PERFECTLY for the last 10 days. Today, it just stopped.
My application cannot load any content from any server anymore. This includes my Stylesheet (yes I prefer to host that on a server) and Google-hosted jquery. I resolved these files problems by just adding jquery.min.js and a client-side style.css file but the $.ajax calls, which I relied on so heavily cannot become client-side.
My config.xml file has always had
<access origin="*" />
The file in question has this code in it:
<body onLoad="loaded();"> .........
function loaded(){
alert("function called.");
$.support.cors=true;
}
The code which is now failing looks like this:
var request = $.ajax({
url: "http://myserver/somefile.php",
method: "POST",
data: { variable:value},
dataType: "html"
});
request.done(function( msg ) { alert(msg); }
Would anyone else care to take a swing?
Have you installed the cordova-whitelist-plugin and added a Content Security Policy meta tag in your app? If not, that may be the issue. This plugin is required for Cordova 4.0 or above (Android & iOS) to access any non file:// URLs. https://github.com/apache/cordova-plugin-whitelist#content-security-policy

Chrome for Android - add web app to home screen

I'm trying to implement an 'add to homescreen' banner using Google Chrome's native banner support, with this demo as reference.
https://googlechrome.github.io/samples/app-install-banner/basic-banner/index.html
According to the spec there, the requirements are:
the page uses a service worker (yep, see below)
the site is using HTTPS (yep, the site has a valid SSL certificate and I am loading over HTTPS. chrome shows the site as secure and has a green padlock, no errors or warnings in the certificate)
the app has a manifest declared (yep, see below)
the manifest has a short_name, 144 pixel icon and a type of 'image/png' (yep, see below)
The manifest I am using is below.
{
"name": "Web app test",
"short_name": "Test",
"icons": [
{
"src": "/resources/launcher-icon-3x.png",
"sizes": "144x144",
"type": "image/png"
}
],
"display": "standalone"
}
Which contains a short_name and a 144 pixel icon of type image/png.
The service worker I am using is a direct copy & paste of this code:
https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/custom-offline-page/service-worker.js
which was recommended in this article:
https://developers.google.com/web/updates/2015/03/increasing-engagement-with-app-install-banners-in-chrome-for-android?hl=en
The service worker has been registered, the manifest is being loaded into the page and the image url is correct, but the banner is not showing.
I also have the chrome://flags/#bypass-app-banner-engagement-checks enabled so this isn't a case of me needing to come back tomorrow and check that it works. I have been able to view homescreen banners on all of Chrome's demos that I have checked (which is where I took most of this code from) and my phone has the latest version of Chrome installed.
Is there anything else I am missing that could be blocking the homescreen banner from appearing?
Thanks.
A couple of things to check:
Ensure you have a start_url in your manifest that defines the page to launch.
Ensure that you have a <link rel=manifest> in your page
Ensure the image URL's all resolve correctly based on the manifest location
Preferably have a 192px icon, 144 is the minimum
Mounir Lamouri has created a manifest validator that you can use to check your manifest is correct.
You should also enable chrome://flags/#bypass-app-banner-engagement-checks if you are using Chrome so that you get a quicker warning or visibility of any issues. Finally you can look in the Dev Tools console on any page load and an error will be shown indicating why the banner wasn't shown.
There is also a lot of guidance on developers.google.com
Using App Install Banners
Create a manifest file including a short_name, icons and launch_url
Link to the manifest file from the page
Web App Install Banner
Optionally include extra information such as the background_color and theme_color.
Listening to events on App Install banner
Learn when Chrome thinks it can prompt for install and then offer the ability to defer it until a more appropriate time.
Understand if the user has accepted or rejected the prompt by looking at the response in the onbeforeinstallprompt event.
In general I'd recommend pasting your manifest into this to ensure it doesn't have any errors: http://mounirlamouri.github.io/manifest-validator/
If using Chrome with chrome://flags/#bypass-app-banner-engagement-checks enabled, you can look in the console on any page load and an error will be shown indicating why the banner wasn't shown.

PhoneGap Android Device Ready but no Ajax

I wonder if my problem is my ajax call is to http, not https. Must I call with https or can I call with http?
I am compiling with PhoneGap cloud cli-5.2.0 ( iOS 3.9.1 / Android 4.1.1 / Windows 3.8.1)
I compile my package, install it on my Android Samsung, it starts up, and my $.ajax errors
errorThrown:undefined
textStatus:error
data:{"readyState":4,"responseText":"","status":404,"statusText":"Not Found"}
Any suggestions/ideas?
I read the following:
jQuery Mobile + Phonegap on Android - no Ajax but its two years old and relates to an older version of phonegap.
My code requires no special magic - I do include phonegap.js but I do not use gps, camera, contacts etc etc
Using the code below, I do get my "deviceready" and "document ready" displayed. When I click on my login button (id='demologin') the function DemoLogin() is executed.
function onDeviceReady() {
$("#demologin").on("click", DemoLogin );
$("#demologin").after("<h3>deviceready</h3>");
return true;
}
$(document).ready(
function()
{
document.addEventListener("deviceready", onDeviceReady, false);
$("#demologin").after("<h3>document ready</h3>");
});
If I were to guess, the ajax "404" leads me to believe its calling a URL that does not exist hence why I wonder if Android expects me to call https instead of http. The problem I have with this is the code works on iOS so I would have thought PhoneGap magic would lead me to believe if it runs on one, it would run on the other.
All help appreciated!
I also use ajax on phonegap app and it work good. You can make call to http. I think the url you called does not exist or there may be connection problems like when data is switched off.
This is a old question but, possibly the solution will help someone who is googling it.
Add this code to your config.xml file:
<gap:plugin name="cordova-plugin-whitelist" source="npm" />
<access origin="*" />
because new release of Cordova need whitelist plugin.

Trying to use openFB with Cordova

So i´m having a situation that someone might be able to help.
Im creating a Mobile APP using PhoneGap Build. I´m trying to use this http://coenraets.org/blog/2014/04/facebook-phonegap-cordova-without-plugin/
Right know if I open the app inBrowser it will work. Ask's for permissions etc and fetch the user data correctly. Of course I defined a Valid oAuth: localhost/...html.
So it works for browser but doesnt work for mobile. Wich should be, if so, the valid url for the mobile? Cause since it's an APP iºm confused. I dont think it's necessary show code but if so just ask me.
Thanks ;)
You can still use openFB and it will work. you don't even need to change anything in the openfb.js file. all you have to do is manipulate the call method from the page where you want to call the facebook login window.
say for example you have the facebook call method in index.html
then add this script to that index.html page where the function "facebooklogin()" is called
<script>
openFB.init({ appId: 'your-app-id' });
function facebooklogin() {
openFB.login(function (response) {
if (response.status === 'connected') {
if (response.authResponse) {
var accessToken = response.authResponse.accessToken;
openFB.api({
path: "/{your app version in facebook developer envi.}/me?",
params: { "access_token": accessToken, "?fields":"name,email,gender,user_birthday,locale,bio&access_token='"+accessToken+"'" },
success: function (response) {
var data = JSON.stringify(response);
// do whatever you want with the data for example
$(".data_div").html(data);
$(".data_email").html(data.email);
},
error: function(err){
alert(err);
}
});
}
else {
alert(“empty response returned”);
}
}
else {
alert(“not connected”);
}
},
{
scope: "public_profile,email,user_birthday"
});
}
</script>
very important! Please replace {your app version in facebook developer envi.} with your app version like v2.0 or v2.5
also don't forget to change 'your app id' to you facebook app id example 432046826485152
with openfb you don't need to crack your head over learning hoe to configure facebook login in other platforms. this will serve all platforms
I've got it working on the phone.
The weird thing is that a real URL is not necessary, just a semantic valid one. I've added a Facebook Canvas platform, on the facebook app page, and filled the platform form:
URL = http://localhost/www/
Secure Canvas URL = https://localhost/www/
Both of above domains doesn't exists. I haven't filled the "Valid OAuth redirect URIs" field in the advanced tab.
After that, I've written the following code in my app:
openFB.init("xyz!##123456789"
, "http://localhost/www/oauthcallback.html");
It seems that what matters is that Facebook Canvas's domains or sub domains matches the one on the openFB.init redirectURL param...
I'm using openFB version 0.1. I'm gonna test the earlier versions.
UPDATE
It just have worked because I was using phonegap serve and it makes openFB understand that my app is a website, because phonegap developer app is a browser wrapper, not a app wrapper. If I try to run it in a compiled app (phonegap local build), my code doesn't work. I think I'll have to use facebook-connect earlier than I thought...

Categories

Resources