How to pass a 'json' parameter with an url in android? - 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.

Related

How to create the Url which contains DATA like Custom url or Deep linking?

I tried the below link but getting the proper way of how to do this.
1st link,
2nd link,
3rd link,
4th link,
5th link
By these above links i only get to know that how can we get the data from the custom link.
Here is my code.
//get uri data
Uri data = getIntent().getData();
//get schma
String scheme = data.getScheme(); // "http"
//get server name
String host = data.getHost(); // Ipaddress or domain name
//get parameter
String urltextboxname=data.getQueryParameter("name");
//set value in textview
name.setText(urltextboxname);
BUT
My problem is that i want to create the custom link or deep linking on button click like I want to pass my UNIQUE ID in the link. and send it to other user by SMS or by EMAIL. And , when the user click on the link from SMS or EMAIL then user should navigate to the GOOGLE PLAY store , and install the application with my data on it. like the referral program application. Please help me to short out from these problem , pardon me if there any grammatical mistake on it.

putExtra sting convert to variable

Sorry for the silly question but im stucked
I want to send a large amount of data to other Activity through putExtra.
Is there any way to convert the "string" in putExtra("string", data ) to a variable given that it's stupid to write 100 different strings;
The putExtra method stores the data as a key/value pair. The string is like an index to the data it is not really a form of data in itself. When you want to retrieve your data you give the string and the system then finds the string in its indexing system and pulls out your data. Think about a book. If you want to find out about a particular subject (i.e. read some data) it would be time consuming to read the whole book to find out what you need. So instead you just check the index and you are able to go straight to the section you want and get the data you need.
Put simply the answer is NO. You must use a string and that string value must stay constant so that you can retrieve your data.
The string is simply the name that the data will be referred to as. If you want to pass 100s of strings then that's pretty easy, you just have to make data be a structure that contains your strings:
String[] data = new String[200];
... fill in the strings ...
putExtra("multipleStrings", data);

Converting multiple datas into a single string for uploading using json in android

I have to submit data from 30 pages into the server.These datas from 30 pages are to be made into a single string and that i have to upload that single string into the server using json.
Each page may contain many answers tht may be either in plain text(value we receive from edit text),from check boxes(yes or no) and so on.....please suggest me a way to add all these data into a single string and upload it using json.
Based on the comment I suspect that you believe that you need to treat these "pages" as strings that you concat. However, what I think you're overlooking is that JSON is pretty versatile in how you add objects to it.
So, let's say you have the thing that you want to ship to your server and you call it
JSONObject myEntireFile = new JSONObject();
you can now add stuff to it at any time like this...
JSONObject page1 = new JSONObject();
myEntireFile.put("page1", page1);
meanwhile you can put whatever you want IN page 1 (cause that's just another serialized container).
You can keep doing this until you're ready to send it, at which time you just call
myEntireFile.toString();
which will convert your object into one long, well formatted, JSON string, that you can then open store for later use.

How to get a string from a string-array?

In my app I have a ListView which is populated with URLs from a string-array. When the user selects some item in this ListView, the app should open a WebView and load the selected URL.
The string-array is like this:
<string-array name="app_urls">
<item>http://www.google.com</item>
<item>http://www.android.com/</item>
<item>http://www.youtube.com</item>
</string-array>
I am trying to get the string value of the url this way:
Resources res = getResources();
String[] url = res.getStringArray(R.array.app_urls);
webView = new WebView(view.getContext());
webView.loadUrl("http://" + url);
How can I correctly get the url value?
I dont know much about android but the last line you probably want something like
webView.loadurl(url[index of the url you want to use]);
because A) you already have the http://'s in your array definition so it would be redundant your way,
and B) as the above poster said you have to reference your array items by index. Think of an array like a train, where each 'index' is a car holding some data. Arrays are 0-indexed so the first slot is [0], 2nd is [1] and so on.
So if you wanted to get google out of your frst array youd call bookmark_urls[0], and if you wanted offspot youd say bookmark_urls[2].
I'm not sure why you define your string array then declare another string array and (as near as i can tell) make it equal to the first though. Cant you just reference 'bookmark_urls[]' throughout?
you have to access the element in the array.. for instance url[0] if the first element and so on.... you can't call an array in that way....

Conceptual help with Android ListView

I have a working android app using TextView, some formatting (line breaks, rows of dashes) and Linkify to generate a primitive "ListView-like" display with clickable URLs in each "row". I'd like to move up to a real ListView, but I'm just not finding the sample/explanation that I need to take that next step.
I have successfully reproduced the HelloListView sample, starting with the hardcoded string array, and moving to a string array defined in my res/values/strings.xml. I've taken one small step toward my goal by adding my HttpClient code to retrieve a set of data from a service, parse the results into a String Array and feed that into setListAdapter() such that my text and links show up as text-only in ListView items.
I want to move to the next step which is to make each "row" in my ListView launch the browser to the URL contained in the data, either by
(A) clicking anywhere in the row, or
(B) clicking a hyperlink displayed within the row data
For option (A), it appears that I need to have my onItemClick() method issue an intent that launches the browser. That's straightforward, but I don't get how to associate the URL with the item (currently its just one part of the string content for each "row" of text). How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL? Do I need to replace my String Array with an array of custom objects?
For option (B), can I use Linkify? It seems that my string array elements get converted to individual TextViews (inferring from the way the Toast text is generated in the HelloListView sample). Do I have access to that TextView to run Linkify against? Do I need to replace my String Array with a TextView Array and run Linkify myself? Am I completely off base?
Thanks to anyone who can help explain back to me what I'm trying to do, in a way that helps to find my way around the SDK, samples and other helps!
How do I separate my URL from the rest of the text, such that I can launch a browser to the corresponding URL?
Use a regular expression (java.util.regex) to find the URL.
For option (B), can I use Linkify?
Yes.
Do I have access to that TextView to run Linkify against?
Yes. Override getView() in your ArrayAdapter. Chain to the superclass and get your TextView from the result of super.getView().
Even better would be to use Linkify on your strings before putting them in the array in the first place.
Do I need to replace my String Array with a TextView Array and run Linkify myself?
No, and that is really not a good idea. Here is a free excerpt from one of my books that goes into more detail on tailoring the individual rows of a ListView, in case this helps.

Categories

Resources