Drawable to data url in android

424 views Asked by At

I have a Drawable generated by a library,it makes round image with letter inside.

But in the view that I have to insert, accepts only url, and I need to convert this drawable to a url, but I don't know how to do it.

The Drable looks like:

TextDrawable drawable = TextDrawable.builder()
                            .buildRound(mConnection.getUser().substring(0, 1).toUpperCase(), ContextCompat.getColor(getApplicationContext(),mConnection.getContactStatus(mcontact).getColor()));;

thanks in advance

1

There are 1 answers

0
CommonsWare On

But in the view that I have to insert, accepts only url

Stop using that View and switch to another one that accepts a Drawable.

I need to convert this drawable to a url

If you want to waste the user's RAM, CPU, and battery, you can draw the Drawable to a Bitmap-backed Canvas, write that Bitmap out to a file (e.g., PNG) using compress(), then try using a file:/// URL.

Your question title suggests using a data: URL. Unless the documentation for this unidentified View specifically claims that the View supports the data scheme, most likely it does not.