1

I have an offline system that integrates with an Android app over a TCP connection.

I need to get an image stored in the system (in the format of "c:/user/me/img/img.png") from the android app and display it inside a button (not imageButton as the button could be either text, or image with a text).

I've tried sending the raw url but I couldn't load the image from the app even after converting it to a bitmap and drawable. So I thought maybe the raw url idea is not a good idea. Do I send a different format (URI?) from the pc to the app? What is the best working way to go about this?

Cheers

EDIT

exchange of data between the two are completely fine. i just need a way for the app to be able to display the image from the app's local database, which was populated with the string data that was sent by the pc over tcp. im just not sure what to send

Omar Dhanish
  • 885
  • 7
  • 18
allanae
  • 145
  • 2
  • 12
  • `c:/user/me/img/img.png` is not a URL. – user207421 Aug 02 '17 at 03:53
  • Here are two options, either write a client program in java for the system to send it over tcp using a serversocket and a output stream. Or run a simple web server such as apache web server to host the picture and then call the url of the pc/server. – SteelToe Aug 02 '17 at 03:59
  • @SteelToe I've done the first option and used it in many other circumstances, but for this particular case, does converting the local image to a bytestring before sending it out would be best? – allanae Aug 02 '17 at 04:04
  • @arzwng If you don't want to go the first route, I would recommend going with the apache web server as it doesn't require much code and works quite well – SteelToe Aug 02 '17 at 04:06
  • @SteelToe ah, second route is not favorable as I only need to retrieve the images once and cache it in the app's local database for future use – allanae Aug 02 '17 at 04:08
  • I think server socket is the best option for your requirement – Ajay Pandya Aug 02 '17 at 04:09
  • @arzwng I understand but I don't believe that there is a easier way, please correct me anyone if I am wrong – SteelToe Aug 02 '17 at 04:16

1 Answers1

2

The url which you are sending is a local path of image in your system. When you send it to Android it can load it.

Do one thing just convert your image to Base64 string and send it to Android over socket connection.

Once you receive Base64 string, just decode it and set it your imageview.

Harish Vats
  • 662
  • 6
  • 21