0

I am developing an Android application where I need to convert an image into a Byte array. I know that it can't be done with JavaScript. I thought maybe I can use a Java class, is that possible? If it is, how do I do that?

stealthyninja
  • 10,343
  • 11
  • 51
  • 59
naaa
  • 7
  • 3

1 Answers1

0

I believe what you're looking for is a plugin for Android Phonegap applications. Have a look through this documentation and see if it fits your needs.

http://docs.phonegap.com/en/2.2.0/guide_plugin-development_android_index.md.html

Edit: Perhaps then a better solution is use the FileReader API. You can read a file as base64 encoded string and break that into the byte array you need.

http://docs.phonegap.com/en/2.2.0/cordova_file_file.md.html#FileReader

Nick Roth
  • 3,057
  • 2
  • 15
  • 15
  • This may fits me, but I cannot use, I cannot waste time doing this.. :/ – naaa Dec 02 '12 at 19:31
  • Well if there is no out of the box support for what you want to do, you'll have write something custom to fulfill your requirements. Perhaps you can describe where the image is coming from and why it needs to be in a byte array. Then we can try to find an already developed solution if one exists. – Nick Roth Dec 02 '12 at 20:04
  • The image is any image in an android phone, I need to convert it to a byte array because this is the only way I can upload the image to the web service I am using – naaa Dec 02 '12 at 20:22
  • Updated answer to also suggest the FileReader API. – Nick Roth Dec 02 '12 at 20:30
  • thanks.I just found this: http://stackoverflow.com/questions/2727763/communication-between-android-java-and-phonegap-javascript. Do you know if this could work? – naaa Dec 02 '12 at 21:31
  • The general pattern that is presented in that post should work. Whether or not it will work for what you need will depend on if you can code it to do what you need. – Nick Roth Dec 02 '12 at 22:25