Web service call - android

in my application I'm calling web service for creating lakes.for that user enters the lake name in edit text and i'm sending that entered name to web service.
now when I'm entering string with space the web service could not call successfully.it shows an exception that illegal char at (the space which I've give in edit text).
i"m not able to find solution for this since i want to send name with space in it.
any help is appreciated.
Thanks

before adding lakeName to the webservice url, do this
final String encodedLakeName = URLEncoder.encode(lakeName, "UTF-8");
Now use this encodedLakeName.

Related

Android SMS app ignores a trailing "?" when the URL containing a trailing "?" is clicked

I send an SMS saying "Click on https://www.example.com/?"
When I receive this SMS on an Android phone, only the https://www.example.com is clickable. The "?" is visible in the SMS, but is not part of the clickable URL.
Is there some way to escape the ? or do some other workaround so that click on the link goes to https://www.example.com/?
EDIT: Forget Android - even on this page on stackoverflow - the "?" is not part of the clickable link
Can you replace the question mark (?) by %3F
www.example.com/%3F
See:
https://www.w3schools.com/tags/ref_urlencode.asp
This appears to be correct behaviour (as far as I have observed on other systems) - an empty query string (effectively a dangling question mark) is not necessarily part of the URL so appears as punctuation.
As a workaround my suggestion is to ensure you always provide a parameter:
https://www.example.com/?a=a
Ideally you can find something that makes the link enticing to the user (rather than only confusing):
https://www.example.com/?vip=yes
Because these are not query parameters you are actually using, they should not affect your page processing
Hi you can send by converting to short url by https://goo.gl/ and you can get same as expected .

ANDROID - display image and text from separate web service calls

I need your advice or ideas regarding my problem. The app I'm working on needs to display an image and text from two separate web services. The first web service (image) returns a base64 encoded string and the last web service(text) returns a plain json response.
Some samples I found on the web is that they only use one service to display the record with the the string url of image something like this:
[{"id":"1","version_name":"Alpha","description":"","version_code":"1.0","api_level":"1","image":"http:\/\/www.test.com/img/cupcake.jpg"}]
But in my case, the client has given me two separate calls to view the data (details) and image:
[{"id":"1","version_name":"Alpha","description":"","version_code":"1.0","api_level":"1"}]
for image Base64 String result (SAMPLE):
"iVBORw0KGgoAAAANSUhEUgAAAGQAAABfCAYAAAAeX2I6AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAACxIAAAsSAdLdfvwAAEc8SURBVHhezb13dBzHmT3qc37nvV1bXq+9tvfn9Xpt79q78tpWdJAsKllWJsWcwRyRc2QQgyiJogIpkiIJEDkMcmLOOSeJOZPIwOQ8gxkAvO9+NWhwBIE0Kck+7497uru6urr7u/Wl6urub+g6SpDfVYIcVHBZhbxblfeMXHCJUuR0ViC7s0ohE9VIJ1az/DbKWFahkMFj1nI7u6sCeV21yL1VhbLOYuhQjOqOXNShAFbWcHV9AheXdmQpOJANJ5ceLt08i8BxK5/7ctU+B/e5b+XB2ZlD5MLZlUVksp1suG6xjOsCtzo+B/ZbRTymGLauPK6znVuFatsh52c9gQNFsHUSXflcl3Pksb1cIl+16brF9rpKed5CgudUbRSptgLtFdwznDze0VmAr0RINoWbyZvIoNBzb1HAJCansxzZt8qR21V9G6ybc6usBxm
To display this in a listview, how would I display them at the same time? How would you create a workaround for this?
I would truly appreciate your help. Thanks.

Seperate address name from number android

I am creating an app and i get an Address from geocoder.So I am getting a string that contains the address.My problem is that I want to put the name in a Textview the number in an Edittext(so the client can edit the number) and the city with the postcode to an other Textview.Any ideas?Thanks.
If there is a particular pattern in the Address you get, you can use String.split() method of Java to extract tokens which can then be used individually to fill particular information. See this example for understanding its working.
The best approach would be to write a Regular expression and group corresponding pieces of information and then getting them back using Matcher class.
This example explains how to get Regular expression's to work.

Difficulty in passing text as parameter from android to jsp page

I am trying to pass a text from the spinner. Actually the spinner contains the textx which I have fetched from the server side of my application.
So what I am trying to do is that, as soon as I select text from the spinner, I want that string to be passed to the server side. So here i am passing the text to a function which can make a request to the JSP.
Main part of the code(android)
categ = ((TextView) selectedItemView).getText().toString();
postData(categ);
//Remaining section
public void postData(categ)
{
String page="processing_pages/individual_phone_communicator.jsp?rom="+categ;
result = ws.getWebData(page);
if (result != null)
plotData();
else
alerter("null");
}
(It is returning a null value always.But when i am directly running the same query without any parameter and taking the value directly at the JSP page, it shows result)
Now it will move to the JSP.
String hk=request.getParameter("rom");
Now i am running a query like this:
sqlstatem="select first_name,latitude,longitude from tbluserdetails where user_id=(select user_id from tblindividual_job where jcat_id=(select jcat_id from tbljobcat where job_name='"+hk+"'))";
I am expecting it to give back data in the form of json array. But instead it is showing an error. I tried entering the parameter directly from browser even. Sometimes, the page is displaying correct answer with above query. This makes me more confusing. But when i tried with numbers such as 1 or 2 from the eclipse:
String page="processing_pages/individual_phone_communicator.jsp?rom=2"
and modified the query by trying the exact word instead of 'hk' like this
int rom=Integer.parseInt(request.getParameter("romo"));
if(rom==1)
{
sqlstatem="select first_name,latitude,longitude from tbluserdetails";
}
else
{
sqlstatem="select first_name,latitude,longitude from tbluserdetails where user_id=(select user_id from tblindividual_job where jcat_id=(select jcat_id from tbljobcat where job_name='Blood donar'))";
}
it is running correctly. From browser also, it is running correctly when i pass integer as parameter. But i need it to be running by taking a text from the emulator as parameter.
But when I try, like this:
String page="processing_pages/individual_phone_communicator.jsp?rom=Blood donor"
Then also i am getting null as result. What I assume is that, my JSP page is only taking integer parameters, I don't know why it is happening.
I am using net beans for JSP. Kindly find me a solution for this issue. Kindly ignore if the question is childish, as i am just a beginner.
I don't know what the "ws" variable is, but the IP for your local machine (not the phone) in the android emulator is 10.0.2.2. So any URL pointing to a local web app on your machine should start with http://10.0.2.2/...
Mike

Android: Parsing URL into web service without space character

All I want to do is to send a URL String into my RESTFUL web service with some kind of code like this
URL someURL= new URL("http://myWebService:port/service/"+CharSequence.getText());
Its all going well until I found error with space character in my URL. I found some solution about replacing the space character with %20 which is I already defined with something like this :
URL someURL= new URL("http://myWebService:port/service/"+CharSequence.getText().replace(" ", "%20"));
Everything, again, seems going well until i found that the replace(Char oldChara, Char newChara) function can only replace ONE space character, and not two.
For brief example when I send the CharSequence.getText() with values "We won" there will be no error, but when I change the values into "We won the battles" there will be an error issuing that there are some illegal character sent to my RESTFUL web service.
Any kind of answer will come up with my great thanks and big salute
~Regards~
Use replaceAll instead of replace.
Although, you should really be doing proper URL encoding. You can use URLEncoder.encode
for example.

Categories

Resources