Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My android app is a news app, and it connects to a web service to get JSON and shows it in a listView. News in app includes title, description, and the date time of the news. I want to get the latest JSON based on date time and if new JSON arrives with a later date time, I want to push a notification to the user.
how use this please help me
Api url sample:"http://api.khabarfarsi.net/api/news/top/1?tid=9&output=json[^]"


Java
  @Override
		protected Void doInBackground(Void... arg0) {
			// Creating service handler class instance
			ServiceHandler sh = new ServiceHandler();

			// Making a request to url and getting response
			String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);

			Log.d("Response: ", "> " + jsonStr);

			if (jsonStr != null) {
				try {
					JSONObject jsonObj = new JSONObject(jsonStr);

					// Getting JSON Array node
					contacts = jsonObj.getJSONArray(TAG_ITEMS);
                                   
                                    // looping through All Contacts
					for (int i = 0; i < contacts.length(); i++) {
						JSONObject c = contacts.getJSONObject(i);

					String teaser = c.getString(TAG_TEASER);
				        String title = c.getString(TAG_TITLE);
                                        String date = c.getString(TAG_DATE);



						// tmp hashmap for single contact
						HashMap<string,> contact = new HashMap<string,>();

						// adding each child node to HashMap key => value
                                            contact.put(TAG_TEASER, teaser);
				            contact.put(TAG_TITLE, title);
                                            contact.put(TAG_DATE, date);
//
						// adding contact to contact list
						contactList.add(contact);
                                            
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			} else {
				Log.e("ServiceHandler", "Couldn't get any data from the url");
			}

			return null;
		}
Posted
Updated 25-Apr-15 18:35pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900