This question already has answers here:
Java URL encoding of query string parameters
(11 answers)
Closed 5 years ago.
I am using URL in one format. but when I enter it in Google and when pressed enter it is converting to another format.
below is my original URL
'https://translation.googleapis.com/language/translate/v2?q=hai basha.how are you&target=te&key={YOUR_API_KEY}'
below is my encoded url
'https://translation.googleapis.com/language/translate/v2?q=hai%20basha.how%20are%20you&target=te&key={YOUR_API_KEY}'
how can I implement this in my code. Actually it is a GET method.
you can use String.replace method to change characters to their respective special character notation. and make a call through get or post or what ever you want.
Related
This question already has answers here:
How can I fix 'android.os.NetworkOnMainThreadException'?
(66 answers)
The AsyncTask API is deprecated in Android 11. What are the alternatives?
(19 answers)
Closed 9 months ago.
I am trying to convert a URL to Base64 in Kotlin. I am using Apache Commons IO to accomplish this by first converting the URL to a ByteArray:
val imageBytes = IOUtils.toByteArray(URL(url))
This line creates a android.os.NetworkOnMainThreadException error when I run my app. How do I resolve this? I don't want to change the ThreadPolicy to bypass the error. Below the above line of code, I also have the following:
val imageBase64 = Base64.encode(imageBytes, Base64.URL_SAFE and Base64.NO_WRAP)
val item = ItemCard(
imageBase64,
label,
total
)
list += item
The entire code block is in a loop. So I would also need something where I can get the result in a timely manner where it doesn't interfere with the actual Base64 encoding.
This question already has answers here:
I can only get part of a url (link) and put into string in android?
(2 answers)
Closed 6 years ago.
Ok I wasn't really sure how to word this question, but basically what I want to do is, I got a url from a RSS feed in android, and I need to put part of that url into a string, the url will look something like this: http://www.prsn.uprm.edu/Spanish/Informe_Sismo/myinfoGeneral.php?id=20161206012821and I only want the part after id=, ONLY the number, is that possible? Please help me, Thanks
You can achieve this by using two ways:
// One Way
String url = "http://www.prsn.uprm.edu/Spanish/Informe_Sismo/myinfoGeneral.php?id=20161206012821";
String substr = "=";
String after = url.substring(url.indexOf(substr) + substr.length());
// Second Way
String[] parts = url.split(substr);
String afterTwo = parts[1];
This question already has answers here:
Simple parse JSON from URL on Android and display in listview
(6 answers)
parse simple json string in android
(4 answers)
Closed 7 years ago.
i have a url that inide of this url is json code .
i need this content to decode. for example if my url is : http://url.com
i have this json in it:
{ "employee":{"mesg":"username is exsist!","id":0,"name":0,"username":0,"email":0,"status":500} }
i need from url.com this data to put in a variable and decode this.
for decoding i dont have problem . just i need to get data from url , like file_get_contents in php .
, thanks
NOTICE:
i use HttpClient for this solution . but it is deprecated . is another way for this?
You can use IOUtils.toString(url) from Apache Commons library.
This question already has an answer here:
How to extract this string variable in android?
(1 answer)
Closed 9 years ago.
String test=["1","Low-level programming language",true]
Here i want to extract this string value and as i need to get only second value like "Low-level programming language".How to get this value using string functions in android?
Per your comment, I'm assuming that you have a single string that contains the entire text (including the brackets). In general, splitting comma-separated values is a fairly tricky process. For your specific string, though, it's kind of easy:
String test = "[\"1\",\"Low-level programming language\",true]";
String[] pieces = test.split(",");
String middle = pieces[1];
// now strip out the quotes:
middle = middle.substring(1, middle.length() - 1);
In general, you might want to look at using a general CSV parser like Apache Commons CSV or openCSV.
Alternatively, if this is JSON data (which looks more likely than CSV), take a look at using one of the Java JSON libraries listed here (scroll down the page to see the list).
This question already has answers here:
Difference between getString() and getResources.getString()
(3 answers)
Closed 9 years ago.
I read about String Resources and I understood that you simply use the getString(...) method in order to read the value of a string from res/values/string.xml. Then I read that you can also use getResources().getString(...).
What is the difference between these two ways of obtaining the value of a string?
No any difference. They're both equal.