How to get Custom Url - android

In my java file URL is static like
String URL = "https://aa.com/hospital/dmc.jpg";
But I want the URL will come from database like
https://aa.com/hospital/dmc.jpg
and after adding " sign at the first and the last word and put into a string.
How can I get that?

You can do it by replace() function
url = url.replace("https:","\"https:").replace(".jpg",".jpg\"");
You can get more information here
question

Related

Passing Edittext value to Get Request URL in Volley

I want to add edittext value to simple GET Request URL in Android. But I am facing some error while concatenation. This is what I am sending.
String forgot_email = et_email.getText().toString(); //gives me proper email output
final String final_url = "http:abc....../"+forgot_email.getText().toString(); // Here edittext value is not appending.
final_url = "http:abc....../" // logs value shows its not appending in the end.
I want send this URL to Server.
http:abc....../EMailID
Any responses will be highly appreciated.
I resolved it. Basically I write these two lines inside click listener.I had written outside previously . Thanks all
It should be either
String final_url = "http:abc....../"+et_email.getText().toString();
or
String final_url = "http:abc....../"+ forgot_email;

Why do Glide only work on raw string url data? (Android Studio)

I can successfully use a string url with glide to get the image I want:
glideVariable!!.loadImageUrl("https://firebasestorage.googleapis.com/v0/b/healthandchocolate-46f3d.appspot.com/o/cookies%2FcookiesImg1.jpg?alt=media&token=63721d7d-207e-441c-9387-14dced13d3c8")
but when I try to use the very same url, stored in a variable, the image doesn't load:
glideVariable!!.loadImageUrl(recipeArray[1].recipeImage.toString())
I have done a Log.d on recipeArray[1].recipeImage.toString() and it does indeed contain the very same url that worked on my first example, using raw string data.
I have used escape commands to encapsulate the variable in quotation marks like this:
glideVariable!!.loadImageUrl("${recipeArray[1].recipeImage.toString()}")
but it still doesn't work. I have also tried to cast it as URL and URI, but still nothing. Any ideas? Can glide only use raw string data?
UPDATE
I noted that recipeArray[1].recipeImage contain both a key and a value. Perhaps this is the problem. It doesn't access the url string directly. How do I make sure just to use the string value? It looks like this:
DataSnapshot { key = recipeImageFirebase, value = https://firebasestorage.googleapis.com/v0/b/healthandchocolate-46f3d.appspot.com/o/cookies%2FcookiesImg1.jpg?alt=media&token=63721d7d-207e-441c-9387-14dced13d3c8 }
OK, got it now. The recipeArray[1].recipeImage.toString() was a data snapshot containing both a key and a string. I went back to when I stored the variable:
val image = item.child("recipeImageFirebase")
tempRecipe.recipeImage = image.toString()
and changed the last part to
tempRecipe.recipeImage = image.value.toString()
Now it only contains the string value and not the key "recipeImageFirebase" as well!

how to pass value at runtime in url in android using json parsing?

i am trying to get name and address of hospitals,atm's,restaurants ....etc. near by my location with the help of google near by places api so i use json parsing ,since i can able to get all the name and address but only problem is that i can't understand that how can i get different values of ex. hotel,hospital,atm,bank...etc. using same url by putting different different values in run time.here is my url ....
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=26.841,75.801&radius=5000&types=hospital&key=AIzaSyBstND0mA7NZJPulZRcNtoWyJwXaKxqsFI";
In the above url there is a field "types" ,here i want to pass different different values at run time.....like hotel,hospital,bank,atm ...etc.
String type = "hospital";
int radius =5000;
String string = String.format("https://maps.googleapis.com/maps/api/place/nearbysearch
/json?location=26.841,75.801&radius=%d&types=%s&
key=AIzaSyBstND0mA7NZJPulZRcNtoWyJwXaKxqsFI", radius, type);
You can use Uri to build this
String base="https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=26.841,75.801";
String RADIUS="5000";
String TYPES="hospital";
String KEYS="AIzaSyBstND0mA7NZJPulZRcNtoWyJwXaKxqsFI";
Uri builtUri=Uri.parse(base).buildUpon()
.appendQueryParameter("radius",RADIUS)
.appendQueryParameter("types",TYPES)
.appendQueryParameter("key",KEYS)
.build();
URL url=new URL(builtUri.toString());
OUTPUT
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=26.841,75.801&radius=5000&types=hospital&key=AIzaSyBstND0mA7NZJPulZRcNtoWyJwXaKxqsFI
You can easily change value of RADIUS,TYPES on runtime

How to pass a 'json' parameter with an url in android?

I have check-boxes on one page and when user selects a particular check-box, it passes the id associated with it to the next page, on this page I want to send those ids in the form of url to a wcf service.
My url is
http://rankup.co.uk/service1.svc/getTopic/
After adding the parameters, I want this json to pass with the url like
http://rankup.co.uk/service1.svc/getTopic/20,32
where "20,32" are the ids selected by the user (it may vary accordingly)
Can anybody tell me how to do this?
Just pass the parameters with the Intent from the calling activity like this
intent.putExtra("parameters", "20,32");
Then retrieve this parameter from the second activity :
String parameters = getIntent().getStringExtra("parameters", 0.0);
After that make the url like this :
String url = "http://rankup.co.uk/service1.svc/getTopic/ "+parameters;
Second part : to get and parse the json you can see this tutorial.
Happy Coding.
You can create an array list or can create an string variable. On clicking on checkbox, you can add all ids in a comma separated list or array and then can send using intent to the next screen.

Only get part of string in android?

Okay I wasn't really sure how to word this question, but basically what I want to do is, I got a url from a webView in android, and I need to put part of that url into a string, the url will look something like this: http://localhost/?code=4/3pakksajdfASDFwek.4nsKfAYN7XQVshQV0ieZDAp-PrgEcAI and I only want the part after code=, is that possible? Thanks
int start = my_string.indexOf("=");
String suffix = my_string.substring(start + 1);
If other parameters can be on the URL, or code is not always first parameter:
String url = "http://localhost/?code=4/3pakksajdfASDFwek.4nsKfAYN7XQVshQV0ieZDAp-PrgEcAI";
String code = url.replaceAll(".*(?:[?]|[&])code=([^&]+)","\1");
tests here: http://fiddle.re/nxfv
If you are totally sure the URL never has other form, you can use indexOf and substring.
Otherwise, it is better if you use URI class to extract out the query part of the URL (use getRawQuery just to be safe), then tokenize it with split along & character and find the correct key-value pair to obtain the correct value. This method is not as brittle as indexOf method above.

Categories

Resources