java - Android Retrofit post information to api database -
how can post in case information android device api route. not response in android monitor.
i have created basic retrofitbuilder class. have created apiservice contains this:
@formurlencoded @post("device") call<deviceresponse> device(@field("device_name") string device_name, @field("device_producer") string device_producer, @field("device_pixel_width") int device_pixel_width, @field("device_pixel_height") int device_pixel_height, @field("device_ratio_width") int device_ratio_width, @field("device_ratio_height") int device_ratio_height, @field("device_android_version") int device_android_version, @field("device_status") int device_status);
a device model contains device constructor setter , getters.
a deviceresponse class:
public class deviceresponse { list<device> data; public list<device> getdata() { return data; } }
and in activity call this:
floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab); fab.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { tokenmanager = tokenmanager.getinstance(getsharedpreferences("prefs", mode_private)); service = retrofitbuilder.createservicewithauth(apiservice.class, tokenmanager); integer id = null; string device_name = "samsung"; string device_producer = "apple"; int device_pixel_width = 12312; int device_pixel_height = 123; int device_ratio_width = 12; int device_ratio_height = 23; char device_android_version = 6; int device_status = 1; call = service.device(device_name, device_producer, device_pixel_width, device_pixel_height, device_ratio_width, device_ratio_height, device_android_version, device_status);
just need add @post
annotation endpoint like
@formurlencoded @post("endpoint") call<deviceresponse> device(@field("device_name") string device_name, @field("device_producer") string device_producer, @field("device_pixel_width") int device_pixel_width, @field("device_pixel_height") int device_pixel_height, @field("device_ratio_width") int device_ratio_width, @field("device_ratio_height") int device_ratio_height, @field("device_android_version") int device_android_version, @field("device_status") int device_status);
check more info: https://futurestud.io/tutorials/retrofit-send-data-form-urlencoded
Comments
Post a Comment