Android manifest question

1,413 views
Skip to first unread message

Nate K

unread,
May 19, 2011, 1:36:03 PM5/19/11
to phonegap
My app relies heavily on communicating with a web service, and it
works good on the apple iPhone OS, but now when we are trying to port
it over to android I am getting the:

"NETWORK_ERR: XMLHttpRequestException 101"

To remove this error, I had to remove the <uses-permission
android:name="android.permission.INTERNET" /> line from the manifest
file. What are the effects of this on the app, and is there anyway to
have that line in and have cross-domain web service calls work?

Thanks in advance.
Nate

Nate K

unread,
May 19, 2011, 1:47:58 PM5/19/11
to phonegap
but then it breaks everything else.... so nevermind that didn't solve
anything at all... so why would I be getting the
xmlhttprequestexception 101 error in the first place?

Simon MacDonald

unread,
May 19, 2011, 1:51:18 PM5/19/11
to phon...@googlegroups.com
Yes, if you remove that permission everything on Android will break horribly.  

Can you post some code showing what you are trying to do?  
Perhaps the "adb logcat" output of your device?  
What version of Android and PhoneGap are you testing with?  
Are you loading your code from the file:// or http:// protocol?

Simon Mac Donald
http://hi.im/simonmacdonald


--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Nate K

unread,
May 19, 2011, 2:05:44 PM5/19/11
to phonegap
In the main java file I load the app using the file:// protocol
because I know the http:// protocol won't work.

Here is the code in the App.java file:

public class App extends DroidGap {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
super.loadUrl("file:///android_asset/www/index.html");
}
}

Here is the code for the web service call:
function dowebservicecall() {
alert('starting call');
var xml = '<?xml version="1.0" encoding="utf-8"?>';
xml += '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
xml += '<soap:Body>';
xml += '<GetCareersWithVideos xmnls="http://website.ca/"/>';
xml = '</soap:Body>';
xml += '</soap:Envelope>';


var xmlRequest;
xmlRequest = new XMLHttpRequest();
xmlRequest.open("POST",server_url+"page.asmx",false);
xmlRequest.setRequestHeader("Content-Type", "text/xml;
charset=utf-8");
xmlRequest.setRequestHeader("Content-Length", xml.length);
xmlRequest.setRequestHeader("SOAPAction", xmlns_url +
"GetCareersWithVideos");
try {
xmlRequest.send(xml);

alert('received');
} catch (Ex) { alert(Ex.message); }

}

The logging in the logcat is not showing me anything relating to this
error, just the catch statement is receiving the error and catching
it.

Thanks


On May 19, 10:51 am, Simon MacDonald <simon.macdon...@gmail.com>
wrote:
> Yes, if you remove that permission everything on Android will break
> horribly.
>
> Can you post some code showing what you are trying to do?
> Perhaps the "adb logcat" output of your device?
> What version of Android and PhoneGap are you testing with?
> Are you loading your code from the file:// or http:// protocol?
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

Simon MacDonald

unread,
May 19, 2011, 2:17:34 PM5/19/11
to phon...@googlegroups.com
Yeah, you ran into a bug in Android.  It doesn't support synchronous XHR.  Change:

xmlRequest.open("POST",server_url+"page.asmx",false);

to 

xmlRequest.open("POST",server_url+"page.asmx",true);

and life will be better.  Mind you, you'll need to handle the async request now.

Simon Mac Donald
http://hi.im/simonmacdonald

Nate K

unread,
May 19, 2011, 3:26:12 PM5/19/11
to phonegap
hey thanks that solved the first issue, but now i get status 0 instead
of 200 that I expect. The response text/xml is also null. Have you
seen this before? I can't seem to find the solution when other people
had this issue.

Thanks

On May 19, 11:17 am, Simon MacDonald <simon.macdon...@gmail.com>
wrote:
> Yeah, you ran into a bug in Android.  It doesn't support synchronous XHR.
>  Change:
>
> xmlRequest.open("POST",server_url+"page.asmx",false);
>
> to
>
> xmlRequest.open("POST",server_url+"page.asmx",true);
>
> and life will be better.  Mind you, you'll need to handle the async request
> now.
>

Simon MacDonald

unread,
May 19, 2011, 3:43:38 PM5/19/11
to phon...@googlegroups.com
It is pretty normal to get a response code of 0 when you are doing XHR from the file:// protocol.  Most if not all of the major frameworks handle this correctly.  Not sure why your response is null though.  I guess it depends on what you what you are doing with your read state change handler.

Simon Mac Donald
http://hi.im/simonmacdonald

Nate K

unread,
May 19, 2011, 4:14:31 PM5/19/11
to phonegap
xmlRequest.onreadystatechange = function() {
if (xmlRequest.readyState == 4 && xmlRequest.status == 0) {
alert(xmlRequest.responseXML);
}
}

replacing responseXML with responseText is just an empty string... I
know the web service returns information from the call.

On May 19, 12:43 pm, Simon MacDonald <simon.macdon...@gmail.com>
wrote:
> It is pretty normal to get a response code of 0 when you are doing XHR from
> the file:// protocol.  Most if not all of the major frameworks handle this
> correctly.  Not sure why your response is null though.  I guess it depends
> on what you what you are doing with your read state change handler.
>

Nate K

unread,
May 19, 2011, 4:49:49 PM5/19/11
to phonegap
If I do a GET to get the content of the page I'm doing it works with
status 200, but when I use POST it comes up with the status 0 and no
responsetext or xml.

Nate K

unread,
May 19, 2011, 6:50:59 PM5/19/11
to phonegap
Found out it was one line.... When i removed the content-length part
of the header it started to work to the 200 response status, and teh
synchronous works!

kind of a weird issue... i'd like to know why it worked like this

Simon MacDonald

unread,
May 20, 2011, 9:17:41 AM5/20/11
to phon...@googlegroups.com
Hey, glad you got it working.  Too bad you ran into some Android quirks on your way.  However, I will caution you not to try the synchronous XHR on Android.  It may be working right now but it will intermittently fail for you and cause your heartache and problems with your users.

Simon Mac Donald
http://hi.im/simonmacdonald
Reply all
Reply to author
Forward
0 new messages