android - Difficulty to set latitude & longitude in marshmallow in url & displaying item -
difficulty set latitude & longitude in marshmallow in url & displaying item. setting latitude & longitude in url after hitting url want information on basis of hitting url .
while did not set lat & long in url dynamically . list coming image while have set lat & long manually in url
when hitting url use below code progress bar loader moving not getting list .
i setting lat & long in url dynamically .
please see error in code not getting in marhsmallow nothing getting while below marshmallow getting loader moving , moving . see in image
public class listviewactivity extends activity implements locationlistener { // log tag private static final string tag = listviewactivity.class.getsimplename(); // change here url of server api // private static final string url = "https://comida-95724.herokuapp.com/api/v1/restaurants?per_page=5&km=1&location=true&lat=19.0558306414&long=72.8339840099"; private progressdialog pdialog; private static string url; private list<movie> movielist = new arraylist<movie>(); private listview listview; private customlistadapter adapter; /** * attention: auto-generated implement app indexing api. * see https://g.co/appindexing/androidstudio more information. */ private googleapiclient client; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_listview); locationmanager locationmanager = (locationmanager) getsystemservice(context.location_service); client = new googleapiclient.builder(this).addapi(appindex.api).build(); //update coordinates every 30 seconds if (activitycompat.checkselfpermission(this, android.manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(this, android.manifest.permission.access_coarse_location) != packagemanager.permission_granted) { // todo: consider calling // activitycompat#requestpermissions // here request missing permissions, , overriding // public void onrequestpermissionsresult(int requestcode, string[] permissions, // int[] grantresults) // handle case user grants permission. see documentation // activitycompat#requestpermissions more details. return; } locationmanager.requestlocationupdates(locationmanager.gps_provider, 30 * 1000, 1, this); listview = (listview) findviewbyid(r.id.list); adapter = new customlistadapter(this, movielist); listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { movie movie = movielist.get(position); intent intent = new intent(listviewactivity.this, secondactivity.class); intent.putextra("name", movie.getname()); intent.putextra("average_ratings", movie.getaverage_ratings()); intent.putextra("full_address", movie.getaddress()); intent.putextra("image_url", movie.getthumbnailurl()); intent.putextra("cuisine", movie.getcuisine()); intent.putextra("cost", movie.getcost()); startactivity(intent); } }); listview.setadapter(adapter); pdialog = new progressdialog(this); // showing progress dialog before making http request pdialog.setmessage("please keep patience.its loading..."); pdialog.show(); } private void loadjson(double latitude, double longitude) { adapter = new customlistadapter(this, movielist); listview.setadapter(adapter); adapter.clear(); url = "https://comida-95724.herokuapp.com/api/v1/restaurants?per_page=5&km=1&location=true&lat="+latitude+"&long="+longitude; // creating volley request obj jsonobjectrequest moviereq = new jsonobjectrequest(request.method.get, url, null, new response.listener<jsonobject>() { @override public void onresponse(jsonobject response) { log.d(tag, response.tostring()); jsonarray restaurantsjsonarray = null; try { restaurantsjsonarray = response.getjsonarray("restaurants"); } catch (jsonexception e) { e.printstacktrace(); } hidepdialog(); // parsing json (int = 0; < restaurantsjsonarray.length(); i++) { try { jsonobject obj = restaurantsjsonarray.getjsonobject(i); movie movie = new movie(); //movie.settitle(obj.getstring("title")); movie.setname(obj.getstring("name")); //movie.setthumbnailurl(obj.getstring("image")); movie.setthumbnailurl(obj.getstring("org_image_url")); movie.setaverage_ratings(obj.getstring("average_ratings")); movie.setcuisine(obj.getstring("cuisine")); movie.setaddress(obj.getjsonobject("address").getstring("area")); // movie.setaddress(obj.getjsonobject("address").getstring("full_address")); movie.setcost(obj.getstring("cost")); movie.setdistance(obj.getdouble("distance")); jsonarray textjsonarray = obj.getjsonarray("restaurant_offers"); (int j = 0; j < textjsonarray.length(); j++) { jsonobject txtobj = textjsonarray.getjsonobject(j); //obj.getjsonarray("restaurant_offers").getjsonobject(0).getstring("text"); //movie.settext(obj.getjsonarray("restaurant_offers").getjsonobject(j).getstring("text")); movie.settext(txtobj.getstring("text")); } // movie.settext(obj.getstring("text")); movielist.add(movie); } catch (jsonexception e) { e.printstacktrace(); } } adapter.notifydatasetchanged(); } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { volleylog.d(tag, "error: " + error.getmessage()); hidepdialog(); } }); appcontroller.getinstance().addtorequestqueue(moviereq); // attention: auto-generated implement app indexing api. // see https://g.co/appindexing/androidstudio more information. //client = new googleapiclient.builder(this).addapi(appindex.api).build(); // client = new googleapiclient.builder(this).addconnectioncallbacks((googleapiclient.connectioncallbacks) this).addonconnectionfailedlistener((googleapiclient.onconnectionfailedlistener) this).addapi(appindex.api).build(); } @override public void ondestroy() { super.ondestroy(); hidepdialog(); } private void hidepdialog() { if (pdialog != null) { pdialog.dismiss(); pdialog = null; } } @override public void onstart() { super.onstart(); // attention: auto-generated implement app indexing api. // see https://g.co/appindexing/androidstudio more information. client.connect(); action viewaction = action.newaction( action.type_view, // todo: choose action type. "listview page", // todo: define title content shown. // todo: if have web page content matches app activity's content, // make sure auto-generated web page url correct. // otherwise, set url null. uri.parse("http://host/path"), // todo: make sure auto-generated app url correct. uri.parse("android-app://com.comida/http/host/path") ); appindex.appindexapi.start(client, viewaction); } @override public void onstop() { super.onstop(); // attention: auto-generated implement app indexing api. // see https://g.co/appindexing/androidstudio more information. action viewaction = action.newaction( action.type_view, // todo: choose action type. "listview page", // todo: define title content shown. // todo: if have web page content matches app activity's content, // make sure auto-generated web page url correct. // otherwise, set url null. uri.parse("http://host/path"), // todo: make sure auto-generated app url correct. uri.parse("android-app://com.comida/http/host/path") ); appindex.appindexapi.end(client, viewaction); client.disconnect(); } @override public void onlocationchanged(location location) { //whenever location updated call method load json loadjson(location.getlatitude(),location.getlongitude()); log.d("hello", location.getlatitude() + " " + location.getlongitude()); } @override public void onstatuschanged(string provider, int i, bundle bundle) { } @override public void onproviderenabled(string provider) { } @override public void onproviderdisabled(string provider) { } }
Comments
Post a Comment