2

I am working on TweetComposer from Twitter Kit. As far as I know, TweetComposer only provides an image URI.

How can I use this URI get images into a Drawable or Asset?

Nadeem_MK
  • 7,533
  • 7
  • 50
  • 61
franco phong
  • 2,219
  • 3
  • 26
  • 43
  • Thanks Andy for correcting my question, I was so rushed at that time so didn't check grammar and meaning, just tried to raised the question before backing home. In addition, I gave some tries on getting Uri from Drawable but not successful. http://stackoverflow.com/questions/6602417/get-the-uri-of-an-image-stored-in-drawable – franco phong Apr 17 '15 at 21:41

1 Answers1

0

Not sure if this is still actual but anyway... Create Bitmap file from your drawable resource with BitmapFactory.decodeResource(), then save it to some temporary file is some way like this:

String filename = "temp_image.png";
FileOutputStream fos;

fos = openFileOutput(filename, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.close();

Then use Uri.fromFile() to get Uri.

  • Context.MODE_PRIVATE will prevent any other application from accessing the file, including the Twitter application. Rather, Context.MODE_WORLD_READABLE should be used (although it was depreciated in API 17), but Google strongly cautions against this due to security concerns: https://developer.android.com/reference/android/content/Context.html#MODE_WORLD_READABLE – user1652110 May 19 '16 at 05:15