1

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

Shudy
  • 7,806
  • 19
  • 63
  • 98
  • Data URL is a misspelling of Data URI - a URI which represents the resource itself, rather than the location of the resource. – Phantômaxx Nov 08 '16 at 10:37
  • Then, is possible to do this? I mean, what i need to send is: ` textMessage.setAvatarUrl(String url);` – Shudy Nov 08 '16 at 10:46
  • From an image stored in your drawable folder you can get the URI by using some of the methods explained here: http://stackoverflow.com/questions/6602417/get-the-uri-of-an-image-stored-in-drawable . However i don't know if it's possible the get an URI from a local drawable variable. – Veselin Todorov Nov 08 '16 at 10:55

1 Answers1

2

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491