android - how to avoid the null value for bitmap images -
i have made program upload image , has 2 buttons 1 pick image fom gallary , upload database if click upload button without choosing image face null value ,how can avoid it.? 1 me.
here upload code:
public void insertimage() { class updateemployee extends asynctask<void, void, string> { string image = getstringimage(bitmap); progressdialog loading; @override protected void onpreexecute() { super.onpreexecute(); loading = progressdialog.show(settings.this, "updating...", "wait...", false, false); } @override protected void onpostexecute(string s) { super.onpostexecute(s); loading.dismiss(); toast.maketext(settings.this, s, toast.length_long).show(); } @override protected string doinbackground(void... params) { hashmap<string, string> hashmap = new hashmap<>(); hashmap.put(config.key_job_user_id, userdetails.user_id); hashmap.put(config.tag_image, image); requesthandler rh = new requesthandler(); string s = rh.sendpostrequest(config.url_update_emp, hashmap); return s; } } updateemployee ue = new updateemployee(); ue.execute(); }
here getstingimage method:
public string getstringimage(bitmap bmp) { bytearrayoutputstream baos = new bytearrayoutputstream(); bmp.compress(bitmap.compressformat.jpeg, 30, baos); byte[] imagebytes = baos.tobytearray(); return base64.encodetostring(imagebytes, base64.default); }
just change:
updateemployee ue = new updateemployee(); ue.execute();
to:
if (bitmap != null) { updateemployee ue = new updateemployee(); ue.execute(); }
no?
Comments
Post a Comment