why my method and taskSnapshot doesn't work ?
and here's my POJO
Add other 4 parameters using coma ,
As declared in your UserInformation you need to put all parameter to create the object.
Try something like that :
String judul = "";
String isi = "";
String penulis = "";
String kat = "";
String url = taskSnapshot.getDownloadUrl().toString;
UserInformation userInformation = UserInformation(judul , isi, penulis, kat, url)
Related
I have an issue in getting parameters from a URL mentioned below,
String url = http://example.com/api_callback#access_token=XXXXXXXXXXXXXXX&state=enabled&scope=profile%20booking&token_type=bearer&expires_in=15551999
My code to extract the parameters is as follows:
Uri uri = Uri.parseurl(url);
Set<String> paramNames = uri.getQueryParameterNames();
However, as you can see a "#" in the URL instead of "?" so that's why I am not able to get the parameters Set.
First thing that came to my mind is to replace "#" with "?" using String.replace method then I thought their might be better solution for this. So if you guys have better solution please help me.
Easiest method:
String string = url.replace("#","?");
String access_token = Uri.parse(string).getQueryParameter("access_token");
Log.d("TAG", "AccessToken: " + access_token);
Now you can get any parameter from the url just by passing their name.
Good Luck
'#' is called refrence parameter, Here you can do one of two things either replace the '#' with '?' and process your uri i.e
String url = "http://example.com/api_callback#access_token=XXXXXXXXXXXXXXX&state=enabled&scope=profile%20booking&token_type=bearer&expires_in=15551999";
url = url.Replace("#","?"); //now your URI object to proceed further
or other alternative
String url = "http://example.com/api_callback#access_token=XXXXXXXXXXXXXXX&state=enabled&scope=profile%20booking&token_type=bearer&expires_in=15551999";
URL myurl = new URL(url);
String refrence = myurl.getRef(); //returns whatever after '#'
String[][] params = GetParameters(refrence);
and the defination for function GetParameters() is following
private String[][] GetParameters(String r)
{
try
{
String[] p = r.split("&"); //separate parameters mixed with values
String[][] data = new String[p.length][2];
for(int i = 0 ; i<p.length; i++) //iterate whole array
{
data[i][0] = p[i].split("=")[0]; //parameter name
data[i][1] = p[i].split("=")[1]; //parameter value
data[i][1] = data[i][1].replace("%"," "); //replace % with space character
}
return data; //return result
}
catch(Exception e)
{
return null;
}
}
i have not executed and tested the code i am lazy one too so i hope you will accomodate lolz :D
You can use the Uri class in Android to do this; https://developer.android.com/reference/android/net/Uri.html
Uri uri = Uri.parse("http://www.chalklit.in/post.html?chapter=V-Maths-Addition%20&%20Subtraction&post=394");
//Then you can even get a specific element from the query parameters as such;
String chapter = uri.getQueryParameter("chapter"); //will return "V-Maths-Addition "
Uri uri = Uri.parse("http://www.chalklit.in/post.html?chapter=V-Maths- Addition%20&%20Subtraction&post=394");
String server = uri.getAuthority();
String path = uri.getPath();
String protocol = uri.getScheme();
Set<String> args = uri.getQueryParameterNames();
Then you can even get a specific element from the query parameters as such;
String chapter = uri.getQueryParameter("key");
I have a google play store url "https://play.google.com/store/apps/details?id=com.apusapps.launcher&hl=en" from this url I have to store"com.example.launcher" in a seperate variable and compare from package name "com.example.launc" if compare I have to send a json request .how can I do that
Try this:
String s = "https://play.google.com/store/apps/details?id=com.apusapps.launcher&hl=en";
String s2 = s.substring(s.indexOf("=")+1, s.indexOf("&"));
Toast.makeText(this,"Milad: "+s2,Toast.LENGTH_LONG).show();
You can do like this:
String urlString = url.toString();
String finalString = urlString.substring(urlString.indexOf("=")+1,urlString.lastIndexOf("&"));
if(finalString.equals(getApplicationContext().getPackageName())){
//Your code
}
I am working on android application. I am getting the String value from webservice extension
i want to split 4 from the string by using index .pls tell me how can do this
String version = "1.4.2";
Try this..
String version = "1.4.2";
Log.v("value ",""+version.split("\\.")[1]);
For more information Refer Link1,Link2
can you try this :
String[] items = "1.4.2".split("\\.");
String version = items[1].toString();
have all the sub-part of your string using
String[] strs = version.split("\.");
now if you want 4 from (1.4.2), do following:
String mMiddle = strs[1]; // it will give 4 as a string in mMiddle
if you want every sub-part:
String mStart = strs[0]; //returns 1
String mMiddle = strs[1]; //returns 4
String mLast = strs[2]; //returns 2
Try this code:
String version = "1.4.2";
String arr[]=version.split("\\.");
String value=arr[1].toString();
System.out.println(arr[0]);
System.out.println(arr[1]);
System.out.println(arr[2]);
thank you.
Example: I have a EditText and I want to check the first word is the city name and second word is the pincode. These both words are separated by comma(,).
Hey try this if you don't want to use split. YOu need to get string into a variable from edittext and then use the following code for doing yourself able to validate :)
String str = "tim,52250";
StringTokenizer st = new StringTokenizer(str, ",");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
Do this way..
String content="Mehsana,384001";
String[] contentArray=content.split(",");
And you will get
contentArray[0]=Mehsana
contentArray[1]=384001
then you can validate each string content..
Use split() to get the things done.
Ex:
String s= "abc,123"
String s1[]=s.split(",");
String city=s1[0];
String pincode=s1[1];
Try this
String strInput = editText.getText().toString();
String strSplit [] = strInput.split(",");
System.out.println("CityName : " + strSplit[0]);
System.out.println("PinCode : " + strSplit[1]);
String data = "ali,524513"
String []array = data.split(",")
you can validate array[0] and array[1] :)
System.out.println("Name: "+array[0]+" code: "+array[1]);
With this function I got a String from the server as a response:
String responseBody = EntityUtils.toString(response.getEntity());
the String value I retrieve looks more or less like this:
"http://url.com 765889"
I want to divide the URL and the numbers into 2 String values, it should be:
String 1="http://url.com"
String 2="765889"
How am I able to perform that?
Use the split() function:
String[] parts = responseBody.split(" ");
Maybe like this
String 1 = responseBody.substring(0,responseBody.indexOf(" ")-1);
String 2 = responseBody.substring(responseBody.indexOf(" ").responseBody.length()-1);
Simples do this
StringTokenizer t = new StringTokenizer("http://url.com 765889"," ");
Log.d("first", t.nextToken());
Log.d("second", t.nextToken());