java - how to instantiate Uri from a String? -


what correct way convert uri image base64 string before send server ?

public void update( final string claimtype,  final string amount, final string description, final string imageuri)     {            class updateimageandtext extends asynctask<void,void,string>{               // progressdialog loading;                @override                protected void onpreexecute() {                    super.onpreexecute();                   // loading = progressdialog.show(edit_staff.this,"updating...","wait...",false,false);                }                 @override                protected void onpostexecute(string s) {                    super.onpostexecute(s);                   // loading.dismiss();                    toast.maketext(getapplicationcontext(), s, toast.length_long).show();                    try {                        intent returnintent = new intent();                        returnintent.putextra("claimtype", claimtype);                        returnintent.putextra("amount", amount);                        returnintent.putextra("description", description);                        returnintent.putextra("photo", imageuri);                        setresult(activity.result_ok, returnintent);                        finish();                    }catch(exception e)                    {                     }                }                 @override                protected string doinbackground(void... params) {                    hashmap<string,string> hashmap = new hashmap<>();                    hashmap.put(configs.key_id, string.valueof(id));                    log.e("id", id + "");                    hashmap.put(configs.key_type, claimtype);                    hashmap.put(configs.key_amount, amount);                    hashmap.put(configs.key_description, description);                    if(imageuri != null){                        log.d("log", "photo " + imageuri);                        hashmap.put(configs.key_image,getstringimage(imageuri)); // error                    }else{                        log.d("log", "photo null " );                    }                    requesthandler rh = new requesthandler();                    string s = rh.sendpostrequest(configs.url_updatede_image_text,hashmap);                    return s;                }            }          updateimageandtext ue = new updateimageandtext();         ue.execute();     }   public string getstringimage(uri imguri) {          try {             bitmap bitmap = mediastore.images.media.getbitmap(getcontentresolver(), imguri);             bytearrayoutputstream baos = new bytearrayoutputstream();             bitmap.compress(bitmap.compressformat.jpeg, 100, baos);             byte[] imagebytes = baos.tobytearray();             string encodedimage = base64.encodetostring(imagebytes, base64.default);             return encodedimage;         } catch (exception e) {         }          return "";     } 

error

error:incompatible types: string cannot converted uri 

in update passing imageuri string:

public void update( final string claimtype,  final string amount, final string description, final string imageuri)    hashmap.put(configs.key_image,getstringimage(imageuri)); // error because imageuri string 

but method expect uri not string:

public string getstringimage(uri imguri){...} 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -